[TUTORIAL] Virtual Pendrive on VM

PanWaclaw

Active Member
Jan 30, 2017
14
19
43
38
I searched a lot on the pages but found nothing interesting so decided to write a short tutorial.

Virtual Flash Drive is very helpful, many systems require it instead of an iso image, and it will also come in handy for quick tests or fast move files beetwen VM.

1. We create an image of our flash drive
Bash:
dd bs=1G count=8 if=/dev/zero of=/tmp/usb0.img
Tip1 - We can use permanent storage instead of /tmp/
Tip2 - We can change the size bs,count - more info in the dd manual

2. Add a device for our flash drive [VM --> Monitor]
Code:
drive_add 0 file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none
Tip - can use another format or cache

3. Install our flash drive in the slot [VM --> Monitor]
Code:
device_add usb-storage,id=drive-usb0,drive=drive-usb0,removable=on
Tip - can change 'removable' walue for example Windows see on=PENDRIVE off=USB HDD

4. (Optional) Remove your pendrive if it is no longer needed
Code:
device_del drive-usb0

Extra Tip :) Can boot from usb, can add more pendrive - repeat all steps and replace drive-usb0 with for example drive-usb[X]
Extra Tip :D To add permanently to our machine:
Bash:
qm set 1003 -args "-drive file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none -device usb-storage,id=drive-usb0,drive=drive-usb0,removable=on"
 
Last edited:
I searched a lot on the pages but found nothing interesting so decided to write a short tutorial.

Virtual Flash Drive is very helpful, many systems require it instead of an iso image, and it will also come in handy for quick tests or fast move files beetwen VM.

1. We create an image of our flash drive
Bash:
dd bs=1G count=8 if=/dev/zero of=/tmp/usb0.img
Tip1 - We can use permanent storage instead of /tmp/
Tip2 - We can change the size bs,count - more info in the dd manual

2. Add a device for our flash drive [VM --> Monitor]
Code:
drive_add 0 file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none
Tip - can use another format or cache

3. Install our flash drive in the slot [VM --> Monitor]
Code:
device_add usb-storage,id=drive-usb0,drive=drive-usb0,removable=on
Tip - can change 'removable' walue for example Windows see on=PENDRIVE off=USB HDD

4. (Optional) Remove your pendrive if it is no longer needed
Code:
device_del drive-usb0

Extra Tip :) Can boot from usb, can add more pendrive - repeat all steps and replace drive-usb0 with for example drive-usb[X]
Extra Tip :D To add permanently to our machine:
Bash:
qm set 1003 -args "-drive file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none -device usb-storage,id=drive-usb0,drive=drive-usb0,removable=on"
Thanks for the amazing tutorial, it works, is there a way I can add a special name to the pendrive like OEMDRV or something like that. Also how to remove the drive from the VM? Just delete it?
 
drive_add and device_add do not seem to work any more anyone know what works in version 7.4 ?
 
Extra Tip :) Can boot from usb,
can add more pendrive - repeat all steps and replace drive-usb0 with for example drive-usb[X]

Extra Tip :D To add permanently to our machine:
Bash:
qm set 1003 -args "-drive file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none -device usb-storage,id=drive-usb0,drive=drive-usb0,removable=on"
So I'm trying to do this as a boot.
Specifically I'm trying to load ChromeOS, as a recovery for my machine, not as FLEX, & the only way to do so is to format a Flash Drive.

This helped immensely for Windows to recognize the IMG as a drive & do the recovery install to that drive. After it is created the drive is not accessible in windows, but it is visible in Disk Management as a drive with 11 partitions. This is the same as when I made the drive on a physical USB so that seems to have worked fine.

The problem is that after the drive is added permanently it does not show in Proxmox's [Hardware] tab for the machine. So I am unable to add it to the Boot Menu on the [Options] tab.

You mention the ability to "Boot from USB" but there is no information on how to do that. The normal way to do that within Proxmox doesn't work, & if I attach the drive to a container.
Now, in my testing it was clear that without doing the {Monitor} steps, which require the VM to be running, & just doing the "To add permanently to our machine" step the drive will not be visible in the system. So using this as a boot drive for a new machine will require it to have an OS installed for it to be added & work initially.

Can you explain how you accomplish booting from the drive?
 
The problem is that after the drive is added permanently it does not show in Proxmox's [Hardware] tab for the machine. So I am unable to add it to the Boot Menu on the [Options] tab.
Check the VM config from CLI by cat /etc/pve/qemu-server/VMID.conf (replacing VMID with the actual ID number of VM)
There you'll see a line: boot: order= ....... change accordingly in editor of choice. Semi-colon goes in between entries. (Maybe backup the file before messing!)
 
Last edited:
When I do that it doesn't show any sign of trying to boot from the "USB", it shows in the Boot Order [Options] menu but if I try to edit the boot order it says
Code:
invalid bootorder: device 'usb2' does not exist' (500)
.

The Description in the Boot Order menu is blank. This does not seem to work
 
