Sometimes booting a virtual machine from USB is necessary to install an Operating System as a guest on VirtualBox if you do not have ISO file. Unfortunately, it is not supported by most of the desktop virtualization software as a built-in feature yet. The below guide explains the steps of how I managed to boot a VirtualBox virtual machine from USB on macOS and Windows host computers. This method will be useful if you have a bootable Live Linux on USB and you want to try that on VirtualBox.
Oracle VirtualBox is one of the best and free desktop virtualization software which allows running multiple Operating Systems on the single computer. Nowadays, most of the PC utilities and Operating Systems have the feature to create a portable and bootable USB disk which can be used in varies ways. VirtualBox has a hidden feature to enable this USB boot support.
Basically, we need to create a VMDK file based on the attached USB disk and mount the VMDK as virtual machine’s first bootable disk and boot it.
VirtualBox Boot from USB in Mac
1) Attach the bootable USB disk and find out the disk path. Because we need to use the disk path in the next command.
Open the Terminal ( Go – Utilities- Terminal) and type mount
It shows the USB disk path, note it down since we need to use it later. In this example, /dev/disk2s2 is mine.
2) Now go to disk utility (Go – Utilities- Disk Utility) and unmount the partition of the USB disk. The next command will not work without unmounting the USB disk. Right-click on USB partition and select ‘Unmount USB name’
3) Type following command in terminal to create VMDK file of the USB disk.
sudo VBoxManage internalcommands createrawvmdk -filename /Users/Dinesh/Documents/myusbdrive.vmdk -rawdisk /dev/disk2s2
/Users/Dinesh/Documents/myusbdrive.vmdk – is the location of vmdk file
/dev/disk2s2 – the USB drive path which we got from mount command earlier.
Provide the superuser password to complete the task.
4) Now we have successfully created the VMDK file. But, if you attach the file to VirtualBox and try to boot, it will throw some access denied errors. We need to modify a couple of permissions.
5) Since we will be using VirtualBox as a normal user but the VMDK file is created with su (superuser) command, we need to give read and write access to all users for particular VMDK file.
Type the following command to change the permission of the VMDK file.
sudo chmod 777 /Users/Dinesh/Documents/myusbdrive.vmdk
6) We need to change the permission of USB disk too.
sudo chmod 777 /dev/disk2s2
7) Now the VMDK file is ready to attach and boot a VirtualBox virtual machine on macOS host.
In virtual machine settings, go to storage and select the controller, then add a hard disk. Select choose existing and browse the VMDK file we created in earlier steps.
Change the hard disk SATA port number to make sure it has listed as the first hard disk for the virtual machine, so it will boot from it (like a CD/DVD drive). In this way, the virtual machine will boot from USB on VirtualBox with Mac OS X Mavericks host.
Steps on Windows OS Host
The process is almost identical which we did earlier for macOS to boot a VM from USB in Windows 10 or 8.1/7. Also, it is similar to our earlier guide on how to access physical disk and partition from the VirtualBox virtual machine.
I’m demonstrating these steps on a Windows OS computer with the bootable DOS USB flash drive. I’m going to boot an existing Linux virtual machine from this USB disk.
1) Make sure your USB is bootable and it is booting on a physical computer. Because, if the USB is not bootable, there is no point in blaming these steps or VirtualBox.
2) Find out the correct disk number of attached USB drive from Windows Disk Management.
Here is mine. Disk 4 is the USB I need to boot from VirtualBox.
3) Let’s create a raw VMDK file for the USB disk.
Open the command prompt as administrator and go to the installation directory of VirtualBox (usually it will be located under Program Files folder under C partition).
Important Note – You must open the command prompt by selecting ‘Run as administrator’ option.
Type the following command.
VBoxManage internalcommands createrawvmdk -filename C:\Users\Dinesh\Desktop\usb1.vmdk -rawdisk \\.\PhysicalDrive4
You must enter the valid path to save output VMDK file and correct disk number of the USB drive which we found from disk management.
A successful message should appear as below if the command works fine.
4) Now open the VirtualBox and go to the settings of the virtual machine you like to boot from USB disk.
We need to attach this VMDK file to the VM as the first bootable hard disk to be able to boot. Since my existing virtual machine is having SATA controller, I clicked on Add Hard disk, selected Choose existing disk and attached the VMDK file created earlier.
Once the disk is added without any error messages, you may need to change the SATA ports or IDE settings to make the added hard disk as the first boot disk, otherwise, it will be booting from earlier OS hard disk only.
5) Now you can switch on the virtual machine, it should boot from attached USB disk.
Here is my Fedora Linux VM booting from DOS USB flash drive.
The involved steps are very easy and straightforward, the only important part is you must open the command prompt as administrator and enter the commands properly with the disk numbers.