Tales of a GeekTrotter Binary Logbook


Boot on your USB Drive in VirtualBox 4

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

VirtualBoxLinux in Windows

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:


Create and format 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:


Disk Management

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

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 Settings\Carletdesiles\.VirtualBox\usb.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.

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


Filed under: IT Leave a comment
  • draxe

    Meeeeerciiiii !!! Juste a cause d’un foutu “e” que j’avais oublié et meme pas vu au passage 🙂 encore merci

  • draxe

    so, now Xubuntu puts many time to starts :/

  • DavidB

    Very good method, thank you very much.
    I have Windows XP SP3 x86 and I’m using VirtualBox as admin.
    Only one problem: any changes made to the USB drive in the virtual machine are not visible in the host OS until I remove it and reattach it.
    I tried a tool called sync.exe, who flushes the Windows RAM buffer, no change.
    I tried also to change usb.vmdk to writethrough, still no change.
    Is there any good setting for this, or even a tool/command (preferably fast too), perhaps even one that can be used in a batch file…?
    Please help me…
    Thank you.

    Regards, DavidB

    • ThomasDalla

      Hi David,
      I have never tried that so cannot really help, but have you tried creating a separate partition on the USB? Data on that non-system partition should be available to both environments.

      • DavidB

        Thank you.
        But I already have 4 partitions on USB drive: one bootable Fat32 20 GB, one Linux ext4 30 GB, one logical Linux swap 2GB and one logical NTFS with the rest of the space (USB drive is 500 GB).
        The first and the fourth partition are visible in Windows and on both there is the same problem.
        But even if this would of worked, I need that ANY partition from USB (system/primary/logical) to show changes made in virtual machine into the host OS.

        Regards, David

      • DavidB

        Well, I found a solution: using mountvol command to dismount USB drive’s volume(s) before starting the VM and to mount them again after closing the VM.
        All can be done in a batch file so it will be very easy to use…

  • Gene Ricky Shaw

    Awesome! It worked on the first try for me. Thank for not only writing a great tutorial but making it cross platform! You ROCK!

  • DavidB

    There is a tool who does that automatically. It’s called “Virtual machine starter”. Works with Qemu and VirtualBox. More: it’s able to automatically dismount the volumes from the USB drive before the VM starts and to remount them back after it’s closed. This way it can prevent any data loss on the USB drive (from been accessed simultaneously by 2 computers) and you can see any modification made inside the VM (to the USB drive) into the real computer right after the VM is closed.

    Where you can find it: go to reboot pro → Boot methods & tools → Boot from USB / Boot anywhere → Booting VirtualBox with USB workaround (last page of the thread).

  • Dan Dart

    Cool!VBoxManage internalcommands createrawvmdk -filename /home/thomas/.VirtualBox/usb.vmdk -rawdisk /dev/sdb

  • Quentin Etienne

    Je ne trouve pas le dossier VirtualBox sur Ubuntu, vous donnez le chemin pour windows mais pas pour Linux ^^’

    • ThomasDalla

      Tu veux dire le dossier d’installation de VirtualBox ? (l’équivalent C:Program Files…)
      Si c’est le cas, tu n’en as pas besoin, VBoxManage devrait être dans ton PATH déjà sous Linux donc tu dois pouvoir lancer la commande depuis un terminal dans n’importe quel dossier.

      Si ce n’est pas le cas, ça doit être dans /usr/bin je pense.

      • Quentin Etienne

        Ok, je vais voir ça. Merci.

  • guest

    Sorry, accidentally replied to some else’s posts below. Reposting as a normal comment:

    Hey, thanks for the post! I managed to create the file using the command you offered, and I was able to import the hard drive, BUT once I try to start the system I receive a “RESOURCE_BUSY” error. I received a similar error first when trying to import the hard drive, but unmounting the USB key did the trick. If I unmount the disk before starting the system, however, the system starts and tells me that there is no bootable drive. I’m not sure what to do, I’ve pasted the error message below. Also, my host is Mac OSX Mavericks. Thanks!

    Failed to open a session for the virtual machine Ubuntu

    VD: error VERR_RESOURCE_BUSY opening image file ‘/Users/Me/VirtualBox/usb.vmdk’ (VERR_RESOURCE_BUSY).

    Failed to open image ‘/Users/Me/VirtualBox/usb.vmdk’ in read-write mode rc=VERR_RESOURCE_BUSY (VERR_RESOURCE_BUSY).

    Failed to attach driver below us! Device or resource is busy. (VERR_RESOURCE_BUSY).

    PIIX3 cannot attach drive to the Primary Master (VERR_RESOURCE_BUSY).Result Code: NS_ERROR_FAILURE (0x80004005)Component: ConsoleInterface: IConsole {8ab7c520-2442-4b66-8d74-4ff1e195d2b6}

    • ThomasDalla

      Have you tried as sudo/root?

  • titi

    t’as fais ça en root ?

  • Arthur Letrue

    Bonsoir, j’ai suivi ce petit tutoriel mais au moment de lancer VM, j’ai un premier message d’erreur qui dit qu’il n’a pas accès au kernel et un suivant qui apparait en disant ceci :
    p, li { white-space: pre-wrap; }
    Code d’erreur :
    E_FAIL (0x80004005)
    Composant :
    Interface :
    IMachine {480cf695-2d8d-4256-9c7c-cce4184fa048}

    Je tiens à préciser que je veux booter une version linux siyuer sur un disque dur externe (disque 1)
    Que c’est-il passé ? Que dois-je faire ?
    Merci pour vos futurs réponses.

  • isselu

    well i have a issue…. it says that i have installed the oracle virtualbox extension and then when i try to open windows 7 with usb2 turned on this comes up…

    so i don’t know how to solve this, and help would be much appreciated 🙂