Booting a VirtualBox guest from a USB flashdrive

I do a lot of work with booting different operating systems, mostly various Linux distributions. One hot area is storing the OS on a USB flash drive and booting from that. For testing my work, using virtual machines to test the OSs is a godsend. However, neither VirtualBox nor VMWare Server give any obvious indication that they support booting a guest machine from a flash drive plugged into the host's USB slot; matter of fact, there are all sorts of forum posts indicating that they don't support this. In fact, VirtualBox does. The steps I used are described below. See Chapter 9 of the VirtualBox Manual for more info. I did this using VirtualBox 2.1.4 on Ubuntu 8.10 and Fedora 10; it should work on Windows but I don't use Windows so I can't be certain.
  1. Plug in your flash drives and run mount to find which device file is assigned to flash drives. In my case, it was /dev/sdb. The flash drive had just one partition so it appeared as sdb1, but it's the sdb part that is of interest. It doesn't seem to matter to VB whether the drive is mounted or not. Just be sure you unmount it (umount) before removing it.
  2. Make sure you have write permissions for /dev/sdb. I did not, but the group disk did, so I just added myself to that group, logged out, and then logged back in.
  3. Use the VBoxImage command to create an image file linked to dev/sdb:
    VBoxManage internalcommands createrawvmdk -filename /home/petre/.VirtualBox/HardDisks/flashdrive.vmdk -rawdisk /dev/sdb
    Do not use the -register parameter with this command. If you do, the image will be tied to the flash drive that was plugged in at the time and won't work with any other flash drives.
  4. Create a virtual machine in the VB GUI, and select the flashdrive.vmdk file to be the hard drive.
  5. Boot the virtual machine.
I don't know the effects of saving things within the guest system, so if you're going to do this, proceed with caution. It may corrupt the flash drive; or not, I haven't tried it.