Wednesday, January 16, 2013

Booting USB from Virtual Box

VirtualBox can be set to accept booting from USB. This is purposed to test the recovery USB stick. Instead of booting from the real machine, you can boot the USB recovery stick from the virtual machine so it is easier to fix the USB. This is very useful for making a booting USB like in my earlier post, "Multiboot USB with 15 instances".

There are 2 methods to boot the USB in virtualbox. First, we can use PloP as an ISO image to attach to the CD ROM drive of any OS in the virtualbox. Then we add our real USB in the USB setting of Virtualbox. (Don't check Enable USB2 box because PloP doesn't support it.) When used, this USB will be seen by the Virtualbox OS only. This method can be used with any bootable USB. The problem is that it is very slow to boot an OS in the USB because PloP allows connecting with USB1 only.

The second method is creating virtual USB device from the real USB with this command:

VBoxManage internalcommands createrawvmdk -filename "%USERPROFILE%"\.VirtualBox\usb.vmdk -rawdisk \\.\PhysicalDrive#

where # is the USB disk number (looked in Windows Disk Management.). The virtual USB is usb.vmdk file. This can be added in Virtualbox as an existing hard drive.

Don't add our real USB in the Virtualbox USB setting as the USB needs to be seen from the host windows.

Note that this virtual USB will use with the USB that you created with only. The order of plugging the USB is also important. This has to be the order to make the USB the right PhysicalDrive number. It means if you fail to do this, i.e. changing from 8G to 4G or plugging the USB the wrong order, the system won't boot. Therefore, it is a good idea to name this Virtualbox OS to be something meaningful like "Virtual USB 8G Disk2". The advantage of this method is that the USB speed is much faster than the first one. This is the method of my choice.

Last but not least, you need to set Virtualbox base memory and video memory to some extent; otherwise, some OS won't boot up. I am using 2048M for the base memory, and 32M for the video memory.