Yesterday I was trying to create multiboot USB drive with Ventoy in my Linux system. After successfully created the bootable drive, I added different ISOs to the bootable drive. But the problem is I had to reboot my system every time after adding a new ISO to check if the USB drive is really working. Since I had no additional system, It seemed a little bit time consuming task to me. I thought it would be better If I could boot from USB drive in Virtualbox in my Linux system. As you might know, Oracle Virtualbox doesn't offer any direct way to boot from USB. Luckily, I have found a simple workaround to allow Virtualbox to boot from an USB flash drive.
Boot From USB Drive In Virtualbox In Linux
To allow Virtualbox boot from USB drives, you need to create a .vmdk file and point it to your USB drive for booting to it. For those wondering, a vmdk file is nothing but a virtual disk file which contains all the information of a virtual machine.
First, you need to find your USB drive name. Refer the following guide to learn different ways to find disk drive details in Linux.
I am going to use "fdisk" command to find my USB drive details:
$ sudo fdisk -l
[...] Disk /dev/sdc: 14.54 GiB, 15597568000 bytes, 30464000 sectors Disk model: Cruzer Blade Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4d924612
As you can see, my USB drive name is /dev/sdc.
Now, open your Terminal and run any one of the following commands to create a vmdk file:
$ sudo vboxmanage internalcommands createrawvmdk -filename ~/usb.vmdk -rawdisk /dev/sdc
In some Linux distros, the vboxmanage command is case-sensitive. In that case, use the following command to create vmdk file:
$ sudo VBoxManage internalcommands createrawvmdk -filename ~/usb.vmdk -rawdisk /dev/sdc
The above command will create a new vmdk file named "usb.vmdk" in your $HOME directory. Upon successful vmdk file creation, you will see an output like below:
RAW host disk access VMDK file /home/sk/usb.vmdk created successfully.
Set proper permission to the newly created vmdk file:
$ sudo chown $USER:$USER ~/usb.vmdk
Next, add your user to "vboxusers" and "disk" groups using the following commands:
$ sudo usermod -a -G vboxusers sk
$ sudo usermod -a -G disk sk
Replace "sk" with your own user name.
Please be mindful that adding a user to "disk" group is dangerous and security risk. Now remove the USB drive and reboot your system to take effect the changes. If you don't remove your USB, the name of your drive letter may change at next boot. So it is important to remove the USB first and reboot the system.
Now open Oracle Virtualbox application and create a new virtual machine:
Enter the name of the VM, OS type and version and click Next to continue:
Enter RAM size:
This is important step. Choose "Use an existing virtual hard disk file" option and click the browse button (UP arrow button):
Click "Add" button to choose the newly created vmdk file:
Choose the newly created vmdk file from your local drive:
After adding the vmdk file, click Choose button to confirm:
You will now see the vmdk file is selected as the virtual hard disk for the new virtual mahine. Click Next to continue:
All done! Plug your bootable USB drive and start the virtual machine:
Now you can be able to boot from USB in Oracle Virtualbox. Here I am booting the USB bootable drive created with Ventoy script in Virtualbox:
Create An ISO From A Bootable USB Drive In Linux
This is another way to boot USB drive in Virtualbox. In this method, we don't need to create vmdk file. Just create an ISO image from the bootable USB using "GNOME disk utility" or "dd" command as described in the following link:
After creating the ISO, open Virtualbox application and go to the Settings of the any VM and add (mount) this newly created .iso file as an optical drive under "Storage Controller: IDE" option.
Now start the VM and it will boot from the ISO image.
Please note that this method will not work with all USB images, especially with multi-partitioned USB drives.