21

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?

2
  • 9
    If 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. Commented Jul 20, 2012 at 21:48
  • For anyone landing here from your search engine of choice, see the excellent answer here Commented Nov 28, 2018 at 6:43

3 Answers 3

11

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

4
  • 4
    Useful to mention that to use this new .vhd, "VirtualBox Manager" must be started with administrative privileges, because accessing raw devices requires this. Commented May 17, 2016 at 8:31
  • 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. Commented Dec 10, 2018 at 20:20
  • 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. Commented Dec 10, 2018 at 20:22
  • I am getting VERR_SHARING_VIOLATION error. I have only on SDD with a partition for linux and another for windows. So my only PhysicalDriver is #0. I tried a lot of things but can´t get awway with this error. Any help? Commented Mar 22, 2021 at 16:33
6

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.

1
4

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.