Jul
25
2009

Boot your USB Drive in VirtualBox

The GUI of VirtualBox does not have an option to boot a USB drive (Physical Drive) in a virtual machine.

However you can attach a physical drive to a virtual machine using a command line tool that is bundled with Virtual Box.You can then boot your virtual machine from the attached Physical drive.You need to use VirtualBox with Windows installed in order to use the software for a o2 mobile broadband dongle. As you are probably aware, you are unable to use it with Linux.

This is the continuation of my previous article Test bootable USB drive without restarting your computer.You can read more about bootable usb drives in that article.

Note:This tutorial has been updated for Virtualbox 4.

In this article I will show you how you can boot a bootable usb drive in Virtual Machine created by VirtualBox.You can easily test bootable USB drives within Windows or Linux and without restarting using this method.

Download and install Virtual Box and VirtualBox 4.0.2 Oracle VM VirtualBox Extension Pack from http://www.virtualbox.org/wiki/Downloads
The Extension pack adds support for USB 2.0 devices.

Attaching a Physical Disk to a Virtual Machine

Section 9.6 in the VirtualBox manual contains all the details required to attach a physical disk to a virtual machine.Using the vboxmanage.exe tool you can create a tiny vmdk file which points to your real USB drive (Physical Drive/Disk).You can attach this tiny vmdk to your virtual machine.A vmdk file is a virtual hard disk file which can be used with VirtualBox and VMWare.

The vboxmanage.exe tool is bundled with VirtualBox.You don’t have to download it separately

Open Command Prompt

Navigate to your Virtual Box installation Directory.

cd "c:\Program Files\Oracle\VirtualBox"

Type the following command and press enter
Syntax of the command

VBoxManage internalcommands createrawvmdk -filename path\to\usb.vmdk -rawdisk \\.\PhysicalDrive1

You have to replace pathtousb.vmdk with the path of your choice

Example

VBoxManage internalcommands createrawvmdk -filename "%USERPROFILE%\usb.vmdk" -rawdisk \\.\PhysicalDrive1

createraw Boot your USB Drive in VirtualBox

In Windows your 1st Hard Disk will be \.PhysicalDrive0.Your 2nd Hard disk will be \.PhysicalDrive1.

Warning:Do not Attach your Primary hard disk to your Virtual Machine and Boot it in the Virtual machine

To find the correct number for your USB Drive

Right Click on My Computer-Manage-Disk Management

Here you can find the correct disk number of your USB Drive

15zi9s6 Boot your USB Drive in VirtualBox

You will have to replace \.PhysicalDrive1 with the correct drive number.

In this case there was only 1 hard disk and 1 USB disk.So the USB drive is referred by \.PhysicalDrive1

In linux you have to replace \.PhysicalDrive1 with the correct /dev/sdx reference.

Now you should have a tiny vmdk file.You can start your Virtual Machine with this tiny vmdk and boot from it.

  1. Start VirtualBox.
  2. Create a new Machine or Select an Existing Machine.
  3. Click on Settings
    vmsettings Boot your USB Drive in VirtualBox
  4. Storage-Add Hard Diskaddharddisk Boot your USB Drive in VirtualBox
  5. Select the vmdk file that you had created.selectharddisk Boot your USB Drive in VirtualBoxvmdkfile Boot your USB Drive in VirtualBox
  6. Make sure that usb.vmdk is your Primary Master.attachedusb Boot your USB Drive in VirtualBox
  7. System-Boot Order.Set your Hard Disk as the first boot device.
  8. Now start your Virtual Machine.

Your virtual machine will boot from your bootable physical USB Drive.

In this screenshot I have used a bootable Ubuntu USB drive created using Unetbootin.

2jfiy39 Boot your USB Drive in VirtualBox

1470ut Boot your USB Drive in VirtualBox

121bekz Boot your USB Drive in VirtualBox

«

»

About the Author: Bharat Balegere

Bharat Balegere is a 22 year old blogger from Bengaluru. He is a technology enthusiast and loves tinkering with computers and usb drives.

