Cannot run native Ubuntu in virtualbox with a vmdk created using the createrawvmdk command with partitions specified

Solution 1:

As soon as you boot Ubuntu from a "virtualized" real harddisk with the method you mentioned it will not find it's bootmanager Grub as in your dual boot setting Grub most likely resides in the MBR of the first (boot) partition on you physical hard drive. From there Grub decides on your choice to boot Windows or Ubuntu.

If you want to boot Ubuntu from a virtual machine then you need a bootmanager (Grub) the same way you need it on a real system.

To achieve this you either need to install Grub in your Ubuntu partition or you need to create a small boot partition for Grub that could easily be added to your Virtual Machine. Read here, and in the GNU Grub manual for further details.

Warning: Both methods could break your dual boot setup or could make your Windows or Ubuntu system unbootable if you made something wrong.


The safe way:

A much safer way to have access for your host and guest data would be installing Ubuntu on it's own 10-15 GB VDI and just mounting your host /home in the guest OS for data acess. By doing so you will also be able to load host or guest kernel modules without breaking the host Ubuntu installation.

Solution 2:

I found a perfectly working workaround. sda7 is the partition where I installed linux, 5,6,7 are the native partition I want to virtualize, and "ceztko" is my home :P

  • from the native linux, reinstall the grub to the native linux partition: sudo grub-install --force /dev/sda7
  • copy the partition boot sector to your home: # dd if=/dev/sda7 of=/home/ceztko/virtualbox-native.mbr bs=512 count=1
  • copy virtualbox-native.mbr to your windows installation
  • Reboot to Windows and from Administrator prompt:

    VBoxManage internalcommands createrawvmdk -filename C:\users\ceztko\ubuntu.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 5,6,7 -mbr c:\users\ceztko\Dropbox\resources\virtualbox-native.mbr

  • Run VirtualBox and assign the new virtual drive to the virtual machine.
  • Enjoy!

This may be a bug in Virtualbox. But better I guess is a bug in grub, confused by the non-accessible Windows partitions when installed as mbr in the boot disk.  

Solution 3:

I had a similar issue and solved it a little bit different, i.e., without booting into the native Linux.

If you specified the -partitions parameter for the .vmdk rawdisk, an image of the MBR and some subsequent sectors will be also created, which you can overwrite directly within the virtual Linux without affecting the original physical sectors. Check the vmdk file for reference. In my case the flat image covered the first 32kb.

In order to boot into the virtual Linux for the first time, you could use e.g., the SuperGrubDisk ISO image. After a successful boot, fix the MBR from the local installation under the virtual environment as usual.

Note that if you want to install grub on your virtual MBR it may be the case that the MBR is not large enough to fit the whole grub image. You notice this only if you attempt to boot the system. In this case you can enlarge the flat image representing the first sectors of your harddisk. You need to adapt the .vmdk file accordingly.