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

IT - My Home Platform View - All Infrastructure

Some ideas Deploy a harverster cluster Deploy a rancher server

Movie - The Gray Man (2022)

  My views Plot In 2003, senior  CIA  official Donald Fitzroy visits a prisoner named Courtland Gentry in Florida. Eight years earlier, Courtland was a minor convicted of killing his abusive father to protect his brother. Fitzroy offers him his freedom in exchange for working as an assassin in the CIA's  Sierra  program, an elite black ops unit, which will allow him to exist in the gray. In 2021, Courtland, now known as  Sierra Six , is working with fellow CIA agent Dani Miranda to assassinate a target named Dining Car suspected of selling off  national security  secrets in  Bangkok  during the national  Songkran  festival. Unable to do so stealthily without harming civilians, he attacks Dining Car directly, mortally wounding him. Before dying, he reveals he was also in the Sierra program as Sierra Four. He hands Six an encrypted drive detailing the corruption of CIA official Denny Carmichael, the lead agent on the assassinatio...

Movie - Source Code (2011)

  My views Romantic movie wrapped around a SciFi movie A Helicoper Captain with the intelligence of a pea Going back all the time, with 8 minutes, and wasting time talking about feelings... Plot U.S. Army pilot Captain Colter Stevens wakes up on a  Metra [ 6 ]  commuter train going into Chicago. He is disoriented, as his last memory was of flying a mission in Afghanistan. However, to the world around him – including his friend Christina Warren and his reflection in the train's windows and mirrors – he appears to be a different man: a school teacher named Sean Fentress. As he expresses his confusion to Christina, the train explodes while passing another train, killing everyone aboard. Stevens abruptly awakens in a dimly lit cockpit. Communicating through a video screen, Air Force Captain Colleen Goodwin verifies Stevens's identity and tells him of his mission to find the train bomber before sending him back to the moment he awoke on the train. Believing he is being tested ...