102 Comments + Add Comment

  • Use plop bootmanager its way easier

    • plop did the job, thanks :)

  • Tried this using Ubuntu 11.04 host and Virtualbox 4.1
    Virtualbox refuses to use the .vmdk file giving an error…
    NS_ERROR_FAILURE (0×80004005)
    Tried changing permissions, etc.

    Any thoughts?

    • In linux you have to be root if you want to access /dev/sdfX

    • I wasn’t very clear…

      I mean you have to be root to access /dev/sdfX, so virtualbox must be running as root (or sudo) to access your usb drive.

      Your vmdk file is like a “pointer” to /dev/sdfX… at least as I undestand it…

  • This don’t work. Keeps flipping “Invalid parameter” in the image path. llameeeeeee

  • How to boot from USB in another Computer which have xp installed using virtualbox?

  • Works on windowsxp. I try install ubuntu 11.10. Thanks

  • it is a good tutorial. but in both the cases ie to create usb.vmdk and load it as hard disk in new machine, the cmd.exe and virtualbox must be run with administrator rights. this was the mistake i did at first.

  • DOES NOT WORK!

    VB says the file is inaccessible. However, the CLI program claims to have succeeded in creating the USB.vmdk. and i checked. so why say its not accessible??? any answers?

    • It appears that you need to run virtualbox as admin (sudo) to access raw disks:
      http : // luckyviplav.wordpress.com/2010/07/17/windows-7-on-mac-os-x-through-virtual-box/

      See the comments by Marcos Vives.

      Cheers,
      ak.

  • Superb! Tested and works with VirtualBox 4.1.2 on Win7 x64 as a host. Booting a 32Gb Transcend JF V60 which was made bootable with Diablerie’s Ultimate Suite…

  • Hi, for me doesn’t work! :(
    I give this error:
    VBoxManage.exe: error: Cannot open the raw disk ‘\\.\PhysicalDrive1′: VERR_ACCESS_DENIED
    VBoxManage.exe: error: The raw disk vmdk file was not created

    My usb key is format with fat32 file system… in a problem?
    Thankyou

    • Please run the command with admin privileges.
      Right click on Command Prompt and choose Run as Administrator.

      • Thankyou worked for me once i:
        ran cmd prompt as administrator
        ran virtualbox as administrator
        ticked the “solid state drive” box under storage in VB
        and finally unchecked the usb drive filter under “USB” in VB

        …although the os is still trying to load…

        • I forgot to run virtualbox as admin so it wouldn’t load the usb vmdk. many thanks to the comment you made

  • worked really fine, just had to run CMD as ADMIN but also VirtualBox, and it worked like a charm thanx a lot dude!

  • After I ran the programs as admin it worked like a charm! Many thanks…

  • Much of the instruction is almost clear, but just enough unclear to make it confusing and create a situation where steps have to be executed several times. Learn better English.

  • I am success making usb.vmdk, but i can’t insert usb.vmdk on existing Virtual Machine.
    i found message error :

    Failed to open the hard disk D:\New MyData\VBOX\USB\usbFreenas.vmdk.

    The medium ‘D:\New MyData\VBOX\USB\usbFreenas.vmdk’ can’t be used as the requested device type.

    Result Code: E_FAIL (0×80004005)
    Component: Medium
    Interface: IMedium {53f9cc0c-e0fd-40a5-a404-a7a5272082cd}
    Callee: IVirtualBox {c28be65f-1a8f-43b4-81f1-eb60cb516e66}

    can you help me ???
    thank you before

    • Run VirtualBox as administrator. If it install something after the run then wait and when it finish the installation close VirtualBox and run it as administrator again.

      I had the same issue using Windows 7 x64 & I am trying to install Windows 8 x64 RTM.

      Issue resolved.

  • Plop is ok but this is much easier and once it’s done you can reuse it anytime as long as you plug any bootable USB into the same USB port. I D\L the latest VBOX for windows and works on my 64bit Win7 on an AMD quad core as well as my 32bit AMD dualcore Laptop.

    Thanks heaps re-booting my laptop for testing grub and syslinux scheme’s was getting old and hadn’t found QEMU this is even better Kudos Mate !!

  • Work’s fine :D thanks
    example for you

    my disk named “disk2″
    add new folder USB
    run cmd in admin mode
    VBoxManage internalcommands createrawvmdk -filename “\usb\usb.vmdk” -rawdisk \\.\PhysicalDrive2

    run virtualbox in admin mode
    and do what he said, mount it in VB all works, you shouldn’t get any error in mount if you run in admin mode.

  • Windows 7 Pro V6.1 (Build 7601: Service Pack 1)
    VirtualBox 4.2.4 r81684

    Following instructions explicitly. Running CMD as Administrator:
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Windows\system32>cd “c:\Program Files\Oracle\VirtualBox”

    c:\Program Files\Oracle\VirtualBox>VBoxManage internalcommands createrawvmdk -fi
    lename “%USERPROFILE%\usb.vmdk” -rawdisk \\.\PhysicalDrive1
    VBoxManage.exe: error: Failed to create the VirtualBox object!
    VBoxManage.exe: error: Code CO_E_SERVER_EXEC_FAILURE (0×80080005) – Server execu
    tion failed (extended info not available)
    VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or
    failed to start.

    c:\Program Files\Oracle\VirtualBox>

    • I got same error – then it worked. Try closing virtualbox before running the commands.

    • have exactly the same problem

      C:\Program Files\Oracle\VirtualBox>VBoxManage internalcommands createrawvmdk -fi
      lename output_usb.vmdk -rawdisk \.\PhysicalDrive4
      VBoxManage.exe: error: Failed to create the VirtualBox object!
      VBoxManage.exe: error: Code CO_E_SERVER_EXEC_FAILURE (0×80080005) – Server execu
      tion failed (extended info not available)
      VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or
      failed to start.

      • For those receiving the error
        VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or failed to start.

        Try putting this into your path

        set VBOX_USER_HOME=path\to\portablevbox\data\.VirtualBox

        Worked for me.

        Also I had to run the command prompt as administrator as well as load VB as administrator.

        Works fine. XBMCBuntu.

        Thanks for the post!

  • Deer GOD WTF !!! Do you reinvent the wheel every day to drive and maybe Cut your toe Nails WITH A Blow Torch to?
    Step 1 Download and install Virtual Box and VirtualBox 4.0.2 Oracle VM VirtualBox Extension Pack from http://www.virtualbox.org/wiki/Downloads

    Step 2 plpbt-5.0.14.zip download http://www.plop.at/en/bootmanager/download.html extract

    mount the plpbt.iso in Virtual Box

    Done

    No need to hurt your self any more!!!

  • Thanks. Works great on win 7 pro and VB 4.2.6

  • hey! i’m thinking this could also work for a second windows installed on a different hard drive or I can attach a hard drive of a different computer using an enclosure. Is it possible?

  • Worked 100% for me.
    Win 7 Pro x32 VB 4.2.12

1 2

Leave a comment

Switch to our mobile site