Skip to content

Instantly share code, notes, and snippets.

@victorbnl
Last active December 10, 2022 13:23
Show Gist options
  • Save victorbnl/ed169a0ba989d0cbbdabbe08a6be9e02 to your computer and use it in GitHub Desktop.
Save victorbnl/ed169a0ba989d0cbbdabbe08a6be9e02 to your computer and use it in GitHub Desktop.
How to boot from physical disk with VirtualBox

How to boot from physical disk with VirtualBox

Do you have a dual boot? If so, isn't it annoying that you have to reboot each time you need the other os? Then boot from the physical disk with VirtualBox! It's not complicated, we'll see how to do this with a Linux host and a Windows host

Requirements

  • VirtualBox
  • A physical disk to boot (the other OS can be on the same disk or another one)

On a Linux host

  • Open a command line
  • Identify which disk you want to boot on (the disk, not the partition, for example /dev/sda and not /dev/sda1)
  • Give the permissions to the device's file to read it and write to it with either :
    • sudo chmod 666 /dev/yourDisk
    • sudo usermod -a -G disk yourUser, this is another, more secure method, but I didn't test it yet
  • Now we'll create a virtual disk (.vmdk) which will be a "link" to the physical hard drive
    THIS IS NOT A COPY, ALL THE CHANGES MADE TO THE VIRTUAL DISK WILL BE MADE ON THE PHYSICAL DISK
    We make the virtual disk with
    VBoxManage internalcommands createrawvmdk -filename "anyNameYouWant.vmdk" -rawdisk /dev/nvme0n1
  • Now create a VM, when asked to choose a disk don't create one but choose this file

On a Windows host

Still in work, please don't follow this one

  • Identitify the disk number. For this, you can go in the disk manager and it's written "Disk 0", "Disk 1" etc...
  • Open a command prompt as admin :
    • Type "cmd" in the search menu
    • Right click on the "Command prompt" entry and click "Open as Administrator"
  • Now we'll create a virtual disk (.vmdk) which will be a "link" to the physical hard drive
    THIS IS NOT A COPY, ALL THE CHANGES MADE TO THE VIRTUAL DISK WILL BE MADE ON THE PHYSICAL DISK
    We make the virtual disk with
    C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands createrawvmdk -filename "anyNameYouWant.vmdk" -rawdisk \\.\PHYSICALDRIVE<theDiskNumber> If you've chosen a custom path for the VirtualBox installation, change the path accordingly.
  • Now create a VM, when asked to choose a disk don't create one but choose this file

Troubleshooting

  • If your VM displays "No bootable medium found" when you start it, it probably means that your system is UEFI and your VM tries to boot in BIOS mode. Go in the VM configuration > System and enable "Enable EFI (special OS only)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment