Using RAW Devices In VirtualBox VMs
Author: Falko Timme
Follow me on Twitter
Usually, VirtualBox creates its virtual machines in disk images (.vdi, .vmdk, etc.). This tutorial explains how you can use RAW devices from the host (partitions, LVM volumes, etc.) and create a VirtualBox VM in it. I will also explain how to mount a RAW device in an existing VM.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
Because I've installed VirtualBox on a headless server, I'm using phpvirtualbox as the VirtualBox GUI here. If you use the original VirtualBox GUI, that is perfectly fine.
My VirtualBox host uses LVM, so I will concentrate on using LVM volumes as RAW devices in this tutorial. The procedure is the same for "normal" partitions.
Make sure that you are logged in as root (type in
to become root), because we must run all the steps from this tutorial as root user.
2 Add The VirtualBox User To The disk Group
Before we start, we must make sure that the user under which we run VirtualBox is a member of the disk group. If you use phpvirtualbox, the username is probably vbox. If you use the normal VirtualBox GUI, the username is the name under which you are logged into your Linux desktop.
usermod -a -G disk vbox
To make sure that this change takes effect, it is a good idea to reboot now:
3 Prepare A RAW Device For Use With VirtualBox
As I mentioned before, I'm using LVM volumes here. Let's create a 20G volume called vm10 (the virtual machine I want to create will have the name vm10) in the volume group vg0:
lvcreate -L20G -n vm10 vg0
Next we must create a .vmdk file that tells VirtualBox to use the RAW device /dev/vg0/vm10. It's probably best to create it in the home directory of the user under which VirtualBox is running (e.g. /home/vbox if you use phpvirtualbox) - the file must also be owned by that user:
VBoxManage internalcommands createrawvmdk -filename vm10.vmdk -rawdisk /dev/vg0/vm10
chown vbox:vbox vm10.vmdk
4 Create The VM In VirtualBox
Next go to your VirtualBox GUI (original VirtulBox GUI or phpvirtualbox) and use the Create New Virtual Machine wizard to create a new virtual machine. On the Virtual Hard Disk screen, select Use existing hard disk and click on the Choose a virtual hard disk file icon:
Select the .vmdk file (vm10.vmdk in this example) that we have created in chapter three and click on OK:
Click on Next >>...
... and on Create:
Now create the virtual machine as you would normally do in VirtualBox.
You are now using a RAW device instead of a disk image for the virtual machine.