How to boot from USB drive in VirtualBox - Tutorial

Updated: February 12, 2024

In VirtualBox, when you create a new virtual machine, usually, you have "two" options for starting the guest operating system. You can boot from an ISO image (which would be the equivalent of a CD/DVD drive), or you can boot from a virtual hard disk. But what if you actually have an operating system on a USB drive, and you wanted to use that as your start media?

There are many reasons why you might want to do this. For instance, the operating system may not be available in a simple, friendly format like ISO. Or you might not even have the source ISO, only the final artifact, the partition table and data on an external drive. In today's tutorial, I will show you how you can boot from an existing (bootable) USB drive, and run whatever operating system resides there. We will use Linux as our platform of choice. Follow me.

Raw disk option, and a BIG word of caution

VirtualBox supports the option of booting from "raw" devices. In other words, you can configure an existing, internal or external, storage device as a raw device, and then boot off of it. This could be any operating system, including dual-boot or multi-boot setups. Technically, you can even map your operating system drive (In Windows, that could be the partition where C:\ resides), and launch it. And herein lies the great danger of using raw devices. It is all too easy to misconfigure a disk. One wrong letter, and you can potentially, irretrievably destroy your existing disks and any data stored on them. Therefore, you must be super-careful when trying the raw device functionality. I have a friend who destroyed their laptop this way. For real. You've been warned. Now let us proceed.

Create disk file and map to raw device

The following command will create a raw disk:

sudo VBoxManage createmedium disk --filename=[file.vmdk] --format=VMDK --variant=RawDisk --property RawDrive=[device]

What do we have here?

The two most important elements are:

The location of the file on the disk is not really important. But identifying the right raw device is critical. In Linux, you can check the list of your devices with fdisk. You do need to be aware of the hard disk notation, and the correct size. You can start with a simple fdisk -l to see all of your local devices. This will also show any loopback devices (like say snaps). Then, once you get the basic understanding of your storage topology, you can narrow down your list. For instance:

sudo fdisk -l /dev/nvme*

Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 1TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: C096EC37-7278-4E24-98C6-6A3906628E91

Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 4550655 3500032 1.7G Linux filesystem
/dev/nvme0n1p3 4550656 1953523711 1948973056 929.3G Linux filesystem

And similarly:

sudo fdisk -l /dev/sdb
Disk /dev/sdb: 14.91 GiB, 16008609792 bytes, 31266816 sectors
Disk model: Cruzer Switch
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: gpt
Disk identifier: A674DC54-3E17-4C42-8B62-90E4DCE4AEB3

In this case, fdisk also prints the disk model information, which is quite useful. This way, it becomes much easier to identify and distinguish external, USB-connected thumb drives from internal hard disks, which you most likely want to avoid. Some distributions also offer a GUI way of seeing device information:

Device info

For example, if your thumb drive is mapped to /dev/sdb (in Linux), then, you can run the raw device mapping command as follows:

sudo VBoxManage createmedium disk --filename=./Rdisk.vmdk --format=VMDK --variant=RawDisk --property RawDrive=/dev/sdb

This is where you need to be extra careful, because you need to identify the USB drive correctly. If you map a wrong device, there could be problems and data loss later on.

sudo VBoxManage createmedium disk --filename=./Rdisk.vmdk --format=VMDK --variant=RawDisk --property RawDrive=/dev/sdb
Medium created. UUID: 041a84a8-9d9a-4ae3-a4a1-5393a24f6f7d

Once the command completes, launch VirtualBox.

Add the new disk to the list of available storage devices

The next step is to attach the newly created disk. You can do this through the Hard Disk Selector tool in VirtualBox. Click Tools > Media > Add, locate the VMDK file, and add it. But wait. To be able to do this, you need to have the correct permissions. Indeed, even if you can add the disk, the virtual machine may still not launch, and you may encounter a number of different errors. We will address this shortly. For now, let's assume the permissions are correct.

Tools, Media

Choose disk

Medium selector

