9th August 2009
Some time ago, after building my PC and getting rather hard drive happy, I set up an install of Ubuntu on a dual boot (for all that native linux work I do...). However I soon found that going back and forth between the two was putting me off making any active use of it. And so the quest began...
Ok, so not really a quest but I did want to get to my ubuntu/vista holy grail:
The above is a screenshot of my current set up. Running Vista natively I use Sun's Virtual Box to access and use the Ubuntu install that I had previously been separately booting into. This means I can avoid any migration of data from the separate disk into a VHD and I can still boot into Ubuntu natively if I need to. In seamless mode I can even play around and make screenshots like the above where IE sits above an Ubuntu Firefox
Install Ubuntu onto a separate drive and get it to dual boot (Download Ubuntu, create bootable disk, install to new drive, setup booting etc). Depending on how you set it up you may find Easy BCD a useful app (if you end up wanting to frig with the windows Boot Loader).
Nip over to Virtual Box and bag yourself a copy - currently 'VirtualBox 3.0.4 for Windows host'.
Bearing in mind the joy of Vistas UAC you may need to run this as admin.
Page 134 of the version 3.0.4 user manual describes the use of a complete physical hard disk as the source for the guest operating system.
Apart from scaring the bejesus out of you with talk of corruption and loss of data it identifies that you need to create a VMDK file and assign it to a virtual machine.
Section 9.10.1 provides us with the following code (to run in a dos command window - that is again being run as admin):
VBoxManage.exe internalcommands createrawvmdk -filename /path/to/file.vmdk -rawrisk /dev/sda
This will create a vmdk file named 'file.vmdk' from the disk '/dev/sda'. Ultimately the example code translates for us 'Vista hosting Ubuntu' folk to something like:
C:\Program Files\Sun\xVM VirtualBox>VBoxManage.exe internalcommands createrawvmdk -filename C:\Tools\ubuntu.vmdk -rawdisk \\.\PhysicalDrive2 -partitions 1,5 -registerfig. 1.1
Note that two partitions are included in my VMDK creation script - unlike the example code. The user manual doesn't include partition specifiers. However if you need to do so you can identify the partition numbers using the following command:
C:\Program Files\Sun\xVM VirtualBox>VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive2fig. 1.2
This will result in a screen similar to below (you can see where I got 1,5 from for my createrawvmdk command):
PhysicalDrive2 in the createvmdk command is in reference to the fact that my machine was/is running 3 HDs (Windows (0), Data (1), Ubuntu (2)).
The easiest way to boot the system is to create a bootable CD and mount that as part of the virtual machine startup. To create this, first boot into your Ubuntu install.
Gnu.org then provides a succinct description on how to create a bootable grub CD:
~$ mkdir iso ~$ mkdir -p iso/boot/grub ~$ cp /usr/lib/grub/i386-pc/stage2_eltorito iso/boot/grubfig. 2.0
At this point you may wish to edit the menu.lst file. My original menu.lst file included menu options for Ubuntu and Vista. As the boot would be occuring within the VM with knowledge only of the physical disk I was booting in to I had to adjust the menu items. Removing the vista related boot options and changing the ubuntu options to use (hd0,0) instead of (hd2,0).
An ISO can then be created using mkisofs as below (assumes [home folder]/iso/boot as the location of the copied stage2_eltorito and menu.lst):
~$ mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso isofig. 2.1
For more information on the mkisofs command check out the man page. In short:
Before returning to Ubuntu copy the ISO to somewhere accessible to windows (either direct to a shared HD or temporarily on to a USB etc).
Back in vista you should now be able to open up VirtualBox (running as admin to avoid permissions errors on disk access).
The first thing I noticed when I entered the VM was that I had a very low resolution and was unable to resize the window larger. This may not be an issue for you. However if, like me, it was then you need to install VirtualBox Guest Additions.
Using the 'Devices -> Install Guest Additions' option on the VBox window attempts to mount the Guest Additions install as a CD within Ubuntu. However when I tried this it kept getting confused between the grub.iso and the disk I was trying to mount. Rather than faff around too much I found it easier to do the following:
~$ sudo sh VBoxLinuxAdditions-x86.runfig. 3.0
All article content is licenced under a Creative Commons Attribution-Noncommercial Licence.