How to Boot a USB Flash Drive in VirtualBox. This process will allow you to run your Portable Linux from the Flash Drive or external hard drive while still running from within a Windows, Linux, or Mac OS X Host. By default VirtualBox does not support USB Booting. However, you can make the VM Virtual Machine USB Boot by creating and mapping a virtual machine (.vmdk file) to the USB Drive. Essentially creating a VirtualBox Bootable USB.
VirtualBox Website: Project Homepage
Make VirtualBox Boot from USB Flash Drive (Windows)
- Download and run VirtualBox (Installing to the default path).
- You’ll need to use the command line to perform steps 3-6,
To open a command prompt;
(1) From the Windows ‘⌕ Type here to search’ box, type cmd.exe
(2) Then click Run as administrator
- At the command prompt, type diskmgmt.msc and press Enter to open the Windows Disk Management Tool. Then, identify your USB Disk #
- Now, back at the command line, type
- Replacing # with your USB Disk number from step 3, type
VBoxManage internalcommands createrawvmdk -filename "%USERPROFILE%"\.VirtualBox\usb.vmdk -rawdisk \\.\PhysicalDrive#
- To start VirtualBox as Admin, type start virtualbox
- Click New, and then proceed to Create a New Virtual Machine.
- When prompted for a Virtual Hard Disk, tick use existing hard disk. Then, browse to your %USERPROFILE%\.VirtualBox folder, and select the usb.vmdk file.
- Once done creating your New Virtual Machine, click Start.
If all goes well, VirtualBox should now be emulating, booting, and running your USB device from within Windows.
Getting Persistence to work in VirtualBox (Windows)
At first the USB flash drive might not work exactly like it does when booted natively. Things like Ubuntu’s casper persistent feature won’t work. Some distributions might not even boot, or will boot with errors. This is because the volumes on the device are mounted by Windows, preventing VirtualBox from gaining full access. In order to fix these issues, you can use a tool called LockDismount. Then simply run the tool (using the following steps), prior to starting the Virtual Machine that is tied to your USB.
- Download the LockDismount tool
- Launch the tool right before starting your VirtualBox VM
- Select your USB from the drop-list, then Press Lock it!
(optionally you can check Force Dismount)
Now your flash drive should be able to boot in VirtualBox exactly as it does when booted natively on a physical machine. ;)
Make a VirtualBox Bootable USB Flash Drive (Linux)
The following process to boot a USB flash drive in VirtualBox was performed from a running Ubuntu Operating environment. This method should also work for Debian and other Ubuntu Linux based Operating systems.
- Open a Terminal Ctrl+Alt+T, and then type the following and press Enter;
sudo apt install virtualbox
- Next, type
sudo fdisk -l
(note which device is your USB drive I.E. /dev/sdx)
- Replacing x with your actual device letter found from step 2, type
sudo vboxmanage internalcommands createrawvmdk -filename ~/usb.vmdk -rawdisk /dev/sdx
- Type sudo virtualbox to start the program, and proceed create a New Virtual Machine.
- When prompted for a Virtual Hard Disk, tick use existing hard disk, then browse to your Home directory and select usb.vmdk.
- Once you’ve finished creating your New Virtual Machine, click Start.
If all went smoothly, you should now be able to boot a USB flash drive from VirtualBox on the Linux Host.
Boot a USB Flash Drive in VirtualBox (Mac OS X)
- Download and install VirtualBox for OS X Hosts via the .dmg file.
- Open a Terminal, type the following and then press Enter
(make note of which disk is your USB drive I.E. /dev/disk#)
- Replacing # with the disk number of your USB drive, type
diskutil unmountDisk /dev/disk#
- Again, replacing # with your actual disk number, type
vboxmanage internalcommands createrawvmdk -filename ~/usb.vmdk -rawdisk /dev/disk#
- Once more, replacing # with the disk number, type
diskutil unmountDisk /dev/disk#
- Finally, to start the program with root access, type
- Next, Proceed to create a New Virtual Machine.
When prompted for a Virtual Hard Disk, tick use existing hard disk.
Then, browse to your Home directory and select usb.vmdk.
- Once finished creating your New Virtual Machine, click Start.
You should now be able to boot a USB flash drive in VirtualBox on the Mac OS X host, while retaining the ability to boot from the drive natively as well.
Note: When first attempting to boot a USB Flash Drive in VirtualBox from within Windows, you may receive an Error similar to this:
Failed to get device handle and/or partition ID for 0000000001e92d20 (hPartitionDevice=0000000000000cd5, Last=0xc0000002/1) (VERR_NEM_VM_CREATE_FAILED).
In which case, you need to set hypervisor launch type to off. To do this;
- Open a command prompt as Administrator. I.E; (Win Key+X) and then press A
- Type the following command string into the terminal, then press Enter
bcdedit /set hypervisorlaunchtype off
- Reboot your computer.
- Try to boot your USB flash drive from VirtualBox again.
This concludes three methods that can be used to Boot a USB Flash Drive in VirtualBox. If you found this useful, you might also be interested in Running VirtualBox from USB.