Use VirtualBox to boot a physical drive/partition

12

6

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?

Joshua

Posted 2012-07-20T18:01:03.360

Reputation: 121

Question was closed 2018-12-12T07:56:43.607

For anyone landing here from your search engine of choice, see the excellent answer here

– Codebling – 2018-11-28T06:43:08.087

7If you're planning to sometimes boot the partition physically and sometimes virtually, be aware that this isn't easy to set up. Windows doesn't like having the hardware changed underneath it. – Harry Johnston – 2012-07-20T21:48:24.920

Answers

6

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

BiTinerary

Posted 2012-07-20T18:01:03.360

Reputation: 1 141

3Useful to mention that to use this new .vhd, "VirtualBox Manager" must be started with administrative privileges, because accessing raw devices requires this. – Jonathan Komar – 2016-05-17T08:31:18.523

The \\.\PhysicalDrive# is the most important part. You CANNOT put a disk image file here, it must be a block device (under linux) "physical" drive under windows. – masterxilo – 2018-12-10T20:20:49.990

However, under linux it is easy to mount any file as a virtual block device (using losetup), while I don't know an easy way under windows. – masterxilo – 2018-12-10T20:22:51.673

5

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.

nc4pk

Posted 2012-07-20T18:01:03.360

Reputation: 8 261

This may work if you install https://www.virtualbox.org/attachment/wiki/Migrate_Windows/MergeIDE.zip first. Cool idea for sure.

– MattPark – 2013-01-02T20:11:36.563

2

I love virtualbox

but normally you can't just all of a sudden virtualize a physical windows computer into a virtual one by just reading the hard drive from Virtualbox. (experience and source) Tapped-out's solution seems easier, but I don't think you will boot successfully. You may want to try it first though. Hopefully your windows install doesn't get corrupted when it tries to load all new drivers, etc. but it will probably just BSOD immediately.

If tapped-out's solution doesn't work, go ahead and try this.

Use the vmware standalone converter tool: Make sure you have vmware player (free) installed also.

VMware standalone will let you convert a virtual machine, running physical machine, or an acronis true image backup to a virtual machine. It will also do something to all the drivers so that your machine will work virtually.

  1. if you tried tapped-out's solution, point vmware-converter at at that virtualbox vm you created there. vmware-converter will read it, convert it to a virtual machine, fix the drivers, and install it in vmware player. From there you can convert it to virtualbox format if you want, or just use player.

  2. If you didn't try his solution, or if option 1 did not like the rawdisk read and failed, Virtualbox has a really good article, on converting a real windows install to virtualbox, using linux.

Basically,

  • Install MergeIDE on the windows machine first
  • cat /dev/sdg | VBoxManage convertfromraw stdin OutPutFile.vdi NUMBEROFBYTES
  • add drive to virtualbox and create new vm

MattPark

Posted 2012-07-20T18:01:03.360

Reputation: 1 061