Written By Bharat Balegere. On Jul 25. In Agni Karya,usb
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.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 pathtousb.vmdk -rawdisk \.PhysicalDrive1 -register
Example
VBoxManage internalcommands createrawvmdk -filename c:UsersAgni.VirtualBoxVDIusb.vmdk -rawdisk \.PhysicalDrive1 -register
You have to replace pathtousb.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
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.
- Start VirtualBox.
- Create a new Machine or Select an Existing Machine.
- Settings-Hard Disk-Add-Select usb.vmdk
- Make sure that usb.vmdk is your Primary Master.



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

Boot Order
- 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.
















Thanks. You resolve my problem. ^^
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!
Very nice description ,i am going to try .
Gracias, has resuelto mi problema. A seguir experimentando
Excelent!!! your guide is EXCELENT!
Thanks Uridium.
I am glad that you liked my article.
Thnaks, that helps a lot… maybe not to fix my issue, but a damn nice way to troubleshoot!
;o)
Thanks Ionreflex.
I am glad that you liked my article.
Thnaks, but this is only for windows? In ubuntu how to use USB Driver boot as VirtualBox ???
I guess createrawvmdk command can be launched on Ubuntu too. You need to adapt this tutorial.
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 )
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).
I have this problem as well.
I am running a live usb version of ubuntu (9.10) from my usb, through virtualbox, using these instructions. I have persistence set up on the usb and it works fine when used normally.
But when loaded on the virtualbox none of the changes I make stay.
I have tried Yoni’s tip of changing the drive to Writethrough in stead of Normal in VirtualBox.xml, but still have the same problem.
Has anyone got this working, with changes to files on the live usb stick persisting?
Thanks.
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.
Thanks but your command generates this error while creating vmdk
Syntax error: Invalid parameter ‘and’
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?
thanks a lot, a very helpful article
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
Great!
Very clear explanations and works perfectly.
Thaks a lot.
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.
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!
Thanks.
I will update my post
Thank you Bharat for taking the time to post these excellent instructions :-))
Thanks for the tips. Your article actually reminded me that USB drives are reported as “PhysicalDriveN” as well.
Аллилуйя!!! :) Используя данный способ, прекрасно загружаюсь с USB-HDD. Большое спасибо… Thank you very much :D
Thanks a lot! Now I can boot from my USB-HDD!
Thanks Mate, Helped…
Thank you for a great tutorial, it was very well written. I feel your information is outdated however, because there is a much easier and better way to get a USB drive to boot in a Virtual Machine.
1. Go to http://www.plop.at/en/bootmanagerdl.html , and download the most recent .zip .
2. Extract it, and navigate to /intsall/plpbtin.iso .
3. Add the ISO in the VM, and install PLoP to the virtual hard disk (option 1)
4. Now, when you turn on the VM, it gives you an option to boot USB, Floppy, Hard Drive, and CD.
This method might be easier, plus users will not need to create a new virtual image of their USB after every single change to it.
Thank you for your time, I hope this information will be put to good use.
Vania S.
yeah!!!!!!!!!
Also, this was earlier noted, both cmd and virtualbox must be run in administrator mode if you’re in windows 7.
thanks! I’v been looking for a good way to do this and tried at least 10 ways… and am fed up with wasting my time frankly..lol but you made a very clean cut and simple tutorial ^.^ i never thought of designating one of my jump drives as a primary disk and THEN using virtualbox to find it… I just used the cheap way of confusing virtualbox into thinking my jump drive was a cd-rom for booting and then using the ISO
file to temp boot…
Great article! Helps a lot!
One additional observation I had:
If you choose to use an existing VM to boot the USB drive… first disable any existing USB filters for the drive you’re attempting to boot from.
hi all,
i am using Virtualbox 3.1.6 with a Windows7 host and am getting this error when i run the command:
Syntax error: Invalid parameter ‘\\.\PhysicalDrive2′
can anyone help?
i have posted more detailed information about it here:
http://forum.virtualbox.org/viewtopic.php?f=6&t=30788
thanks! :D
It happened to me. I forgot to write “-rawdisk”. That’ll do.
Hello;
Now I’m using Virtual Box and the windowsXP.vdi file is installed/stored in my disk, but I won’t put/run that from a USB external disk , is possible with this information ,of this article? “Boot your USB Drive in VirtualBox”
José Gonçalves
I can’t add to VirtualBox the “usb.vmdk” as harddrive, when it point to a external harddrive formated as ext4. Just got an error trying to do that. That way I can’t boot Ubuntu as guest from an external hard drive, on a Windows host. When Sun/Oracle say that will not implement USB on VirtualBox’s bios, they justify saying that there is no benefit on this feature, they can only be kidding from our intellect.
And just to confirm what was told here before: on windows 7 and vista you have to run cmd as administrator to have rights to access the “\\.\PhysicalDrive1″ and create the vmdk file.
Thanks anyway for all the info, great post!
My most heart-felt kudos for this guide. You have saved me 2 days of frustration over this. So glad I found your blog this morning. For once staying up late pays off!
Read this : http://blogs.sun.com/shashank/entry/how_to_boot_from_usb
Mr. Shekhar from Sun has told how to boot from USB.
Should have searched for this before writing this much long procedure
Well,I tried this method.But it does not seem work.Where do you get the option to specify the floppy drive letter?
thank you so much, that’s judt what i was searching
It works. Thanks for posting this information.
That was perfect! I’m using Linux, it it seems to work only as root. That’s because I suppose that it connects to device /dev/sdx. And only the root can manage that directory. I’ve lunched the command as a root (sudo Vbox…) but still when I’m trying to load the file in VBox as a normal user i get an error – something like access denied. If i run Vbox as root, everything works as a charm.
I’m not to confident to run Vbox as root. If someone finds a way to make this work without being a root use, it would be great! Thanks a lot!
Thank you so much – the pictures help a lot too!