Using RAW host disks in VirtualBox on Mac OS 10.5

The manual of VirtualBox has a section called Using a raw host hard disk from a guest which explains in detail how to use raw disks from the guest host. However, it’s a bit tricky on Mac OS as you have the disks automatically mounting. Here is a small HOWTO showing how to mount a USB stick (using Mac OS 10.5) so it can be used as the IDE Primary Master in VirtualBox.

Warning: this is probably for more advanced users. Careful what you do with mounting and umounting manually!

Start by inserting the USB stick and see if gets mounted in Finder. If you would Eject the device, it gets u(n)mounted, but you can’t use it anymore in VirtualBox. The trick here is to use diskutil (which replaces disktool) in a Terminal session. I assume the volume (e.g. USB stick) is empty.

Preparing the volume:

  1. Launch the Terminal application
  2. At the prompt do: diskutil list
    • Look for your device in the list, probably at the end. In my case it was /dev/disk4
    • Now lets u(n)mount it (not eject!): diskutil umountDisk /dev/disk4
  3. At this point, your Finder window might disappear. But that’s not a problem.

To make the volume available to VirtualBox we need to create a VMDK file. This is described fully in the manual, but here it is in a few steps:

  1. Launch the Terminal application
  2. Go to the location where you store your Hard Disk images, e.g. cd ~/Virtual
  3. Execute (on one line, changing filename and the actual rawdisk): VBoxManage internalcommands createrawvmdk -filename ./USBStick.vmdk -rawdisk /dev/disk4
  4. Open the VirtualBox application, and from the File Menu launch the Virtual Media Manager
  5. Click Add, and locate the file you created, e.g. USBStick, and click ‘Open’. At this point, you should have the new Virtual Hard Disk available which you can use to make a new virtual machine. Use the disk you created as the primary hard disk just like you would do with hard disk images.

Some errors you might run into:

  • VBoxManage reports VERR_DEV_IO_ERROR: this means the volume is still in use by Mac OS. You should first unmount it using diskutil (see earlier in this post)
  • Mac OS keeps mount the volume: I didn’t find a good solution for this (i.g. using /etc/fstab is no good, and scripting was to much work). I just kept unmounting it using diskutil until VirtualBox locked it.
  • VBoxManage reports VBOX_E_IPRT_ERROR, and lots more: This is when storage format could not be read. I’m not sure why this is reported, but the RAW host disk VMDK was created successfully in my case, and can be used.

A caveat doing the above: you’ll need to remake the VMDK file if the disk is on a different device. This can for example happen when you first insert a DVD, and then the USB Stick. Maybe there is a solution for this using /etc/fstab or similar in Mac OS.

I had to do the above to make an installation on a USB stick. Ubuntu somehow failed during the installation (not sure why..); now I’m trying OpenSolaris.

Whatever you do, make sure your USB Stick is fast: I got a slow, cheap one now and it takes forever to format..

Comments

ionas
Thanks for sharing.
Another way that worked for me:
- Connect USB Stick Hardware to your Mac.
- Eject it from the Finder. Make sure its still in as hardware in your System Profiler under USB.
- Start Virtual Box. It should be there then.