I couldn’t find this anywhere, so I thought I’d blog about this. Thanks to the #general channel on the MacAdmins Slack for the help.
To find a serial number for a Mac when booted into the Recovery Partition or the macOS installer, to go Utilities and choose Terminal, type in ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformSerialNumber/{print $4}'
That’s it, it will output the serial number for the computer.
It ask for a program. The next line start > (waiting for a command)
ioreg -rd1 -c IOPlatformExpertDevice | serial
Edit:
ioreg -rd1 -c IOPlatformExpertDevice | grep Serial