March 26

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).

Note: As noticed by Carlet, if any path contains spaces, write it between quotation marks (“) to make it work.
Example: VBoxManage internalcommands createrawvmdk -filename "C:Documents and SettingsCarletdesiles.VirtualBoxusb.vmdk" -rawdisk \.PhysicalDrive1
Note: As noticed by Alex and skydvr, on Windows Vista/7, you need to start the command prompt as administrator (right click -> run as administrator) in order to access to the USB drive/stick.

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


Copyright 2021. All rights reserved.

Posted March 26, 2014 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B