Where's the serial number of a Mac located, in the storage or in the firmware? I know this command gives you the serial number for a Mac:

$ ioreg -l | grep IOPlatformSerialNumber


Where does this command get the serial number from? From the storage or from the firmware (this last more likely I guess)?  Any way to get the serial number from the startup disk, so that you can get the serial number for a machine in target disk mode or connected to an enclosure?
Serial numbers are stored within the logic board firmware. 

As a result, if you're trying to access a Mac in Target Disk Mode you're not going to get it's serial number from the Startup Disk (well, not unless someone has previously recorded the serial number on a file stored somewhere on the disk).

If you need the serial number and you can't boot into the Mac, there may be other ways to obtain it (e.g. Apple sometimes engraves serial numbers on the device, by contacting Apple, etc).