Tuesday 3 December 2013

Boot from a USB drive using VirtualBox with full rd/wr access

It has been possible to boot directly from a USB drive attached to a Virtual Machine for several years now.

Plop!

One approach is to boot from a Plop ISO and then through Plop you can boot from the USB drive.

However, Plop employs a read-only USB driver stack and so only read-accesses to the USB drive are possible (when in real mode using BIOS calls) when you boot under a VM using Plop. For instance, if you boot to DOS using Plop you will find that you cannot edit/create any files on the USB drive.

Make a .vmdk file

Alternatively, you could make a USB drive vmdk file for VirtualBox to use, using a VBox command line or the MakeUSBVmdk.cmd script to make the .vmdk file for the USB drive. However, this still only allows read-only access to the USB filesystem under VirtualBox (until you boot to an OS which has it's own USB drivers).

VMUB

Download VMUB here (use the small link at the top of the page)



DavidB has solved this problem with his Virtual Machine USB Boot utility (see here for the original blog post which started the development of this utility). This allows you to boot directly from a USB drive using either QEMU or VirtualBox with full read/write access to the USB drive. It works by dismounting the USB drive from Windows, running the VM, and then re-mounting the USB drive when you quit the VM.

This is important for Easy2Boot users because Easy2Boot writes to sectors and files on the E2B USB drive using grub4dos (which uses the BIOS), so unless you have full read/write access, booting from an E2B USB drive via VirtualBox often leads to problems. Most of my YouTube videos and all my preliminary testing of USB booting is done using VBox and DavidB's utility.

Users of grub4dos USB drives may have noticed that the grub4dos 'default' command does not work under VBox when using just a .vmdk file or Plop! This is because the default command actually writes values to a file on the USB drive (usually called default). Using DavidB's VMUB utility however, the grub4dos default command will work just fine!

I have made a YouTube video here: http://www.youtube.com/watch?v=mvYkujvUXhc showing how to set up a VM for the VMUB utility. There is also a tutorial here.


Tip: Hold down the CTRL key and then click Start and VMUB will not dismount the USB drive before running VBox. This is useful if you are designing E2B menus (for instance) - you can still edit any file on the USB drive whilst VBox is running, then simply reboot (e.g. press F9 in E2B) and it will reboot with the new changes. There is no need to stop the VM and re-run it every time you need to change a file or two.

One thing to bear in mind is that the USB drive will be treated by any OS as a hard drive and not a 'Removable drive'. That means that you cannot use VBox+DavidB's utility to run a Windows 7/8 install from an E2B USB Flash drive as it won't pick up the AutoUnattend.xml file.

Also any OS that tries to look for the boot files only on a USB drive on a USB controller will fail to boot because the USB drive is attached to a 'virtual hard disk' in the VM. Luckily, most OS's scan all devices on boot-up, but a few linux distros specifically look for the source boot files on a USB port. In these case, the VM boot will fail and you will need to try a real system. Some linux distros specifically look for a real CD/DVD drive for the boot files - in this case, booting from an E2B USB drive, even on a real system will fail (the same distro will fail on ANY kind of USB drive, no matter how it was prepared!).

You also need to realise that access to the USB drive is not possible while the VM is running because the USB drive has been detached from Windows at that point (unless you hold down the CTRL key first).

Apart from this, I have found 99% of bootable ISOs, etc. boot just as well from E2B under VMUB as they do when booting on real hardware. If you do experience any problems with a particular payload, then you should test using a real system (try both USB 2.0 and 3.0 ports).

No comments:

Post a Comment