Use VirtualBox to boot a physical drive/partition [duplicate]

I have two partitions on my hard drive, one for Windows and one for linux. I would like to use VirtualBox in Linux to boot the Windows partition as a virtual machine. How can I acheive this?


Solution 1:

There's actually a really easy solution to achieve this. The following process will create a virtual disk (.vmdk) that will boot to a designated drive/partition. You essentially "fake" boot directly to the drive so the created virtual drive isn't very big in size and it doesn't get any bigger.

However, a downfall to the following suggestion would be that it boots virtually. Meaning, you can run any programs or files that are on it but once in the Virtual Machine, settings/program changes can't be made on the physical drive. If you wanted to add programs, updates, etc... you would have to normally boot to the drive, make desired changes, then boot from the VirtualBox. I don't know if this is a deal breaker for you but here's the goods.

Part of this example is for doing it in Windows because I don't know the Linux directory structure and path variables by heart but the VirtualBox command will be the same, regardless of Host OS. Same process just supplement the OS commands accordingly

1: WindowsKey + R > Type diskmgmt.msc Make note of the disk number of the drive you're trying to virtualize. Linux alternative for figuring this out would be running one of the following utilities > fdisk, lsblk, gparted

2: Open a CommandPromptTerminal with Admin/Sudo privileges > type cd %programfiles%\oracle\virtualbox. I don't know what the default directory path for VirtualBox is in Linux distros but simply find it and cd to it.

3: Run the following VirtualBox command: VBoxManage internalcommands createrawvmdk -filename "%USERPROFILE%"\.VirtualBox\CUSTOMNAMEOFVHD.vmdk -rawdisk \\.\PhysicalDrive#

~ Replace "CUSTOMNAMEOFVHD" to whatever you would like. You can also change the entire path of that file to something else. It's simply telling VBoxManage where to put the created .vhd

~ Change the last character # do the disk drive number recorded in step 1.

Windows Tutorial: http://www.pendrivelinux.com/category/virtual-machine/

Ubuntu Specific Example: https://askubuntu.com/questions/168156/how-to-use-a-real-partition-with-windows-7-installed-in-a-virtualbox-vm

Solution 2:

From chapter 10. Advanced Topics of the VirtualBox manual:

To create a special image for raw partition support (which will contain a small amount of data, as already mentioned), on a Linux host, use the command

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda -partitions 1,5

This example would create the image /path/to/file.vmdk (which, again, must be absolute), and partitions 1 and 5 of /dev/sda would be made accessible to the guest.

For example, if your hard drive is /dev/sda/ and the Windows partition is /dev/sda2, the command you use might look like:

VBoxManage internalcommands createrawvmdk -filename ~/windows.vmdk -rawdisk /dev/sda -partitions 2

This would create a file, windows.vmdk, in your home folder, which you would then mount in the virtual machine.