AlexanderWillner / runMacOSinVirtualBox

Run macOS 10.16 Big Sur (and other versions) in VirtualBox on macOS
MIT License
936 stars 125 forks source link

Go clover-less #37

Closed AlexanderWillner closed 5 years ago

AlexanderWillner commented 5 years ago

See subject and https://forums.virtualbox.org/viewtopic.php?f=22&t=88258&sid=e4081881cc08c41641bcb36d464e6db9&start=15#p431856

AlexanderWillner commented 5 years ago

Also see https://github.com/img2tab/okiomov

bdausses commented 5 years ago

Hi Alex-

Wanted to follow up on this one as I had used your repo to build an image...

Also see https://thetechbloggerguy.blogspot.com/2018/12/macos-mojave-virtualbox-win10.html

I've essentially followed his method, but then baked in his drivers into what you are normally doing here to make it auto-boot without the iso in the drive:

https://github.com/AlexanderWillner/runMacOSinVirtualBox/blob/master/moveCloverToEFI.sh

This produces a Clover-less image that auto boots and works beautifully. Interestingly, it also seems to have gotten rid of the Error loading kernel cache (0x9) errors that I was getting on about 20% of boots... Although I can't say that with 100% certainty, as I've only booted this new build about 15 or 20 times.

fcastilloec commented 5 years ago

@bdausses Could you provide a more detailed (for dummies) guide on how you modified the moveCloverToEFI.sh script so we can follow the guide from thetechbloggerguy.blogspot.com and also don't have the need to have the ISO mounted on boot

bdausses commented 5 years ago

@fcastilloec Sure...

1.) Using this guide, get your VM to the point where it will boot with the Clover ISO. 2.) Grab TheTechBlogger's APFS Drivers ISO at: https://thetechbloggerguy.blogspot.com/2018/12/apfs-efi-iso.html 3.) Attach that ISO to the second optical disk in the VM settings. 4.) In your VM, go and create a script that looks like this (this is the slightly modified moveCloverToEFI.sh script):

#!/bin/bash

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 
   exit 1
fi

# Run this within the virtual machine and remove the ISO from the setup afterwards
mkdir /Volumes/EFI
mount -t msdos /dev/disk0s1 /Volumes/EFI
mkdir -p /Volumes/EFI/EFI
cp -r /Volumes/TheTechBlogger\ A/EFI/* /Volumes/EFI/EFI
diskutil unmount /dev/disk0s1

5.) Run that script as root. (This script is actually copying the drivers to a place that the EFI shell will be able to use them.) Once that completes, shutdown the VM. 6.) Detach BOTH ISO files in the disk settings, then boot the VM. 7.) This will drop you into an EFI shell. We need to create a file here to load the drivers so that it can read the APFS devices and boot the system. Thats where the startup.nsh script comes in. So in that EFI shell, at the Shell> prompt, type edit startup.nsh. Once in that editor, make the file look like this:

echo -off
load fs0:\EFI\drivers\apfs.efi
load fs0:\EFI\drivers\AppleUiSupport.efi
load fs0:\EFI\drivers\ApfsDriverLoader.efi
map -r
fs1:
cd System\Library\CoreServices\
boot.efi

To exit that editor, press CTRL+Q, then Y when it asks you to save. That will drop you back to the EFI shell. Type exit, then press enter. This will drop you to a menu where you will select Continue. This will drop back into the EFI shell with a 5 second timeout before it autoruns the startup.nsh script that you just created. Let that happen and it will load the drivers and boot the system.

At this point you are done. Every time you boot, it'll drop into the EFI shell and have that 5 second timeout, but it will autoload those drivers and boot by itself.

fcastilloec commented 5 years ago

@bdausses Thanks for that guide!!! It works great! Is there any way to reduce the timeout before startup.nsh runs?

AlexanderWillner commented 5 years ago

I can confirm, this works. Let's see how to get make this a bit easier. E.g. the script could just be

load fs0:\EFI\drivers\*
map -r
fs1:\System\Library\CoreServices\boot.efi

And we can create the startup.nshfile on the EFI partition with the script. This still requires clover at the beginning, but removes it in the second stage. Would be nice to mount the EFI partition from the VDI file outside of the VM though...

AlexanderWillner commented 5 years ago

One idea would be to use vdfuse, however, doesn't seem to be maintained anymore...

AlexanderWillner commented 5 years ago

Actually, with the latest version we can go clover-less:

  1. Run make check installer vm run
  2. Install macOS and shutdown (otherwise you'd boot the installer again)
  3. Run make patch run
bacongravy commented 5 years ago

I used this same technique to add support for VirtualBox to https://github.com/bacongravy/macinbox. Thanks!

If you want to remove your dependence on paragon-vmdk-mounter you could try using the technique I use in macinbox, here and here: instead of creating a VDI and then mounting it to modify it, you create and attach an empty APFS Apple disk image, mount the EFI partition, copy the driver onto it, and then convert the attached disk to a VDI using VBoxManage convertfromraw.

AlexanderWillner commented 5 years ago

@bacongravy Thanks! So you end up mounting two VDI images, one for the EFI (that can be recreated on demand - then there is also no need to format it as APFS ) and one for the OS? I recently had to change the boot lookup a bit ( see c3190cc7cb0aa2199fe1b6d09aa3d9eafadf6ecb ) to allow the OS to run an update.

bacongravy commented 5 years ago

@AlexanderWillner Not quite... more like this (but not exactly, some hand waving involved):

/usr/bin/hdiutil create -size 64g -type SPARSE -fs APFS -volname "Macintosh HD" -uid 0 -gid 80 -mode 1775 scratch.sparseimage
/usr/bin/hdiutil attach scratch.sparseimage -nomount
# determine whole disk and EFI partition device path, set DEVICE and EFI_DEVICE
# create a mountpoint, set EFI_MOUNTPOINT
/usr/sbin/diskutil mount -mountPoint $EFI_MOUNTPOINT $EFI_DEVICE
/bin/mkdir -p $EFI_MOUNTPOINT/EFI/drivers
/bin/cp /usr/standalone/i386/apfs.efi $EFI_MOUNTPOINT/EFI/drivers/
# write to $EFI_MOUNTPOINT/startup.nsh
/usr/sbin/diskutil unmount $EFI_MOUNTPOINT
VBoxManage convertfromraw $DEVICE disk.vdi --format VDI

This should result in a VDI with a blank 64 GB APFS partition with a volume named "Macintosh HD", and an EFI partition with the apfs driver and startup.nsh pre-installed.

bacongravy commented 5 years ago

...but upon further reflection, your idea does sound like it would work: a disk with nothing but an EFI partition that loads the apfs driver and then scans the rest of the disks for something to boot. So, you'd end up mounting three things into VirtualBox: the EFI disk, the blank disk that you'll target with the installer, and the installer media.

AlexanderWillner commented 5 years ago

@bacongravy Did this in 3855af0