Here I explain how to use a Physical disk partition for a guest OS under VirtualBox. This is also called Raw Disk partition use for VirtualBox. My use case was to run WindowsXP as guest OS from a physical installation under Linux and still be able to boot up the system in same Windows installation when needed. My system is running Ubuntu 11.04 on core2 duo, 3GB memory, two hard disks (one with Ubuntu and other with WindowsXP installation), with VirtualBox 4.0.4. Process is simple but took quite a while to get all information/steps collected and tested. In nutshell, first we need to know the partition that we will use, then the user who is going to use it needs to have access to it. After that an mbr has to be created and finally a vmdk file is created to use the Raw Disk. Keep reading for the full process.
- Lets assume our raw disk is /dev/sdb.
unixite@sandbox:~/ > sudo fdisk -l /dev/sdb Disk /dev/sdb: 160.0 GB, 160000000000 bytes 255 heads, 63 sectors/track, 19452 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xd0f5c1be Device Boot Start End Blocks Id System /dev/sdb1 * 1 19452 156248158+ 7 HPFS/NTFS
- First add the user that is going to run VirtualBox to the disk group (or the group to which this disk belongs, use lsto find the right group for your system. Without this step, you will not be able to create a vmdk file. It will complain of accessibility error with the raw disk. After that logout and log back in or start a fresh new shell that shows that the user now belongs to disk group. (Update : 2011-11-11 Thanks kszys for suggesting the correction to usermod command)
unixite@sandbox:~/ > ls -l /dev/sdb brw-rw---- 1 root disk 8, 16 2011-05-11 10:32 /dev/sdb unixite@sandbox:~/ > sudo usermod -a -G disk unixite
- Create an mbr (master boot record) to use with Windows. This is a must step otherwise you could get “grub> Unknown format” (or similar) error. mbr package has utilities to create an mbr file (install it using sudo apt-get install mbr). Be careful. Here we want to only create an mbr file and not modify any disk settings.
unixite@sandbox:~/ > install-mbr --force WinXP.mbr unixite@sandbox:~/ > ls -l WinXP.mbr -rw-r--r-- 1 unixite unixite 512 2011-04-29 11:29 WinXP.mbr
- Create a Virtual Disk out of the real raw partition. This will not create a huge disk or a copy. It will only create the settings to make use of the raw partition. So here we tell VBoxManage that /dev/sdb is the real raw disk, from which we want to use partition 1 for this purpose and mbr to be used is in the given file.
unixite@sandbox:~/ > VBoxManage internalcommands createrawvmdk -filename /home/unixite/.VirtualBox/WinXP.vmdk -rawdisk /dev/sdb -partitions 1 -relative -mbr WinXP.mbr RAW host disk access VMDK file /home/unixite/.VirtualBox/WinXP.vmdk created successfully.
- Once the disk is created, you create a virtual machine or add this disk as primary disk to already existing virtual machine which is a very much established process.
- Boot up the system and it could crash or give blue screen on death first time. If it does, then boot in safe mode first, followed by the normal mode and it will work out ok.
Note: For me the SATA emulation for the RAW disk (under VirtualBox) did not work. I had to use the IDE emulation for the real SATA disk to get this working. There is some patch available to break windows binding to a given SATA driver and go more generic, but I did not try that yet.