Bharat Balegere 's Undocumented Tech Tips

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.

This is the continuation of my previous article.You can read more about bootable usb drives in my previous article.

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 and without restarting using this method.

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

Download and install Virtual Box from here http://www.virtualbox.org/wiki/Downloads

Attaching a Physical Disk to a Virtual Machine

Section 9.10 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”\Sun\”xVM VirtualBox”

Type the following command and press enter
Syntax of the command
VBoxManage internalcommands createrawvmdk -filename path\to\usb.vmdk -rawdisk \\.\PhysicalDrive1 -register
Example
VBoxManage internalcommands createrawvmdk -filename c:\Users\Agni\.VirtualBox\VDI\usb.vmdk -rawdisk \\.\PhysicalDrive1 -register

You have to replace path\to\usb.vmdk with the path to your VDI folder(Where all your virtual hard disks are stored).If you want to save your usb.vmdk in different location,then you will have to add the usb.vmdk file manually in the GUI.This is because the register switch only registers the virtual hard disks stored in the User ’s VDI folder .

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

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

Drive Number of the Physical Drive

Drive Number of the Physical Drive

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/sda 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. Settings-Hard Disk-Add-Select usb.vmdk
  4. Make sure that usb.vmdk is your Primary Master.


  5. System-Boot Order.Set your Hard Disk as the first boot device.

    Boot Order

  6. Now start your Virtual Machine.

Your virtual machine will boot from your bootable physical hard disk.

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

 

Like This Post ?

RSS Digg Twitter StumbleUpon Delicious Technorati Reddit Facebook Mixx Diigo Google Yahoo

28 Comments

  • Jess says:

    Thanks. You resolve my problem. ^^

  • maxschaf says:

    thanks a lot.

    notice:
    running windows 7 (i also guess windows vista) with UAC turned on you have to run cmd and virtualbox as an administrator to get access to the usb drive!

  • madar says:

    Very nice description ,i am going to try .

  • Jesus Martinez says:

    Gracias, has resuelto mi problema. A seguir experimentando

  • Uridium1 says:

    Excelent!!! your guide is EXCELENT!

  • Ionreflex says:

    Thnaks, that helps a lot… maybe not to fix my issue, but a damn nice way to troubleshoot!

    ;o)

  • smilehsu says:

    Thnaks, but this is only for windows? In ubuntu how to use USB Driver boot as VirtualBox ???

  • Sergey says:

    I have external bootable usb-hdd with ms-dos installed (+some utilities) and Windows XP as host OS.
    Attaching and booting usb-hdd in VirtualBox works fine, but any changes made on this disk in guest OS (ms-dos) are not actually saved on disk i.e. i did not see any changes when explore usb-hdd in my host OS (Windows).
    For example, i successfully create some file in guest ms-dos, it is shown in file system (via ‘dir’ command). But when i close my virtual pc and explore this usb-hdd in my host OS, this file does not exist!
    What is the problem?
    ps: excuse me for my bad english )

    • Yoni says:

      I haven’t tried it, but perhaps you should set the drive to Writethrough instead of Normal (the default).

      Either change it in VirtualBox.xml or use `VboxManage.exe modifyhd ` (see the user manual for more information).

  • Patrick says:

    Thanks genious!

    Now that I can boot from the USB key (created by Symantec Ghost for Broadcom NICs), the next problem to solve is joining the network interfaces between the physical and virtual. Or may be more simpler get the drivers that VirtualBox is simulating.

    I’m doing this for documentation with screenshots.

  • Tendy says:

    Thanks but your command generates this error while creating vmdk

    Syntax error: Invalid parameter ‘and’

    • Bharat Balegere says:

      Which version of Virtual Box are you using and which Operating system?
      Are you sure you have entered the commands correctly?
      Can you post the exact command you tried?

  • marco says:

    thanks a lot, a very helpful article

  • Ruud says:

    Its working!
    Wow.
    I’m making a bootable usb-stick with several programs/minixp/bootcd etc. And now i dont have to switch constantly.

    Many thanks for the tut

  • Youpi says:

    Great!
    Very clear explanations and works perfectly.
    Thaks a lot.

  • Yoni says:

    Works great, thanks!

    BTW, for those who are paranoid like me, there’s a simple way to mount the physical device as read-only.

    In the .vmdk file, under “Extent description”, change RW to RDONLY.

  • parsons says:

    If you take this cmd :
    VBoxManage internalcommands createrawvmdk -filename D:\Documents and Settings\y\.VirtualBox\VDI\usb.vmdk -rawdisk \\.\PhysicalDrive2 -register
    You will get [Syntax error: Invalid parameter ‘and’]

    Take this cmd :
    VBoxManage internalcommands createrawvmdk -filename “D:\Documents and Settings\y\.VirtualBox\VDI\usb.vmdk” -rawdisk \\.\PhysicalDrive2 -register
    Its works great!

  • Joe Dowd says:

    Thank you Bharat for taking the time to post these excellent instructions :-) )

  • Mike says:

    Thanks for the tips. Your article actually reminded me that USB drives are reported as “PhysicalDriveN” as well.

  • Tesla-dln says:

    Аллилуйя!!! :) Используя данный способ, прекрасно загружаюсь с USB-HDD. Большое спасибо… Thank you very much :D

  • Rom4ik says:

    Thanks a lot! Now I can boot from my USB-HDD!

  • Ace says:

    Thanks Mate, Helped…

Trackbacks and Pingbacks

Leave a Comment


Name (required)

Mail (will not be published) (required)

Website

Comment

Spam Protection by WP-SpamFree