Quickie: Booting Virtualbox from a USB thumb drive

I’m interested in customizing the excellent clonezilla, so that we can simplify our imaging operations. The easiest way to do that is to create a bootable and customizable USB thumb drive. I was then hoping to test the thumb drive customizations using VirtualBox running on my Mac. Booting Virtualbox from a USB key is something of a chore.

Here are the steps that I went through – I’m writing them down just in case I need the information again in the future.

  1.  Follow the instructions on how to create a bootable clonezilla thumbdrive.
  2. Customize the thumbdrive to do whatever it is you need it to do.
  3. Create a new guest machine in Virtualbox for testing. Configure this with a normal OS, etc. Next, you’re going to create a special VMDK disk file that points at the  thumb drive. This means that you are going to leverage VB’s ability to use an entire physical disk as a virtual disk on a virtual machine.
  4. Shutdown the guest OS and Virtualbox.
  5. You need to know the name of the disk file that will become the raw hard disk for the VB guest machine. Insert your thumbdrive. Allow it to mount. Open a terminal window. Type the command “diskutil list” at the command prompt. Figure out the device name of the thumb drive. This is a classic “measure twice, cut once” situation. If you mess this up, you can render your host system unusable. In my case, it was “/dev/disk2”.
  6. Add a “raw” host hard disk to the Virtualbox machine by doing this in Terminal:
$ cd /Applications/VirtualBox.app/Contents/MacOS/
$ sudo -s
# diskutil unmount /Volumes/UNTITLED
# ./VBoxManage internalcommands createrawvmdk -filename /Users/bjchapm/usb.vmdk -rawdisk /dev/disk2
# chmod 666 /dev/disk2

That’s about it. You need to become root (using sudo) so that you can run the unmount command to take the thumbdrive away from OSX. At this point, you will need to add the VMDK file to Virtualbox the way that you would add any new disk to a virtual machine. Now you’re ready to test the USB thumbdrive.

Note that any time you stop Virtualbox, OSX will re-assert control over the USB key. You will need to open a terminal window and run “sudo diskutil unmount /Volumes/UNTITLED” manually before launching Virtualbox.

Please share your thoughts in the comments.

Advertisements

2 thoughts on “Quickie: Booting Virtualbox from a USB thumb drive

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s