How can I boot from a USB stick with VirtualBox?
In most cases, VirtualBox will boot you with an ISO file and then install the operating system of your choice. But how can I use a USB installation media and boot from it?
Instruction
The function to boot from USB sticks is not directly included in the user interface of VirtualBox and is only accessible with a little trick. First we plug the USB stick into the computer. Then we open the disk management.
The USB stick should now appear in the data medium management and also the number of the data medium. In my case it is number 1, which we will remember.
Then we open the command prompt with administrator rights.
Here we now change to the VirtualBox directory:
cd %programfiles%\Oracle\VirtualBox
Then we enter the following command:
VBoxManage internalcommands createrawvmdk -filename C:\temp\usb.vmdk -rawdisk \.\PhysicalDrive#
This command creates a virtual VMDK file for us, which is a shortcut to the USB drive. Instead of the hash, enter the number of the disk from Disk Management. You can adjust the path.
Our virtual data medium should then be stored in the target directory.
Now we start VirtualBox with administrator rights.
We create a new virtual machine.
In the settings page for the hard disk, however, we do not create a new one, but use the USB disk we created.
We can then start the virtual machine and it should now boot from the USB stick.
Install operating system
To install an operating system, we first need to add a hard drive. We can add this in the settings under Mass storage. It is important that the new data carrier is added to the list after the USB data carrier, otherwise the system will no longer boot from the USB stick.
With the new hard disk, we can now boot from the USB stick and also install the operating system on our newly created data medium.
Update for VirtualBox 7
In VirtualBox 7, the currently does not seem to work and is broken. The following error message appears:
VBoxManage.exe: error: VMDK: Image path: 'C:\temp\usb.vmdk'. Getting config interface failed VBoxManage.exe: error: Error code VERR_INVALID_PARAMETER at F:\tinderbox\win-rel\src\VBox\Storage\VMDK.cpp(4481) in function int __cdecl vmdkRawDescParseConfig(struct VMDKIMAGE *,char **,unsigned int *,unsigned int *,void **,unsigned __int64 *,bool *,char **) VBoxManage.exe: error: VMDK: could get raw descriptor for 'C:\temp\usb.vmdk'. VBoxManage.exe: error: Error code VERR_INVALID_PARAMETER at F:\tinderbox\win-rel\src\VBox\Storage\VMDK.cpp(5296) in function int __cdecl vmdkCreateImage(struct VMDKIMAGE *,unsigned __int64,unsigned int,const char *,const struct VDGEOMETRY *,const struct VDGEOMETRY *,const union RTUUID *,struct VDINTERFACEPROGRESS *,unsigned int,unsigned int) VBoxManage.exe: error: Cannot create the raw disk VMDK: VERR_INVALID_PARAMETER VBoxManage.exe: error: The raw disk vmdk file was not created
The only remedy at present is to download a previous version.