Skip to content

Instantly share code, notes, and snippets.

@DavesCodeMusings
Last active December 31, 2024 20:05
Show Gist options
  • Select an option

  • Save DavesCodeMusings/e00f08365c1c0103d4dd1e89df822641 to your computer and use it in GitHub Desktop.

Select an option

Save DavesCodeMusings/e00f08365c1c0103d4dd1e89df822641 to your computer and use it in GitHub Desktop.
Ventoy VirtualBox Boot

Ventoy Flash Drive as VirtualBox Boot Device

This document shows how to use a Ventoy formatted USB device (instead of an optical disk) to boot an ISO image in VirtualBox. There are other HowTo documents on the internet that explain this procedure (one is mentioned in the References section below), but most use a deprecated VBoxManage sub-command to create the raw device. This document uses the preferred createmedium sub-command. It also uses PowerShell rather than cmd.exe.

The generic form of the command that makes the Ventoy USB drive available to VirtualBox is as follows:

.\VBoxManage createmedium disk --filename=PATH --format=VMDK --variant=RawDisk --property RawDrive=DEVICE_NAME

But, there are some prerequisites...

  1. You must be using a Windows Terminal PowerShell session with admin privileges.
  2. You must be in the correct directory to execute the VBoxManage command.
  3. You need to determine the PATH that will represent your USB flash drive.
  4. You need to know the Windows DEVICE_NAME of your USB flash drive.

Starting Windows Terminal with Admin Privileges

There are many ways to do this. The steps below will get you there quickly.

  1. Use the key combination of Windows Key + X to open the quick link menu.
  2. Select Terminal (Admin) from the list of choices.
  3. Respond with Yes when the User Account Control dialog appears.

Changing to the VirtualBox Program Directory

If you installed VirtualBox to the standard Location, the necessary executables will be under C:\Program Files\Oracle\VirtualBox. You can get there using the PowerShell command: cd $env:programfiles\Oracle\VirtualBox

If you customized the installation location, you'll need to find it and change directory to there before proceeding.

Verify the location by running .\VBoxManage createmedium disk with no command-line parameters. You should see a command usage summary. If you get an error instead of the summary, you're in the wrong directory.

In this example, we'll use C:\Program Files\Oracle\VirtualBox

Deciding the PATH That Will Represent the USB Flash Drive

This is the full path name of Virtual Machine Disk (VMDK) file that represents the flash drive. A simple example would be to use C:\USB_Flash_Drive.vmdk or something similar. You may also want to place it in a subdirectory.

Ultimately, where it goes and what it's called is entirely up to you. Just make the path easy to remember, because you'll need to know it later when setting up a virtual machine that uses it.

In this example, we'll use the path C:\FlashDrive.vmdk

Finding the Device Name of your Flash Drive

Use the Get-PhysicalDisk command to show all disks on the system and visually identify which one is the USB flash drive using its friendly name. Once the DeviceID is known, we can construct the device name by prepending \\.\PhysicalDrive

The command below shows how to isolate the fields of interest.

Get-PhysicalDisk | Select DeviceID,FriendlyName

DeviceID FriendlyName
-------- ------------
1        SanDisk Cruzer Glide
0        NVMe BM9C1 Samsung 1024GB

In this example, we see the SanDisk Cruzer Glide with a Device ID of 1. This is the USB flash drive.

The device name in this case is \\.\PhysicalDrive1

Running the Command

With all the prerequisite parameters gathered, it's time to run the command. The example below shows the command constructed using the prerequisites identified in the steps above. Your command parameters will likely be different.

cd C:\Program Files\Oracle\VirtualBox
.\VBoxManage createmedium disk --filename=C:\FlashDrive.vmdk --format=VMDK --variant=RawDisk --property RawDrive=\\.\PhysicalDrive1

This command should output "Medium created." along with a UUID if all is successful.

Next Steps

After creating the VMDK representing the USB flash drive, you can run VirtualBox Manager and navigate to Tools, Media to see FlashDrive.vmdk. This represents your USB flash drive and can now be attached to any virtual machine as a hard disk.

NOTE: You must run VirtualBox as administrator or you will not be able to access the USB flash drive.

References

https://www.howtogeek.com/187721/how-to-boot-from-a-usb-drive-in-virtualbox/

https://www.virtualbox.org/manual/UserManual.html#adv-storage-config

Command-Line Verification of USB Disk Attachment

Below is some abreviated output from VBoxManage that shows the USB flash drive attached to the SATA controller.

PS C:\Program Files\Oracle\VirtualBox> .\VBoxManage.exe list vms
"Alpine" {e8e50bff-340b-487e-b773-ac4795ae800b}

PS C:\Program Files\Oracle\VirtualBox> .\VBoxManage showvminfo Alpine
Name:                        Alpine
...
Storage Controllers:
#0: 'SATA', Type: IntelAhci, Instance: 0, Ports: 2 (max 30), Bootable
  Port 0, Unit 0: UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    Location: "C:\Users\dave\VirtualBox VMs\Alpine\Alpine.vdi"
  Port 1, Unit 0: UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    Location: "C:\FlashDrive.vmdk"
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment