Virtual Box: using raw hard disk feature to access an external USB storage device

No Comments

Using Virtual Box 4.0.8 for MAC OSX 10.6.7 I was unable to access data on my external USB disk on a Windows 7 guest machine.

No solution was found after searching the web although there are similar issues out there like:

I was almost ready to give up when I found page 142 on the Virtual Box manual. Section 9.7.1 tells how to configure a physical disk to be accessed as if it was attached to the guest/virtual machine.

So the guest OS instead of accessing the disk using the USB bus it would access using the SATA or IDE bus.

There’s a warning on that page that I’m copying here:

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 impor- tantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption.

Following the instructions on that section I could access my external USB drive successfully.

This is what I did, remember that I’m using OSX as host operation system.

Connected my usb drive. OSX automatically mounts it.

Opened a terminal and wrote mount to find which /dev device is the disk mapped to. It was /dev/disk1s1:

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
/dev/disk0s3 on /Volumes/BOOTCAMP (ntfs, local, read-only, noowners)
/dev/disk1s1 on /Volumes/SergioDrive (exfat, local, nodev, nosuid, noowners)

Now before using it on virtual box I unmounted it on OSX:

$ diskutil unmount /Volumes/SergioDrive
/Volume SergioDrive on disk1s1 unmounted

Now I created the virtual box image file that I’ll use to configure my virtual machine:

$ VBoxManage internalcommands createrawvmdk -filename ~/VBAccessToSergioDrive.vmdk -rawdisk /dev/disk1s1
RAW host disk access VMDK file /Users/machados/VBAccessToSergioDrive.vmdk created successfully.

Now you can use the virtual box gui to add the image file as a disk to the virtual machine. This is done under the storage definitions. I added another disk under SATA controller.

This can also be done on the command line with this command:

$ VBoxManage storageattach "Windows 7" --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium ~/VBAccessToSergioDrive.vmdk

The command has no output. Of course “Windows 7″ is the name of my virtual machine.

This image file can only be used with the same physical external disk because it maps the UUID of the disk.

Leave a Reply