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


I have a Win7 x64 & Ubuntu 11.10 x64 dual boot set-up on a single HDD.

I wanted to run the native Ubuntu as a guest OS inside Virtual-box running on Win7 host.

I used the following command to list the partitions:

C:\ >vboxmanage internalcommands listpartitions -rawdisk \\.\physicaldrive0
Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
1       0x07  0   /32 /33  153 /27 /2           1200         2048
2       0x07  153 /27 /3   1023/254/63        363337      2459648
5       0x82  1023/254/63  1023/254/63          9537    746575872
6       0x83  1023/254/63  1023/254/63         46430    766107783
7       0x83  1023/254/63  1023/254/63         46431    861200384
4       0x07  1023/254/63  1023/254/63         10000    956291072

Then I created the vmdk file as follows (specifying the ubuntu partitions 5,6 & 7):

C:> vboxmanage internalcommands createrawvmdk -filename
"C:\ubuntu_01.vmdk" -rawdisk \.\physicaldrive0 -partitions 5,6,7

The vmdk file was created successfully, but when I created a VM and specified this virtual drive, the VM wont start, theres just a blank black screen with a white cursor at the top left corner. It doesnot even show up the Grub boot menu.

Then I created another vmdk file without specifying the partitions.

C:> vboxmanage internalcommands createrawvmdk -filename
"C:\ubuntu_02.vmdk" -rawdisk \.\physicaldrive0

This time the VM starts and ubuntu boots successfully from inside the VM (the grub 2 boot menu is presented and on selecting Ubuntu, it boots successfully).

How can I use only the specific native ubuntu partitions instead of the entire disk for the guest ubuntu OS in virtualbox? Please help.

Host: Win 7 x64
Guest: Ubuntu 11.10 x64
Vbox version: 4.1.6 r74713 with latest guest additions installed.

Best Answer

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.