Creating Windows and macOS VMs



4 Dec 2020

Just a bunch of un-related findings that may help when creating Windows and macOS VMs using VirtualBox.

Windows 7 Images from Microsoft

The quickest way to get a Windows 7 VM is from the legacy IE11 and Edge Virtual Machines from Microsoft directly. The Windows 7 images are already on SP1:

  • Images for VirtualBox, HyperV, VMWare and Parallels (on macOS) are all available. With VirtualBox, just import the OVA.
  • The VMs will expire after 90 days, but just import the OVA again, or revert to a snapshot.

When I tried it today, I got a “BlobNotFound” error downloading IE8 on Win7 (x86) for VirtualBox, but other downloads for VirtualBox were ok.

Downloading Windows 7 SP1

If you are using your own Windows 7 image / ISO for testing, then you may have challenges finding Service Pack 1. Without SP1, Windows Update does not work! Many links, including Microsoft’s own Install Windows 7 Service Pack 1 (SP1) support document, are broken!

The place to find the installer is at the old Microsoft Update Catalog. IE8 that comes with the initial Windows 7 release can’t reach the https version of this site (perhaps due to expired root certificates), so thankfully http still works.

Windows 7 end of support was January 14, 2020. Use at your own risk.

Defragmenting and Compacting a Virtual Hard Disk

Mostly to keep keep a record for my own use in the future, here is how to shrink a virtual hard disk:

  • If you have multiple VMs available, then mount the virtual disk from another VM to defrag. That avoids any in-use files not getting defragmented. Else, just boot into the guest OS itself:
    • Defragment using the guest OS’s own tools,
    • For Windows, download the once-upon-a-time famous SysInternals SDelete from Microsoft, and run it to zero out unused disk space sdelete64 C: -z. The equivalent with Linux would be fstrim /mnt/fs/.
    • When that is done, shutdown the guest.
  • From the host OS, using the Command Prompt,
    • If you don’t know where the virtual hard disk image is, then find it from the VirtualBox VM settings page > Storage.
    • Now you know the location to the image (e.g. D:\VMs\hdd.vdi), then just run vboxmanage modifymedium D:\VMs\hdd.vdi --compact.

Creating a macOS High Sierra VM

Seriously, don’t do what is below. I have no idea if it is legal, safe or even accurate. I am not responsible or liable if your machine dies.

I am summarizing what I read on How-To Geek. Refer to this for a verbose explanation with screen shots.

High Sierra

First and foremost, you’ll need a Install macOS High on a mac already. If you didn’t keep this from the time of High Sierra (September 2017) you are out of luck. On the mac with this installer:

hdiutil create -o /tmp/HighSierra.cdr -size 7316m -layout SPUD -fs HFS+J
hdiutil attach /tmp/HighSierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build
asr restore -source /Applications/Install\ macOS\ High\ -target /Volumes/install_build -noprompt -noverify -erase
hdiutil detach /Volumes/OS\ X\ Base\ System
hdiutil convert /tmp/HighSierra.cdr.dmg -format UDTO -o /tmp/HighSierra.iso
mv /tmp/HighSierra.iso.cdr ~/Desktop/HighSierra.iso
rm /tmp/HighSierra.cdr.dmg

Next, go through the normal VirtualBox New VM steps:

  • “High Sierra” as the VM name (important for next step)
  • Type is Mac OS X and version macOS 10.13 High Sierra (64-bit)
  • 2GB RAM
  • 2 processors
  • no floppy
  • 128MB video memory
  • 30GB SATA HDD but I think 20GB HDD is enough
  • make sure the ISO is mounted from Storage > SATA controller > Optical drive.

Before running the VM, edit the VM settings via the command line, from the location where VirtualBox is installed. This sets the VM’s UEFI/BIOS to identify itself as a Mac:

VBoxManage modifyvm "High Sierra" --cpuidset 00000001 000306a9 04100800 7fbae3ff bfebfbff
VBoxManage setextradata "High Sierra" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "MacBookPro11,3"
VBoxManage setextradata "High Sierra" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage setextradata "High Sierra" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Mac-2BD1B31983FE1663"
VBoxManage setextradata "High Sierra" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VBoxManage setextradata "High Sierra" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 

The default resolution is 1024x768, so change the last digit for the desired resolution (1=800x600, 2=1024x768, 3=128-x1-24, 4=1440x900, 5=1920x1200):

VBoxManage setextradata "High Sierra" "VBoxInternal2/EfiGopMode" 4

Check everything with VBoxManage getextradata "High Sierra".

Now, a very important step for AMD processors to identify as Intel instead (which is not in the How-To Geek guide):

VBoxManage modifyvm "High Sierra" --cpu-profile "Intel Core i7–6700K"

Boot the VM from the ISO (you will be prompted to select the correct file by VirtualBox), and go through the installation, but:

  • After the language selection screen, select Disk Utilities and Continue
  • Select VBOX HARDDISK Media and hit the Erase button. If you don’t see this disk, from the View menu > Show all devices.
  • Clicking Erase using Mac OS Extended (Journaled) and GUID Partition Map (setting AFS will not work).
  • Close the disk utility, and continue to Reinstall macOS.

In my case the installer rebooted twice - which resulted in VirtualBox crashing - but in both cases, upon restart, the installation continued successfully (actually this happens anytime I reboot). Finally, the installer will complete, and you will be on the desktop!

I didn’t have problems with the boot process that some people reported, dropping into a UEFI shell Shell> fs1: and requiring to manaully run "macOS Install Data/Locked Files/Boot Files/boot.efi"

After a reboot, go ahead install Guest Additions, available for macOS starting with Virtual Box 6.0. From the Devices menu > Insert Guest Additions CD image.... Open the CD on the desktop, and run VBoxDarwinAdditions.pkg.

During the install you will be prompted - System Extension Blocked - but you will be allowed to enable it by going to Open Security Preferences:

High Sierra VirtualBox Additions System Extension Blocked

There, just click Allow for the developer "Oracle America, Inc." Reboot.

High Sierra VirtualBox Additions Security & Privacy Allow

Big Sur

High Sierra supports 32-bit and 64-bit apps, but Big Sur is exclusively 64-bit. Big Sur is also almost double in size, perhaps because it supports x86 and M1 ARM.

Similar to above, you need Install macOS Big to then create the bootable ISO:

hdiutil create -o /tmp/BigSur.cdr -size 12685m -layout SPUD -fs HFS+J
hdiutil attach /tmp/BigSur.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/bigsur
sudo /Applications/Install\ macOS\ Big\ --volume /Volumes/bigsur --nointeraction
hdiutil detach /Volumes/Install\ macOS\ Big\ Sur
hdiutil convert /tmp/BigSur.cdr.dmg -format UDTO -o /tmp/BigSur.iso
mv /tmp/BigSur.iso.cdr ~/Desktop/BigSur.iso
rm /tmp/BigSur.cdr.dmg

You will need to then create a VM as above, except this time the minimum is about 40GB.

Guest Extensions simply do not work with Big Sur, as the drivers from Oracle VirtualBox are unsigned.

Big Sur VirtualBox Additions System Extension Blocked

Alas, as Apple transitions away from Intel x86 CPUs + Intel/AMD GPUs to custom Arm CPUs + integrated GPUs, running macOS VM will likely become a thing of the past. Catalina is the first macOS version to support both x86 and Arm, but its very possible that future versions will drop support for x86, just like macOS dropped support for 32-bit not long after High Sierra (which is one reason I still have this version around).