VirtualBox is a free and easy to use multi-platform Virtualization software.
It means you can run a different OS inside your current OS (Linux in Windows, Windows in Linux, Linux in Linux, Windows in Windows, almost everything is possible!).
It is very easy to start a new virtual machine and use space on a virtual hard drive on your local hard drive (or USB drive). Just follow the VirtualBox wizard.
However, some people want more portability in the physical meaning. To have a system that you can put in your pocket, bring anywhere, plug into any computer and it will run YOUR system.
This is possible by installing a system on a USB stick! This guide won't explain how to install an OS on a USB stick but how to boot on this USB disk in VirtualBox.
Sometimes you don't want to boot on your USB stick directly but within another running system. Then, you need to run the system in a Virtual Machine.
Unfortunately, VirtualBox doesn't allow you to boot from the USB from the GUI.
Nevertheless, there is a small trick to make it possible, using only a single built-in VirtualBox command-line tool.
Let see how to do so in this tutorial!
This tutorial is largely inspired by the Boot your USB Drive in VirtualBox tutorial by AgniPulse, only updating it to the last current version of VirtualBox (4.0).
I assume you have:
- 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 Files\Oracle\VirtualBox"
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:\Users\Thomas\.VirtualBox\usb.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:\Users\Thomas\usb.vmdk -rawdisk \\.\PhysicalDrive1
Replace the 1 in \\.\PhysicalDrive1 by YOUR device number os the USB drive (for example \\.\PhysicalDrive2).
VBoxManage internalcommands createrawvmdk -filename "C:\Documents and Settings\Carletdesiles\.VirtualBox\usb.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.
You can do it step by step by following the screenshots:
You can see the result of my Ubuntu 10.10 on my 8GB USB stick running on VirtualBox on Windows 7 at the very beginning of this article (first screenshot).
Video Summary of this tutorial