[TUTORIAL] Virtual Pendrive on VM

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.
I've tried the BIOS in the VM but it doesn't even have a section to change
 
I've tried the BIOS in the VM but it doesn't even have a section to change
I'm sorry I don't currently have a VM with OVMF bios (in test, non-production scenario) that I can currently reboot to test. But I'm almost sure that in the past I have managed to enter a BIOS/BOOT/SELECTION section of the OVMF bios. If I have a chance I'll try & spin something up to test.
Do you have any screenshots of the BIOS/settings you are able to see?
 
Screenshot 2024-04-01 124459.pngScreenshot 2024-04-01 124539.pngScreenshot 2024-04-01 130655.png


So I spun up a Linux Mint VM on OVMF/UEFI bios - added a Gparted CD Rom image to it. And I'm able to enter the bios settings & boot from whatever.

It would be surprising that you see the USB disk in Windows Disk Management, but not in the BIOS. Maybe some Secure Boot constraint?

EDIT: I also further added a SystemRescue Cd rom, which I know has problems booting in some UEFI scenarios - and yes I couldn't boot from it - but it still showed up in the BIOS.
 
Last edited:
I wish i could add a Pendrive in the GUI.
Lovely & useful idea. Would use it endlessly. Should be implemented with no backup enabled for VM. Should also be "hot swappable" & "insertable" on any VM (not at the same time). Coming to think of it - it shouldn't have any VMID configuration attached to it.
I go on & on asking for everything ......
 
Last edited:
  • Like
Reactions: LostOnTheLine
I followed the tutorial and was able to burn the virtual USB perfectly. Thank you @PanWaclaw !
However, I notice the speed of the interface is terribly low. I checked over VM -> Monitor, the "info usb" and shows me using ubs 1.1:

Code:
Type 'help' for help.
# info usb
  Device 0.1, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet, ID: tablet
  Device 0.2, Port 2, Speed 12 Mb/s, Product QEMU USB Hub
  Device 0.3, Port 2.1, Speed 12 Mb/s, Product QEMU USB MSD, ID: drive-usb0

Does anyone know how can I change it at least to USB 2.0?

Thank you,
 
Does anyone know how can I change it at least to USB 2.0?
I believe your going to need to add a device usb-xhci, and then add device usb-storage to the bus as bus=xhci.0
As per docs.

Note: I've never personally done this or used any virtual USB flash stick, only attempting to help.
 
