4

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.

Ringtail
  • 16,285
Zak
  • 141

4 Answers4

5

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.

Takkat
  • 144,580
4

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.  

user994165
  • 245
  • 4
  • 11
ceztko
  • 141
1

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.

0

The complete solution:

The normal place of an OS loader, Grub is one, is "on the PBR", inside the partition. And that's the safest place against its destruction, instead of exposing it on the MBR.

And that makes Linux boot the conventional way, by loading the PBR and executing it. GAG is a nice program to multi-boot and/or to boot logical partitions. It's best to get it on a CD like SystemRescueCd together with a host of tools. Burn the CD or use the ISO file and boot it, then select GAG then configure it, done.

If you don't suspend/resume 6 months long as Linux allows, Tux'll greet you everyday. Thanks for the tip that GAG will rewrite that virtual MBR.

And if you can contact GAG's author, tell him:

  1. My eternal thanks
  2. That he should start configuration with a fully populated Main Screen and let delete, reorder and modify the icons. That makes an already usable configuration right away instead of having to do a lot of manipulations to get started.
Papou
  • 129