[SOLVED] Attach a raw image as a USB disk to the VM

shantanu

Renowned Member
Mar 30, 2012
112
11
83
Hi,

Is there a way from the WebGUI (or via editing the config) to attach/create a usb disk to the VM ?
That is, the attached raw image file will show up as a USB device from inside the VM.

Regards,
Shantanu
 
Hi LnxBil,
Thank you for the information. (I did search the forums, but could find it :( )

Anyway, I would like to report that this works for me, with a little modification.

Using the line from the website as-is emitted a warning:

Code:
# qm start 103
Running as unit 103.scope.
WARNING: Image format was not specified for '/var/lib/vz/images/103/usb.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.


So, I added the "format=raw" option. The final "args: " line in my config now looks like:
Code:
args: -device piix3-usb-uhci,addr=0x18 -drive id=my_usb_disk,file=/var/lib/vz/images/103/usb.img,if=none,format=raw -device usb-storage,id=my_usb_disk,drive=my_usb_disk

Also, the more important thing that I was really interested in was "booting from virtual USB", which ALSO worked. (Using the noVNC console, I pressed F12 and chose the USB disk option)

I created the bootable USB from INSIDE the VM :)
Ref: http://www.chtaube.eu/computers/freedos/bootable-usb/
:):):)

Thanks,
Shantanu
 
  • Like
Reactions: Hyacin
Both URLs are dead, was stuck with the same problem. My solution:

- prep the 'usb' drive as a regular hard disk on the vm, keep it empty
- add a cdrom drive loaded with ubuntu iso
- boot from iso, do NOT install but run directly from disk ("try ubuntu" option)
- download the .img to /home
- open terminal, run `lsblk` to get device directory
- flash .img to device: `sudo dd if=/home/your_file.img of=/dev/sda bs=1M status=progress`
- stop vm
- unload iso/remove cdrom drive/change boot order
- start vm and let it boot from hard disk, flashed with your bootable .img
 
  • Like
Reactions: swipe
The VM args in shantanu post didn't work for me. Probably it is outdated. I use:

Code:
args: -drive id=stick,if=none,format=raw,file=/home/stick.img -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick

Source: https://qemu-project.gitlab.io/qemu/system/devices/usb.html

If you use q35 machine, the XHCI bus is probably already present by default, so the following is enough:

Code:
args: -drive id=stick,if=none,format=raw,file=/home/stick.img -device usb-storage,drive=stick

Then press ESC in noVNC console to see boot options and choose USB MSC Drive
 
Last edited:
  • Like
Reactions: huey and sudouser
Hello again,

After booting with the virtual usb key, Unraid block my USB GUID.

This USB Flash device has an invalid GUID. Please try a different USB Flash device.

Ql43mZh.png


I tried adding a different serial but it doesn't fix my problem, the USB key becomes blacklisted if I change the serial.

o4muuND.png


I am blocked to register my Unraid server.

My question: is there a way to change the productid and vendorid of the virtual USB stick?

Thank you for your help and sorry for my English! :)
 
Last edited:
  • Like
Reactions: SmartPhoneLover
Hello again,

After booting with the virtual usb key, Unraid block my USB GUID.

This USB Flash device has an invalid GUID. Please try a different USB Flash device.

Ql43mZh.png


I tried adding a different serial but it doesn't fix my problem, the USB key becomes blacklisted if I change the serial.

o4muuND.png


I am blocked to register my Unraid server.

My question: is there a way to change the productid and vendorid of the virtual USB stick?

Thank you for your help and sorry for my English! :)
Did you solve it?