I have a dual-boot laptop with Windows 7 and Ubuntu 12.04. I am trying to boot the ubuntu partition from windows using Virtualbox. I have successfully created the .vmdk, and created the virtual machine. However, I can't get it to boot (in Virtualbox). All I get is a black screen with the cursor in the top left.

I wonder if I'm specifying the partitions correctly. My Ubuntu install has 3 partitions: \, \boot, \home. No swap partition. These are all in Disk 0, partitions 3,4,5 respectively.

The command I used to create the .vmdk is:

 VBoxManage internalcommands createrawvmdk -filename C:\Users\abalter\.virtualbox\ubuntu.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 3,4,5

Then I create a virtual machine based on that .vmdk.

Why won't it boot?


Solution 1:

It's a known bug: https://www.virtualbox.org/ticket/9926 This http://www.neowin.net/forum/topic/784138-howto-boot-existing-ubuntu-partition-using-virtualbox-inside-windows/ suggests creating a custom iso that bootstraps grub2 as a workaround.

Solution 2:

I just did this yesterday, finally got it working using this tutorial: https://askubuntu.com/questions/78902/cannot-run-native-ubuntu-in-virtualbox-with-a-vmdk-created-using-the-createrawvm

I used ceztko's post (copied below). Note also that after I had it all working, I booted into Ubuntu in the VM and re-ran update-grub, which got rid of the extra entry in grub for Windows 7 (this is for safety's sake; if you accidentally try to boot the Win 7 partition from within a VM running on that same Windows 7 install, bad bad bad things will happen). After doing this, I essentially have 2 separate installs of grub: one on the system MBR that includes entries for Win 7 and Ubuntu, and one on the MBR of the VirtualBox .vmdk file (even though this file points to the raw Ubuntu partition, it's possible for it to have a different MBR).

ceztko's post:

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.

Edit: I should mention that Hemlock was pretty close - the problem is indeed that the .vmdk file pointing to the raw partition doesn't include a valid bootloader/boot sector. The first step in cetzko's post has you install grub to the MBR of the partition, and then make a copy of that MBR to add in to the .vmdk file. Normally grub is installed to the MBR of the entire hard drive.