Booting VM off raw disks in Windows

Booting VM off raw disks in Windows

Goal is simple - boot a VM off the raw disks in Windows.
I will use VirtualBox as hypervisor and one 512 GB (disk 4) + two 4 TB disks (disk 1 & disk 2 ).

Disk 4 is bootable with the Ubuntu Linux previously installed there. I normally just boot it off directly from the Grub2 or BIOS Boot menu, but sometimes I just want to boot it directly while sitting in Windows.
Disk 1 & Disk 2 are the data disks where I keep my things on ZFS mirror.

Now I run diskpart tool as admin (Win+R, then Ctrl+Shift OK/Enter) in order to see the disk layout:

Press Ctrl+Shift OK/Enter to run it as Administrator

After that, I'll create the VMDK files which will point to these disks.
Make sure you run cmd.exe tool as admin (Win+R, then Ctrl+Shift OK/Enter) in order to have the raw disk access when creating the VMDK files using the VBoxManage.exe commands below:

Press Ctrl+Shift OK/Enter to run it as Administrator
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands createrawvmdk -filename C:\VirtualBoxDrives\raw-disk4.vmdk -rawdisk \\.\PhysicalDrive4
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands createrawvmdk -filename C:\VirtualBoxDrives\raw-disk1.vmdk -rawdisk \\.\PhysicalDrive1
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands createrawvmdk -filename C:\VirtualBoxDrives\raw-disk2.vmdk -rawdisk \\.\PhysicalDrive2

And will attach them to the VM that I've created in beforehand using the VirtualBox Manager:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" list vms
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach ubuntu --storagectl SATA --device 0 --port 0 --type hdd --medium "C:\VirtualBoxDrives\raw-disk4.vmdk"
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach ubuntu --storagectl SATA --device 0 --port 1 --type hdd --medium "C:\VirtualBoxDrives\raw-disk1.vmdk"
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach ubuntu --storagectl SATA --device 0 --port 2 --type hdd --medium "C:\VirtualBoxDrives\raw-disk2.vmdk"

Troubleshooting

VERR_ACCESS_DENIED issue

VBoxManage.exe: error: Permission problem accessing the file for the medium 'C:\VirtualBoxDrives\raw-disk4.vmdk' (VERR_ACCESS_DENIED)
VBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee IUnknown
VBoxManage.exe: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 191 of file VBoxManageDisk.cpp
VBoxManage.exe: error: Invalid UUID or filename "C:\VirtualBoxDrives\raw-disk4.vmdk"

Make sure you are running cmd.exe as Administrator.

VERR_SHARING_VIOLATION issue

VBoxManage.exe: error: Cannot open the raw disk '\.\PHYSICALDRIVE4': VERR_SHARING_VIOLATION

Start procexp64.exe as Administrator, search for "harddisk#" (where # is number of the driver you are looking for), kill the relevant process which is using your disk.
In my case that was LEDKeeper2.exe process ("C:\Program Files (x86)\MSI\One Dragon Center\Mystic_Light\LEDKeeper2.exe"). I have just uninstalled the "MSI SDK" which I did not really need, eventually.

Inaccessible raw disks

Close VirtualBox GUI, restart "VirtualBox system service", then start VirtualBox GUI as Admin again.
To restart the service, run  services.msc tool as admin (Win+R, then Ctrl+Shift OK/Enter).

Press Ctrl+Shift OK/Enter to run it as Administrator
Restart VirtualBox system service
Run VirtualBox GUI as admin
After that you will see the disks are accessible
Each time you start Oracle VM VirtualBox GUI as User, you need to close it and restart VirtualBox system service, before starting it as Administrator again.

To boot UEFI system

If the disk you are trying to boot off your VM has the system installed in UEFI mode, the following VirtualBox settings need to be enabled:

  • VirtualBox -> Settings -> System -> Motherboard -> Extended Features -> [x] Enable EFI (special OSes only)
  • VirtualBox -> Settings -> Storage -> Controller: SATA -> [x] Use Host I/O Cache      you may get I/O cache related errors during Linux boot without this setting
  • VirtualBox -> Settings -> Display -> Acceleration -> [x] Enable 3D Acceleration      also set >= 32 MiB video memory

If you found this useful, please consider making a donation!

Donations