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

Movie - The Wizard of Oz (1939)

  My views Plot In rural  Kansas ,  Dorothy Gale  lives on a farm owned by her Uncle Henry and Aunt Em, and wishes she could be somewhere else. Dorothy's neighbor, Almira Gulch, who had been bitten by Dorothy's dog, Toto, obtains a sheriff's order authorizing her to seize Toto. Toto escapes and returns to Dorothy, who runs away to protect him. Professor Marvel, a charlatan fortune-teller, convinces Dorothy that Em is heartbroken, which prompts Dorothy to return home. She returns just as a  tornado  approaches the farm. Unable to get into the locked storm cellar, Dorothy takes cover in the farmhouse and is knocked unconscious. She seemingly awakens to find the house moving through the air, with her and Toto still inside it. The house comes down in an unknown land, and Dorothy is greeted by a good witch named  Glinda , who floats down in a bubble and explains that Dorothy has landed in Munchkinland in the  Land of Oz , and that the Munchkins are cel...

Movie - Bastille Day | The Take (2016)

  My views Plot On the eve of  Bastille Day  in  Paris , American drifter and  pickpocket  Michael Mason steals a woman's handbag, not knowing that it contains  explosives . After taking the cash from the bag, he discards it, caught unwittingly on  CCTV  as he does so. The bag then detonates and kills four people. Upon being captured by  CIA  agent Sean Briar, who is being reprimanded for irresponsible conduct on the job, Mason protests that he is not a  terrorist  and tells Briar that the bag contained a cellphone owned by a woman named Zoé. The bomb was set up by a group of  corrupt policemen , all of them members in the  French special police RAPID unit  led by Rafi Bertrand, who intend to pull a robbery at the  Bank of France . Zoé was told to plant the bomb at the office of the  French Nationalist Party  (as part of a diversion for the heist), but after seeing the night cleaning crew arri...

Movie - The Gorge (2025)

  My views For 80 years everything was ok ... until they sent a woman For sure is DTV ... really bad Inside the gorge is clearly designed and written by a gamer Plot Two elite  snipers  receive identical missions: travel to an undisclosed location and guard the West and East sides of a deep gorge for one year without any contact with the outside world nor their counterpart on the opposite side. Levi Kane, a former  U.S. Marine  and current  private contractor  accepts the offer to guard the West tower. Drasa, a  Lithuanian  covert operative frequently employed by the  Kremlin , agrees to guard the East side. Upon arriving, Levi relieves his predecessor, J.D., a  British   Royal Marine  of duty and asks for specifics about the mission. J.D. explains that in addition to the towers on the East and West, there are automated turret defenses to the North and South, a powerful signal ‘ cloak ,’ and  explosives on the walls ...