Edit 22/11/09
Ubuntu 9.10 uses the new grub 2 as its boot-loader thus this article would not work for 9.10. I am currently in the progress of getting 9.10 to work under Virtualbox.

This tutorial would no longer be supported. Any comments regarding support will be ignored.

If you want to get 9.10 working please READ THIS ARTICLE

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I recently got Windows 7 and Ubuntu running in a dualboot. However, since I’m using more of Windows now I figured I should probably find a way to run Ubuntu inside my Windows. VM’s are great, but it’d be better if I can actually boot into my existing Ubuntu partition. So I searched the web and kept on finding tutorials on how to boot existing XP partitions inside Windows. So I decided to extrapolate from those tutorials and work my way through it. I’ll be writing how I did it here.

Before we begin, you should have a dual boot setup. I will NOT be showing you how to setup a dual boot, if you need help plenty of other guides out there.

Step 1: Creating a grub boot iso

The grub iso file will allow you to specify which partition to boot into.

  1. Boot into Ubuntu
  2. We create the folders and copy the necessary files to setup an iso
    Run the command:  cd ; mkdir -p iso/boot/grub ; cp /usr/lib/grub/*-pc/stage2_eltorito /boot/grub/menu.lst iso/boot/grub
  3. Configure your ~/iso/boot/grub menu.lst file to boot your target OS (in this case Ubuntu). Remove the “savedefault” option from your target entry if it exists.
  4. We now create the bootable iso file
    Run the command: cd ; mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o grub.iso iso
  5. Move the iso to a location that’ll be accessable by your Windows partition

Step 2: Creating the .vmdk file

This creates a file which tells Virtualbox what partition to actually load as the harddrive. Unfortunately, unlike VMWare Workstation, Virtualbox does not support a GUI interface for selecting RAW hard disks as the “virtual hard drive”.

  1. Boot into Windows
  2. cd into the directory you installed virtualbox
  3. We find the partition number that needs to be mounted
    Run the command: VBoxManage.exe internalcommands listpartitions -rawdisk \\.\PhysicalDrive1
    (where 1 is the number of the hard drive ubuntu is installed on. E.g. Master should be 0, you’re second hard-drive should be 1 etc…The output should be something like:

    Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
    1       0×07  0   /32 /33  1023/254/63        902023         2048
    5       0×83  1023/254/63  1023/254/63         49677   1847346543
    6       0×82  1023/254/63  1023/254/63          2164   1949086188

    In this example, my Ubuntu partition is number 5 and the swap is number 6

  4. We now create the VMDK file with the given information
    Run the command: VBoxManage.exe internalcommands createrawvmdk -filename C:\path\ubuntu.vmdk -rawdisk \\.\PhysicalDrive1  -partitions 5,6 -register

Step 3: Setup Virtualbox

Now everything should be ready to setup Virtualbox. Create a new virtual machine. Select the .vmdk file we just created as the hard drive and mount the grub.iso file we created at Step 1. If everything was successful Ubuntu should boot up nicely.

DONE!

If this has helped you in any way, please take the time to drop a comment! If you have any problems, just post a comment or send me an email through the “Contact me” page.

References:

Boot an existing XP (Physical HD) install with VirtualBox