How do you know this? There may be a problem with your USB image / bootloader etc.
Because it doesn't show anything in the boot log, & if I remove everything else from the boot options in the .conf it boots to the Windows I created the USB drive on, even when the Netboot is 1st, it just skips that when only USB2 is set
 
show me your VMID.conf file - correctly formatted - with the boot order you wish USB2; Windows Disk etc.
 
Here's what it looks like where it doesn't boot to the "USB" drive

Code:
agent: 1
args: -drive file=/spinning/usbdrive/usb2.img,if=none,id=drive-usb2,format=raw,cache=none -device usb-storage,id=drive-usb2,drive=drive-usb2,removable=on
balloon: 1024
bios: ovmf
boot: order=usb2;virtio0;net0;ide2
cores: 4
cpu: host
efidisk0: spinning:787/vm-787-disk-0.qcow2,efitype=4m,pre-enrolled-keys=1,size=528K
ide0: spinning:iso/virtio-win-0.1.240.iso,media=cdrom,size=612812K
ide2: spinning:iso/Win11_23H2_English_x64v2.iso,media=cdrom,size=6653034K
machine: pc-q35-7.1
memory: 4096
meta: creation-qemu=7.1.0,ctime=1674169585
name: Win11-PE-Setup
net0: virtio=0E:2B:82:D2:DA:9B,bridge=vmbr0,firewall=1
numa: 0
ostype: win11
scsihw: virtio-scsi-single
smbios1: uuid=c4b28085-0a5b-4b0b-96c6-3a5700f657fd
sockets: 1
tpmstate0: spinning:787/vm-787-disk-1.raw,size=4M,version=v2.0
usb0: host=1bcf:280b
virtio0: spinning:787/vm-787-disk-2.qcow2,iothread=1,size=100G
vmgenid: ab2cf625-0151-4733-a6a1-37c092385911

Here's another where it is set to ONLY boot from the "USB" but will boot from `virtio0` even when it's not on the list.

Code:
agent: 1
args: -drive file=/spinning/usbdrive/usb2.img,if=none,id=drive-usb2,format=raw,cache=none -device usb-storage,id=drive-usb2,drive=drive-usb2,removable=on
balloon: 1024
bios: ovmf
boot: order=usb2
cores: 4
cpu: host
efidisk0: spinning:787/vm-787-disk-0.qcow2,efitype=4m,pre-enrolled-keys=1,size=528K
ide0: spinning:iso/virtio-win-0.1.240.iso,media=cdrom,size=612812K
ide2: spinning:iso/Win11_23H2_English_x64v2.iso,media=cdrom,size=6653034K
machine: pc-q35-7.1
memory: 4096
meta: creation-qemu=7.1.0,ctime=1674169585
name: Win11-PE-Setup
net0: virtio=0E:2B:82:D2:DA:9B,bridge=vmbr0,firewall=1
numa: 0
ostype: win11
scsihw: virtio-scsi-single
smbios1: uuid=c4b28085-0a5b-4b0b-96c6-3a5700f657fd
sockets: 1
tpmstate0: spinning:787/vm-787-disk-1.raw,size=4M,version=v2.0
usb0: host=1bcf:280b
virtio0: spinning:787/vm-787-disk-2.qcow2,iothread=1,size=100G
vmgenid: ab2cf625-0151-4733-a6a1-37c092385911

When either one of these is set editing the `Boot Order` in the GUI results in invalid bootorder: device 'usb2' does not exist' (500).

Trying to use this "USB" drive on any VM other than the one it was created on doesn't work because it needs tp be running to add the device, & there's no indication that it ever even tries to boot to the device
 
In both your .conf files, you're not showing any additional line that indicates what that usb2 device is. You do have one for usb0 but not for usb2.
Correct. It was created using THIS Guide...

Line 2: args: -drive file=/spinning/usbdrive/usb2.img,if=none,id=drive-usb2,format=raw,cache=none -device usb-storage,id=drive-usb2,drive=drive-usb2,removable=on is the only place that it exists. As the guide says it's created in the [Monitor] settings & made permanent via the args addition. At the end it says it can be used to boot... But I do not see how that is possible & no information as to how that is done was given... That's why I was asking how to do that... & why I specified that it is visible inside the Machine but not in Proxmox anywhere... The "additional lines" would make it visible in Proxmox... Which is what I'm asking how to do... But which was not explained... In the guide... that this thread is about... I'm not really sure why you thought that it should be there. Is it there when you do it? Can you share your .conf where it works?

I've tried adding an entry for it... But nothing I tried worked
The ones I remember are:
usb2: drive=drive-usb2,removable=on
usb2: drive=drive-usb2
usb2: file=/spinning/usbdrive/usb2.img,if=none,id=drive-usb2,format=raw,cache=none
usb2: file=/spinning/usbdrive/usb2.img
I tried a few other things but I don't remember what exactly I tried as nothing worked
 
Last edited:
Sorry for any misunderstanding, I have never configured the above said "USB Device". I'm just trying to go through possible suggestions.
Have you tried to set it within the BIOS of the VM?
So when you boot-up the VM in the console, hit the Esc to enter the BIOS/Boot device menu.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!