Skip to main content

Virtualization BASH: Set VirtualBox Guests for macOS serial number

This script sets the VirtualBox macOS guests Serial Number and other stuff to allow a macOS to correctly see the underlying hardware. 

All my macOS guests have a name composition to easily identify the type of OS. I could had used the "OS Type", but it is too much work. 

This script only sets the serial number for Big Sur guest. The line with grep "Mac OS X 11." is used to grab only the macOS 11 guests.

#!/bin/bash

# https://en.tab-tv.com/?p=18929
# https://github.com/MagerValp/MacModelShelf/blob/master/dump.markdown (Apple Serial Number Product Code)
# https://mrmacintosh.com/list-of-mac-boardid-deviceid-model-identifiers-machine-models/

# MacBookPro15,1 (15-inch Mid 2018) Mac-937A206F2EE63C01

# JG5H MacBook Pro (15-inch, 2018)
# JG5L MacBook Pro (15-inch, 2018)
# JG5M MacBook Pro (15-inch, 2018)
# JGH5 MacBook Pro (15-inch, 2018)
# JGH6 MacBook Pro (15-inch, 2018)
# JGH7 MacBook Pro (15-inch, 2018)
# JGH8 MacBook Pro (15-inch, 2018)

sBoardId=Mac-937A206F2EE63C01
sProductCode=JG5M

GetVMDetails() {
  sKey="$("${VB}" getextradata "${sVMName}" | tr -d '\r')" 
  sBP="$(echo "${sKey}" | grep DmiBoardProduct  | sed 's/^.*Value: //')"
  sSP="$(echo "${sKey}" | grep DmiSystemProduct | sed 's/^.*Value: //')"
  sSS="$(echo "${sKey}" | grep DmiSystemSerial  | sed 's/^.*Value: //')"
}

if [[ "$(uname -r)" == *Microsoft ]]; then
  VB="/mnt/c/Program Files/Oracle/VirtualBox/VBoxManage.exe"
elif [[ "$(uname -s)" == Darwin ]]; then
  VB="/Applications/VirtualBox.app/Contents/MacOS/VBoxManage"
elif [[ "$(uname -a)" == *Cygwin* ]]; then
  VB="/cygdrive/c/Program Files/Oracle/VirtualBox/VBoxManage.exe"
else
  VB=""
fi
[[ -z "${VB}" || ! -e "${VB}" ]] && exit

sValidDigit="0123456789BCDFGHJKLMNPQRTVWXYX"

nSeq=0

"${VB}" list -s vms | grep "Mac OS X 11." | cut -d\" -f2 | sort | while read sVMName; do

  echo "${sVMName}"
  GetVMDetails
  printf '   Current => %-35s : %-25s : %s : %s\n'  "${sVMName}" "${sBP}" "${sSP}" "${sSS}"

  nSeq=$((nSeq + 1))

  # iBridge2,3 J680AP 0x0B Apple T2 MacBookPro15,1 (j680)
  # MacBookPro15,1 (15-inch Mid 2018) Mac-937A206F2EE63C01
  sSequantial="1Q${sValidDigit:${nSeq}:1}"
  "${VB}" setextradata "${sVMName}" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "MacBookPro15,1"
  "${VB}" setextradata "${sVMName}" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct"  "${sBoardId}"
  "${VB}" setextradata "${sVMName}" "VBoxInternal/Devices/efi/0/Config/DmiSystemSerial"  "C02XH${sSequantial}${sProductCode}"

  # C02 -> Factory/Line number
  # XH  -> 2018/October

  GetVMDetails
  printf '   New     => %-35s : %-25s : %s : %s\n'  "${sVMName}" "${sBP}" "${sSP}" "${sSS}"


done

Comments

Popular posts from this blog

TV Series - The Brokenwood Mysteries [NZ] (2014) - Season 10

 

Movie - Sin City: A Dame to Kill For (2014)

 

Movies - Deadpool & Wolverine (2024)