Virtualbox and raw host disk access

The VirtualBox forums lists numerous reports of people not being able to get VirtualBox to work with raw disk partitions. Initially I bumped into the same problems, but got it working in the end.

The setup used in this article is an Ubuntu 12.04 host system with VirtualBox 4.1.18 installed. From disk /dev/sda the partitions 3 and 4 will be made available to a virtual machine. All virtual machines are run as user virtualbox. All console samples show clearly the user that runs the command.

On Ubuntu, raw devices have the following default access rights:

To give the virtualbox user proper access to the disks, the disk group will be extended:

Before going any further, please make sure that any processes currently running as user virtualbox are restarted! This is needed for these processes to pick up the changed permissions. Next to the VirtualBox subsystems, don’t forget to restart the active shell sessions. By adding the virtualbox user to the group disk, the change is also persisted over system reboots.

With the proper access in place, we first create the VMDK file pointing to the raw device:

Assuming that the VM machine1 is already created and contains a storage controller, the raw disk is now attached to the virtual machine:

On successful completion, this command returns no output. If you want to validate that the disk is attached correctly, print the virtual machine information:

That’s it!

Please report typos and/or improvements to this article in the comments!