Linux: virtualbox using physical bootable partition
I recently reformated my laptop hardrive to use ArchLinux instead of Gentoo. So I decided to make a special partition to run WinXP natively as well as under virtualbox. I just explain a little the steps I followed to make it working…
First, you need to partition your harddrive correctly. That is to say that any bootable partition must be primary.
As a simple example here is my partition scheme for a 160Gb drive:
/dev/sda1 : Primary, /boot (ext2fs, 180 Mb)
/dev/sda2 : Extended Master
/dev/sda3 : Primary, MacOSX (HFS+, 20Gb)
/dev/sda4 : Primary, WinXP (FAT32, 9Gb)
/dev/sda5 : Extended, / (XFS, 20Gb)
/dev/sda6 : Extended, /var (ReiserFS, 9.5Gb)
/dev/sda7 : Extended, /home (XFS, 95Gb)
/dev/sda8 : Extended, Linux swap
As you can see, I use /dev/sda4 as my windows XP partition.
A Virtual disk as partition wrapper
Virtualbox is not able to use physical partition easily out of the box. In fact you have to create a fake disk image that define how to access the physical partition.
Making a pseudo MBR
If you want to make the partition bootable you will need to make a pseudo MBR (Master boot record). The package “ms-sys” contains the tool to build one:
pacman -S ms-sys # install ms-sys package
touch ~/.VirtualBox/WindowsXP.mbr # the file that will receive the MBR must exists...
ms-sys --mbr -f ~/.VirtualBox/WindowsXP.mbr # create a MBR and store it in a file
Making the fake disk image
To do so, open terminal and be sure that your user is part of the “vboxusers” and “disk” groups.
Then use VBoxManage (for /dev/sda4):
VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/VDI/winxp_sda4.vmdk \
-rawdisk /dev/sda -partitions 4 -relative -register -mbr ~/.VirtualBox/WindowsXP.mbr
just after “-filename”, you can see the virtual disk file that will represent the VirtualBox disk.
“-rawdisk /dev/sda -partitions 4” is for using /dev/sda4
Using the new partition
Create a new virtual machine and choose the existing harddisk we just created. When the VM wizard has finished, select the VM and edit its setting to turn on “IO APIC”.
You can install windows XP either using the VM or booting natively.
As soon as Windows is installed, go to settings / system and open the hardware list windows. find the IDE controller and change the driver to be the “generic IDE”.
Then, create a new hardware profile. You can reboot the computer or th VM. You will now have to choose the profile to use before booting.
Now you can install all needed drivers for each profile, but do not try to boot VirtualBox with the profile used for the hardware boot, else it wont work (and vice-versa).