Tuesday, July 5, 2011

Accessing your Physical Hard Drives/Disks from a Virtual Machine (VirtualBox)

I recently found that my computer running Ubuntu 64-bit had problems with the nForce motherboard SATA drivers and I kept getting errors. However, having used Linux long enough, I realized that I had a good alternative, which is to use Windows with a Virtual Machine running Ubuntu Server, easy enough to do.

But there was something that I forgot, which was that my hard drives were in ext4 format, but instead of taking the easy way (moving around data in a Live USB and reformatting the drives), I decided to try to access the data from the Ubuntu virtual machine, because I knew it was possible (without any proof).

Accessing the physical drives from VirtualBox allows for full support of the filesystems supported in the guest and (I'm pretty sure) at full speed. Combined with shared folders, this is very useful.

Any way, here is the end result done on VirtualBox (because it's the best and free):

First, you need to create a VMDK file describing the physical drive so that you can access it through VirtualBox. To do this you will first need to know the location of the drive, which looks like "\\.\PhysicalDriveX" where "X" is a number for Windows users, and /dev/sda (\\.\PhysicalDrive0), /dev/sdb (\\.\PhysicalDrive1), and so on for Linux users.

On Linux you can easily list the drives with the command (as root):
# fdisk -l
On Windows, you can find the drive number in many ways.
The easiest way is to open the Disk Manager by right clicking on "My Computer" or "Computer", clicking on "Manage" to open "Computer Management", and then clicking on "Disk Management". The bottom pane lists the disks with the correct disk numbers.