Thanks @gfngfn256 for suggestion but struggling to get correct parameters / commands. VM don't start bc unable to find out this bus=xhci.0 :(
I mitigated it adding usb0 as SPICE (don't know why) but only to 100Mb... it is really paintful process if can not get USB2.0 or even better USB3.1 to move data around
 
but struggling to get correct parameters / commands
Again I've never done this, but how about (based on @PanWaclaw advice in first post):

1. Create Flash Drive image:
Bash:
dd bs=1G count=8 if=/dev/zero of=/tmp/usb0.img

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

3. Add a USB xhci bus [VM --> Monitor]:
Code:
device_add nec-usb-xhci,id=xhci

4. Install our flash drive in the slot on the xhci bus [VM --> Monitor]:
Code:
device_add usb-storage,bus=xhci.0,drive=drive-usb0,removable=on

I'd really be interested to know, if this works.

EDIT: For my own reference (based on test case of user in coming posts) - changed step 4 from:
Code:
device_add usb-storage,bus=xhci.0,id=drive-usb0,drive=drive-usb0,removable=on
 
Last edited:
  • Like
Reactions: Kingneutron
Again I've never done this, but how about (based on @PanWaclaw advice in first post):

1. Create Flash Drive image:
Bash:
dd bs=1G count=8 if=/dev/zero of=/tmp/usb0.img

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

3. Add a USB xhci bus [VM --> Monitor]:
Code:
device_add nec-usb-xhci,id=xhci

4. Install our flash drive in the slot on the xhci bus [VM --> Monitor]:
Code:
device_add usb-storage,bus=xhci.0,id=drive-usb0,drive=drive-usb0,removable=on

I'd really be interested to know, if this works.
Everything works well but step 4. I get the following error:
Code:
# device_add usb-storage,bus=xhci.0,id=drive-usb0,drive=drive-usb0,removable=on
Error: Property 'usb-storage.drive' can't find value 'drive-usb0'

However, if I run this similar command without "bus=xhci.0" it works
Code:
device_add usb-storage,id=drive-usb0,drive=drive-usb0,removable=on

Thanks,
 
However, if I run this similar command without "bus=xhci.0" it works
Have you checked speeds with this.

How about you replace command number 4, with:
Code:
device_add usb-storage,bus=xhci.0,drive=drive-usb0,removable=on
& then check speeds.
 
@gfngfn256 thank you! it worked! and also figure out way bc q35 machines have slightly difference (always enabling USB3.0 performance).
Let me summarize:

  • SeaBIOS machines (I can do it over VM>Monitor, requires VM running)
Code:
drive_add 0 file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none
device_add nec-usb-xhci,id=xhci
device_add usb-storage,bus=xhci.0,drive=drive-usb0,removable=on

  • Q35 machines which support UEFI (got it working only using args)
Code:
args: -drive file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none -device pcie-root-port,id=root,slot=0 -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=drive-usb0,removable=on

With Q35 machines, I can create personalized windows 11 images using rufus and load it without need of having physical USB.
Thank you!
 
Hi,
Is it possible to change GUID of the emulated pendrive?
The goal is to emulate the pendrive for an unraid.
Thanks
 
The goal is to emulate the pendrive for an unraid.
I've don't use Unraid - but I remember reading many posts of people attempting what you describe (I believe unsuccessfully!).

What I would try If I were you; in step 2 of my above post try adding the serial number, so that would be:

Code:
drive_add 0 file=/tmp/usb0.img,if=none,id=drive-usb0,format=raw,cache=none,serial=12345....
# replacing 12345.... with your actual USB serial

I'm not too sure about this one, so if the above doesn't work, maybe try it in step 4 of above post (& remove it from step 2), so that would be:
Code:
device_add usb-storage,bus=xhci.0,drive=drive-usb0,removable=on,serial=12345....
# replacing 12345.... with your actual USB serial

Good luck & report back.
 
It seems 'serial=...' still not working anymore for drive_add.
I receive the error message:
Block format 'raw' does not support the option 'serial'
For device_add no error, but the GUID is not correct when I see it in the VM.
 
Last edited:
It seems 'serial=...' still not working
As I said before, I don't actually use a Virtual USB drive, so I'm only working from theory.

Searching the web I couldn't find a solution to your problem, (& I found that the qemu drive-serial option has been deprecated some time ago), but maybe we can try the following - which may or may not work.
For device_add no error, but the GUID is not correct when I see it in the VM
I assume from that - you did find a GUID - but not the correct one - so qemu is in fact creating the GUID. Maybe you can share with me what type of GUID it is creating? Can you find any reference of the supplied serial we added (non GUID) in the VM?

Maybe try adding (unlikely to work, I'm trying!) guid=12345..... (or maybe GUID=12345....) to one of the options above?

I'm thinking (although unlikely) that maybe the xhci bus in fact creates the GUID, so lets try:
Code:
device_add nec-usb-xhci,id=xhci,serial=12345....
# replacing 12345.... with your actual USB serial
Report back please.
 
As I said before, I don't actually use a Virtual USB drive, so I'm only working from theory.

Searching the web I couldn't find a solution to your problem, (& I found that the qemu drive-serial option has been deprecated some time ago), but maybe we can try the following - which may or may not work.

I assume from that - you did find a GUID - but not the correct one - so qemu is in fact creating the GUID. Maybe you can share with me what type of GUID it is creating? Can you find any reference of the supplied serial we added (non GUID) in the VM?

Maybe try adding (unlikely to work, I'm trying!) guid=12345..... (or maybe GUID=12345....) to one of the options above?

I'm thinking (although unlikely) that maybe the xhci bus in fact creates the GUID, so lets try:
Code:
device_add nec-usb-xhci,id=xhci,serial=12345....
# replacing 12345.... with your actual USB serial
Report back please.
I tried and it didn't work :( I'm also looking for a way to make a virtual usb stick with a GUID
The last 2 blocks of the serial are correct on windows - aaaa-bbbb-cccc-dddddddddddd - c and d are correct, a and b shows wrong on windows

edit: aaaa-bbbb is 46f4-0001, its the default vid and pid from qemu virtualization. Can I change it?
 
Last edited:
The last 2 blocks of the serial are correct on windows
As I pointed out above, I don't actually use a Virtual USB, & all the posts above from myself were based on theory & not practice.
However about a month ago, I decided to test the above with the intent of trying to get the serial correctly passed to the VM. I only tried with Linux VMs but had zero success. It seems you have already improved on that by getting the serial (partly) passed to a Windows VM. It interests me to know on which line you added the serial to accomplish this.

BTW, this thread is good news for Lime Technology, Inc. !
 
As I pointed out above, I don't actually use a Virtual USB, & all the posts above from myself were based on theory & not practice.
However about a month ago, I decided to test the above with the intent of trying to get the serial correctly passed to the VM. I only tried with Linux VMs but had zero success. It seems you have already improved on that by getting the serial (partly) passed to a Windows VM. It interests me to know on which line you added the serial to accomplish this.

BTW, this thread is good news for Lime Technology, Inc. !
I added the serial part on device_add

I spent the day trying to solve this and did it

First install https://github.com/RushOnline/dummy-hcd dummy_hcd kernel module on proxmox host

Then create the virtual usb stick https://unix.stackexchange.com/questions/338026/centos-how-to-emulate-a-usb-flashdrive

Then I just passed via GUI to the VM I wanted
 
Last edited:

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!