Archive

Archive for February, 2009

VirtualBox VM’s on real partitions

February 1st, 2009

I always wanted to give a try to VirtualBox working on a physical partitions, rather than the usual VDI file, mainly to see if there is a performance difference but more importantly because I’d be able to run the hosted operating system on it’s own with a few changes on grub.

Before proceeding I think some warning is needed on what this step-by-step is about.
From VirtualBox user manual:
Warning
Raw hard disk access is for expert users only. Incorrect use or use of an outdated configuration can lead to total loss of data on the physical disk. Most importantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption.

As root add your username to the disk group so that you will have access to partitions:
sudo usermod -a -G disk marty

Now logout and login again or just reboot the system and you should have access to the disk, check if that is true by:

[marty@delorean ~]# VBoxManage internalcommands listpartitions -rawdisk /dev/sda
VirtualBox Command Line Management Interface Version 2.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
1       0x0c  0   /1  /1   1023/254/63        102406           63
5       0x82  1023/254/63  1023/254/63          4102    209728638
6       0x83  1023/254/63  1023/254/63        112643    218130633
3       0x07  1023/254/63  1023/254/63         86090    448823970

We need to create a fake vmdk file that points VirtualBox to the raw disk:



VBoxManage internalcommands createrawvmdk -filename /home/marty/.VirtualBox/HardDisks/realsda3.vmdk -rawdisk /dev/sda3 -register

Output:

VirtualBox Command Line Management Interface Version 2.1.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

RAW host disk access VMDK file /home/marty/.VirtualBox/HardDisks/realsda3.vmdk created successfully.

If everything went like this, you should find a new disk realsda3 in the Virtual Media Manager of xVM.

references:

- the Windows equivalent of this http://www.paulgraydon.co.uk/geeky/nixtricks/virtualbox-win7-centos-on-real-partitions/

- VirtualBox manual http://download.virtualbox.org/virtualbox/2.1.4/UserManual.pdf 9.9. Using a raw host hard disk from a guest

Sysadmin ,