Once you've added the disk, open your virtual machine settings, click on Storage. By default, there will most likely be a SATA controller already assigned, with one disk (VDI). Select it, then click on the blue + icon to add a disk, and choose the VMDK file. If there isn't a SATA controller, first click on the green + icon, add a SATA controller, then click on the green + icon, and add a disk. In the example below, my "final" setup includes two assigned disks, a Windows 11 one (VDI format), and my Rdisk.vmdk (VMDK format). I removed the default virtual optical drive, as I will not be booting from an ISO file.

Add new disk

Select and use disk

What I wanted to do is as follows: I had created a Windows 11 installation media with Rufus, a superb little tool, which also lets you customize the installation experience. Namely, it can remove some of the nonsense stuff you normally see during the Windows setup. But Rufus writes its media plus configuration exclusively to external devices. It does not create ISO files.

Therefore, to test whether Rufus did its job, I needed to boot the USB device somewhere, and see what gives. I could do that on a physical box, but that's not always an easy option, especially if you need to format the disk and install a system there. Instead, a virtual machine is a perfect substitute for testing, but then one needs to boot from a USB drive rather a virtual CD (ISO file).

Thus, in the example above, my virtual machine has its (empty) Windows disk, plus the attached raw device, which we will only use during the installation. Technically, you could have multiple bootable disks attached to a virtual machine, and then you have to make sure they boot in the correct order in the machine's BIOS.

Possible errors

When you create a new raw disk, its permissions will be, in Linux, 0600 and ownership root:root. This means that you won't be able to access this file, let alone use it in VirtualBox. You need to change the permissions either by adding rwx for other users, or by changing the ownership (better). Something like:

sudo chown roger:roger file.vdmk

Or perhaps:

sudo chown roger:vboxusers file.vdmk

But this ain't enough. You will most likely hit a VERR_ACCESS_DENIED error:

Access denied error

Permission problem accessing the file for the medium 'path-to-your-vmdk-file' (VERR_ACCESS_DENIED).

Result Code: VBOX_E_FILE_ERROR (0X80BB0004)
Component: MediumWrap
Interface: IMedium {ad47ad09-787b-44ab-b343-a082a3f2dfb1}
Callee: IVirtualBox {7682d5eb-f00e-44f1-8ca2-99d08b1cd607}

The reason is, even if your user is correctly set up, and you are a member of the vboxusers group, you still need to separately allow your user to access raw devices ( disk group). This can be done by:

sudo usermod -a -G disk $USER

After this, you can log out, and log back in for the change to take effect. There are also ways to do this without logging out, but this is the simplest way for most people. An alternative to this entire problem, both in Windows and Linux, is to start VirtualBox with administrative privileges. But that's not a smart idea in general, because everything you do, including all your errors, will reflect the elevated level of permissions.

Boot and test

Now that we've sorted all of the different issues, let's see that everything works. Indeed, I could see the customized boot screen, already an indication that Rufus was doing its job. And in the setup phase, I could see both hard disks, the small one that is actually the raw device (USB drive) and the larger, 100GB empty virtual disk, which is actually the installation target device.

Windows boot test

Disk selection step

Two drives: drive 0 is the 16GB USB drive with two partitions, we don't want that as the installation target (hence the possible risk of using raw devices in VirtualBox); and drive 1 is the 100GB empty virtual disk, with no partition table. Still, you need to be extremely careful, when there's more than one option available.


Now that you've mastered this tutorial, you can start playing in earnest. You can test multi-disk setups, try booting operating systems that already exist on various external (and possibly internal) devices. You can also create multi-boot USB devices, and check whether they work correctly in VirtualBox before you try them in earnest on physical hardware. In all of these cases, you need to exercise caution, as the raw disk functionality breaks the isolation boundary between the physical host and the virtual guest.

Hopefully, this was useful. The very first step to using raw devices in VirtualBox is to correctly identify the right storage medium. If you don't know how to do that, or you're unsure, just stop, right now. Then, once this step is done, you will need to create a vmdk file, and map it to the right device. Next, there might be some possible permission problems, and finally, you can attach the disk, and boot your virtual machine from a USB drive. That would be all for today, and if you have any other questions regarding VirtualBox, drop me a line or two, and I might create another fresh, raw guide here and there. See ya.