Skip to content

Instantly share code, notes, and snippets.

@tap52384
Last active January 10, 2023 23:38
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tap52384/9971deac57ea5ba9f39fcde0a84cbcf2 to your computer and use it in GitHub Desktop.
Save tap52384/9971deac57ea5ba9f39fcde0a84cbcf2 to your computer and use it in GitHub Desktop.
Bootcamp via Virtualbox 5.2 on macOS Mojave

virtualbox-bootcamp

directions for getting windows 10 to work with virtualbox 5.2 based on this page

Tools Used

Procedure

Install Windows 10 via Boot Camp Assistant

  • Requires you to remove any external hard drives before continuing
  • Probably should download the Boot Camp Support Software prior to installing Windows 10 to a USB key for installation
  • Boot back into macOS when you are done and confirmed all drivers are installed

Install VirtualBox on macOS

Unmount the BOOTCAMP partition

In order to use your bootcamp partition with VirtualBox it will need to be unmounted first. This can be done manually from the Terminal using the following commands:

diskutil list
diskutil unmount /Volumes/BOOTCAMP <--- this is the name of the BOOTCAMP volume
sudo chmod 777 /dev/disk0s1 <--- This is the drive number of the EFI disk
sudo chmod 777 /dev/disk0s3 <--- This is the drive number of the BOOTCAMP disk

If your bootcamp volume doesn't have a name for some reason, use /Volumes/Untitled.

Create a VirtualBox raw disk image for the BOOTCAMP partition

To create an image that represents an entire physical hard disk (which will not contain any actual data, as this will all be stored on the physical BOOTCAMP partition). You will need the following information from diskutil list:

  • /dev/disk0 (internal, physical):
  • /dev/disk0s1 - the drive number of the EFI disk
  • /dev/disk0s3 - the drive number of the BOOTCAMP disk
mkdir ~/virtualbox
cd ~/virtualbox
sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win10raw.vmdk -partitions 1,3
sudo chown your_username_here *.vmdk

Please note that vboxmanage internalcommands is an internal tool and is completely unsupported and will change in compatible ways without warning.

This command will create an image that will reference the EFI and BOOTCAMP partitions on our internal hard drive. If this command fails, then you may need to disable System Integrity Protection. This requires you to boot into Recovery Mode and execute the following command csrutil disable:

-bash-3.2# csrutil status
System Integrity Protection status: enabled.
-bash-3.2# csrutil disable
Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.

Documentation on configuring System Integrity Protection can be found here and here.

Create a new VM

  • In the Finder menu, go to Machine --> New.
  • Click Expert Mode to continue.

In the Name and operating system window:

  • Name: Boot Camp
  • Type: Microsoft Windows
  • Version: Windows 10 (64-bit)
  • Memory Size: 4096 MB
  • Use an existing virtual hard disk file: ~/virtualbox/win10raw.vmdk Click Create. In the main application window, select the Boot Camp VM and click Settings.

In the System --> Motherboard settings:

  • Boot Order: Only check Hard Disk and Optical and move Hard Disk before Optical
  • Enable EFI (special OSes only): Checked

In the System --> Processor settings:

  • Processors: 4
  • Execution Cap: 100%
  • Enable PAE/NX: Checked

In the System --> Storage settings:

  • Controller: SATA: Check the Use Host I/O Cache option

Click OK to save these settings.

You should now be able to run Windows 10 from your BOOTCAMP partition!

Remember that you have to complete the steps under Unmount the BOOTCAMP partition upon every restart.

Automatically unmount the BOOTCAMP partition upon boot into macOS

There may be a way to prevent the partition from mounting upon boot using the vifs command as detailed on this page

@fbertanha
Copy link

im getting an error when running the command below. The System Integrity Protection is disabled, the BOOTCAMP partition is unmounted, and applied the chmod 777 commands above.

my-user@MacBook-Pro-de-Felipe virtualbox % sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win10raw.vmdk -partitions 1,3
VBoxManage: error: Cannot read the partition information from '/dev/disk0'
VBoxManage: error: The raw disk vmdk file was not created

Make sure you are using the correct partition numbers. What did you get when you ran diskutil list?

Hello friend, this is my disk list

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         379.0 GB   disk0s2
   3:       Microsoft Basic Data BOOTCAMP                121.0 GB   disk0s3

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +379.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            11.3 GB    disk1s1
   2:                APFS Volume Macintosh HD - Data     298.9 GB   disk1s2
   3:                APFS Volume Preboot                 126.0 MB   disk1s3
   4:                APFS Volume Recovery                528.9 MB   disk1s4
   5:                APFS Volume VM                      1.1 GB     disk1s5

@heerdt
Copy link

heerdt commented Oct 1, 2020

Same error for me! when I run: "sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win10raw.vmdk -partitions 1,3" I got:
VBoxManage: error: Cannot open the raw disk '/dev/disk0': VERR_ACCESS_DENIED VBoxManage: error: The raw disk vmdk file was not created

@tompointexe
Copy link

tompointexe commented Jul 15, 2021

im getting an error when running the command below. The System Integrity Protection is disabled, the BOOTCAMP partition is unmounted, and applied the chmod 777 commands above.

my-user@MacBook-Pro-de-Felipe virtualbox % sudo vboxmanage internalcommands createrawvmdk -rawdisk /dev/disk0 -filename win10raw.vmdk -partitions 1,3
VBoxManage: error: Cannot read the partition information from '/dev/disk0'
VBoxManage: error: The raw disk vmdk file was not created

Hey, Same error here :) does anyone have a fix ?

@KeeliGITHUB
Copy link

I get stuck in the UEFI Interactive Shell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment