VirtualBox: booting from an existing “raw” partition

The problem when trying to run a guest OS inside VirtualBox that can also be booted physically using grub is that grub will refuse to cooperate if you try to invoke it from within VirtualBox.

There are quite a lot of HOWTOs on the net dealing with this issue, but none made me really happy. So here’s my setup:

  • one HDU /dev/sda
  • Mandriva 2009.1 on /dev/sda2
  • Windows XP on /dev/sda1
  • grub as a boot loader

So what I wanted to do was to have VirtualBox boot my existing Windows installation.

BEFORE you start, boot natively into your Windows installation and create a hardware profile reflecting the native hardware components (Control panel->System->Hardware profiles). That allows you always have a working hardware configuration, not matter if you boot natively or using VirtualBox.

The steps to achieve this are simple:

  • install syslinux
  • create a dedicated boot loader (as root):

    % dd if=/dev/zero of=dummy.img bs=1M count=50
    % losetup /dev/loop0 dummy.img
    % dd if=/usr/lib/syslinux/mbr.bin of=/dev/loop0
  • extract the boot loader (as root):
    % dd if=/dev/loop0 of=wxp.mbr bs=512 count=1
  • create a virtual disk pointing to the existing partition (as ordinary user):
    % VBoxManage internalcommands createrawvmdk -filename ./wxp.vmdk -rawdisk /dev/sda -partitions 1 -mbr ./wxp.mbr -register
  • create a new VM using the VirtualBox GUI
  • choose “existing” in the “virtual hard disk” page

    and add the wxp.vmdk file to the list of known hard disks

Complete the creation process and finally boot your WXP installation – that should be it 🙂

Spread the love

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of

Post Navigation