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

shantanu

Active Member
Mar 30, 2012
112
10
38
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
 

shantanu

Active Member
Mar 30, 2012
112
10
38
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

gosuto

New Member
Jul 12, 2021
1
0
1
35
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
 
Mar 22, 2018
34
6
28
39
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:

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 your own in 60 seconds.

Buy now!