Linux: Boot a USB drive in virtual box
Assumed:
- a bootable USB stick/drive with the system you want to boot on
- VirtualBox installed with the Expansion Pack (to support USB2 devices)
First, we need to know what is the device ID of your USB. Plug your USB in.
If you are running VirtualBox on Linux, the USB ID will be something like /dev/sdx (for example /dev/sdb for me).
On Windows, you can see it in the “Disk Management”.
Start typing “dsk” after entering the Start Menu and choose Create and Format Hard Disk Partitions:
Then you will have a page where you can identify the device number of your USB stick or drive.
In my case, my 8GB USB stick is on the Disk 1:
Note that on Ubuntu with VirtualBox 4.0.4 OSE (Open Source Edition): Make sure that you remove the USB device from the “USB Device Filters” list in the machine’s settings (thanks Tim).
Now we are ready to create a Raw Virtual Machine Disk that will link to our USB stick.
Simply open a terminal on linux or a command-line tool on Windows (Win+R cmd) and change directory to your VirtualBox folder.
cd "C:Program FilesOracleVirtualBox"
Then we run the VBoxManage command with the following options to link the USB Drive to a vmdk file (Virtual Machine Disk):
VBoxManage internalcommands createrawvmdk -filename output_usb.vmdk -rawdisk path_to_usb
You need to change the two red color highlighted parts to YOUR settings.
For example on Linux if I want to save in /home/thomas/.VirtualBox/usb.vmdk a virtual machine disk that links to my USB in /dev/sdb, I type the following line:
VBoxManage internalcommands createrawvmdk -filename /home/thomas/.VirtualBox/usb.vmdk -rawdisk /dev/sdb
On Windows, if I want to save the virtual machine disk in C:UsersThomas.VirtualBoxusb.vmdk that links to my USB in in Disk 1 (according to the previous Disk Management), I type the following line:
VBoxManage internalcommands createrawvmdk -filename C:UsersThomasusb.vmdk -rawdisk \.PhysicalDrive1
Replace the 1 in \.PhysicalDrive1 by YOUR device number os the USB drive (for example \.PhysicalDrive2).
Example:
VBoxManage internalcommands createrawvmdk -filename "C:Documents and SettingsCarletdesiles.VirtualBoxusb.vmdk" -rawdisk \.PhysicalDrive1
That’s it, you have done a Virtual Machine disk that should be very tiny (~1KB) and links to your USB drive.
You just need to import this hard drive in VirtualBox and use it as primary hard drive (to boot on) for your new system.
By: Thomas