Blog

VirtualBox raw disk with Ubuntu host and Windows guest on the same drive

Dual booting can be both useful and inconvenient.

Having both a Linux (in this case, Ubuntu 20.04 LTS) and Windows (10) partition means that they can each harness the power of a dedicated GPU that is just not possible in a virtual machine (there’s work in progress to have GPU access via Windows Subsystem for Linux 2, though).

Even as faster drives seek to reduce the boot time, restarting a selecting the next partition closes previous work and forces you to “context switch” whether you want to or not.

Fortunately, referencing the already set up “other” operating system is possible in VirtualBox.

Here, I will consider the case where…

  1. We have a single disk (SSD) that has been set up to boot into Ubuntu 20.04 (default) or Windows 10.
  2. Ubuntu is the “host” machine where we have VirtualBox installed (v6.1)
  3. Windows 10 is the “guest” machine that we want to access from the “host” without rebooting or setting up a new virtual disk + machine.

Disk partitions

  1. EFI - mounted to /boot/efi in Ubuntu
  2. Microsoft reserved - not mounted
  3. Windows 10 - not mounted
  4. Ubuntu 20.04 - mounted at /
  5. Recovery partition

VirtualBox commands (Ubuntu host)

  1. Open a terminal and type

sudo VBoxManage internalcommands createrawvmdk -filename windows.vmdk -rawdisk /dev/sda -partitions 1,3

where windows.vmdk is the output filename, /dev/sda is the disk containing the operating systems (can be check using the Disks program), and -partitions 1,3 references the EFI (1) and Windows 10 (3) partitions (seek Disk partitions above).

  1. Open VirtualBox with root privileges (e.g. sudo virtualbox &)
  2. Add the hard drive

    Settings -> Media -> Hard drive -> Add > select the windows.vmdk file created above

  3. Create a new virtual machine in expert mode

    OS: Windows 10 (64-bit)
    Existing virtual disk > select windows.vmdk

  4. Try boot and if it works, great success! Otherwise close and continue
  5. Changes virtual machine settings

    Make sure “Enable EFI (special OSes only)” is checked

  6. Create a startup.nsh file

    In a terminal:

    sudo nano /boot/efi/startup.nsh

    Make sure the file has the following contents

    # startup.nsh
    FS0:\EFI\Microsoft\Boot\bootmgfw.efi
    

    Save and quit nano

  7. Run the virtual machine again

    You will likely encounter the EFI interactive shell. If the startup.nsh file is set up correctly, then it will shortly boot into Windows.

    Subsequent boots should head straight to Windows!

  8. Enjoy accessing your Windows partition on Ubuntu!
  9. do not attempt to access the Ubuntu drive within the Windows machine within Ubuntu