Run a dual-boot operative system virtually

I have a dual-boot system with Windows 7 and Ubuntu 11.10 installed on separate partitions, according to the following partitioning scheme:

1. MBR for windows
2. Windows system partition (NTFS) - i.e. C:\
3. Ubuntu / partition (ext4)
4. Ubuntu /home partition (ext4)
5. Ubuntu /boot partition (ext4)
6. Ubuntu swap partition
7. Data partition (NTFS) - mounted as D:\ in windows and /media/data/ in Ubuntu

When I'm in a Windows session, I'd like to be able to start a virtual box with the Ubuntu system from my disk. That is, I don't want yet another Ubuntu installation virtually on some .vhd file, but to actually start it with the data from my hard drive.

I've used Windows Virtual PC before, but never with an actual disk partition as the hard drive rather than just a .vhd file.


I have done that setup using http://www.virtualbox.org, it is described on the manual and the command is something like this: (Please read the documentation !!)

VBoxManage internalcommands createrawvmdk -filename linux.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 7,8
  • The command creates a linux.vmdk and linux-pt.vmdk files on your hard drive, you can use these files as a "virtual disk" in the setup of your virtual machine.

  • This command limits the access of the Virtual disk to only some partitions of your hard drive to prevent damages, please adjust the partitions numbers accordingly.

  • In Windows 7, Virtualbox has to be run "as administrator" in order to access the linux partitions properly.

  • The first time you run the virtual machine Ubuntu should be able to detect the hardware in the virtual machine and configure itself again.

  • You will have to probably install GRUB again in the MBR of your virtual disk (which will be different from your hard drive MBR)

  • Do not attempt to mount the Windows data partition under Ubuntu, that will for sure corrupt the partition, but if you need to access the data, instead configure the networking and mount the partition as a samba share.


The following is the help message printed by VBoxManage:

Usage: VBoxManage internalcommands  [command arguments]

---snip---

  createrawvmdk -filename  -rawdisk 
                [-partitions  [-mbr ] ]
                [-relative]
       Creates a new VMDK image which gives access to an entite host disk (if
       the parameter -partitions is not specified) or some partitions of a
       host disk. If access to individual partitions is granted, then the
       parameter -mbr can be used to specify an alternative MBR to be used
       (the partitioning information in the MBR file is ignored).
       The diskname is on Linux e.g. /dev/sda, and on Windows e.g.
       \\.\PhysicalDrive0).
       On Linux or FreeBSD host the parameter -relative causes a VMDK file to
       be created which refers to individual partitions instead to the entire
       disk.
       The necessary partition numbers can be queried with
         VBoxManage internalcommands listpartitions

The manual seems to suggest that it's possible, although experimental (please backup!): http://www.virtualbox.org/manual/ch09.html#idp13647760

I've never tried for myself, though.