Attach a raw image as a USB disk to the VM

modem7

Member
Nov 2, 2021
35
2
13
38
Hey guys,

I'm trying to get UNRAID working in a VM, specifically trying to figure out how to virtualise the USB stick aspect.

I've looked at similar issues (https://forum.proxmox.com/threads/setup-usb-disk-image-for-tailsguest.38824/ and https://forum.proxmox.com/threads/attach-a-raw-image-as-a-usb-disk-to-the-vm.27306/) but neither seem to allow UNRAID to write to the virtual usb disk.

Steps performed:
1. Create VHD and SCP it across to Proxmox.
1a. VHD created as required by unraid instructions.
2. Run the following script:

Bash:
VMNUM=1112
VMSCSINUM=0
VMDISKLOC=/mnt/prox/images
DISK_STOR=Proxmox
USBARG="args: -drive 'file=$VMDISKLOC/$VMNUM/vm-$VMNUM-disk-$VMSCSINUM.raw,if=none,id=drive-usb0,format=raw,cache=none,aio=io_uring,detect-zeroes=on' -device 'usb-storage,drive=drive-usb0,bootindex=1,removable=on'"
cd $VMDISKLOC/$VMNUM/
qemu-img convert -O raw UNRAID.vhd unraid.img && \
rm UNRAID.vhd && \
qm importdisk $VMNUM unraid.img $DISK_STOR && \
qm set $VMNUM --scsihw virtio-scsi-pci --scsi$VMSCSINUM $DISK_STOR:$VMNUM/vm-$VMNUM-disk-$VMSCSINUM.raw && \
sed -i -e "1i${USBARG}   ${1}" /etc/pve/qemu-server/$VMNUM.conf

I've tried both:
Code:
args: -drive 'file=/mnt/prox/images/1112/vm-1112-disk-0.raw,if=none,id=drive-usb0,format=raw,cache=none,aio=io_uring,detect-zeroes=on' -device 'usb-storage,drive=drive-usb0,bootindex=1,removable=on'

and

Code:
args: -drive id=stick,if=none,format=raw,file=/mnt/prox/images/1112/unraid.img -device usb-storage,drive=stick,bootindex=1,removable=on

And whilst the VM boots into UNRAID with both, it throws up a warning that it cannot write to the "disk".

Is img/raw the right way to go here?

Has anyone successfully managed to pass through a writeable disk image as a virtual USB disk (regardless if unraid or not)?
 
Last edited:
Hi @modem7

Have you been able to get that working?
I would like to have my unraid as virtual device on my ssd as well.

thanks for answering.
 
Hi @modem7

Have you been able to get that working?
I would like to have my unraid as virtual device on my ssd as well.

thanks for answering.
Unfortunately not.

In the end, I passed the USB stick through.

As much as I dislike the solution, it's currently the only way that works every time.

My current setup is:
1682338806462.png
 
sad...
I am interested why it just not working...
I will do some tests myself
 
sad...
I am interested why it just not working...
I will do some tests myself

Here are my very messy notes as I never got it working in the end, so didn't clean up the notes:

The thing I never really got working was migrating the contents of the USB stick to a VHD.

Specifically, I couldn't get Unraid to verify the GUID as legitimate. There is no way that I could see to change the GUID of the virtual drive (not to be mistaken for the UUID).

I even tried setting the serial number using the info here: https://pve.proxmox.com/wiki/Manual:_qm.conf (serial=<serial>) but no go.

Bash:
SCP VHD to server


VMNUM=100
VMSCSINUM=0
VMDISKLOC=/mnt/prox/images
DISK_STOR=Proxmox
USBARG="args: "
cd $VMDISKLOC/$VMNUM/
qemu-img convert -O raw unraid.vhd unraid.img && \
qm importdisk $VMNUM unraid.img $DISK_STOR && \
qm set $VMNUM --scsihw virtio-scsi-pci --scsi$VMSCSINUM $DISK_STOR:$VMNUM/vm-$VMNUM-disk-$VMSCSINUM.raw && \
qm set $VMNUM -args "-drive if=none,id=drive-usb0,format=raw,cache=none,detect-zeroes=on,file=$VMDISKLOC/$VMNUM/vm-$VMNUM-disk-$VMSCSINUM.img -device usb-storage,drive=drive-usb0,bootindex=1,removable=on" && \
rm unraid.vhd


sed -i -e "1i${USBARG}   ${1}" /etc/pve/qemu-server/$VMNUM.conf


https://www.nicksherlock.com/2020/12/running-tails-as-a-vm-with-persistence-on-proxmox/


nano /etc/pve/qemu-server/$VMNUM.conf


args: -set drive.drive-scsi0.readonly=on -drive 'file=/mnt/prox/images/1112/vm-1112-disk-1.raw,if=none,id=drive-usb0,format=raw,cache=none,aio=io_uring,detect-zeroes=on' -device 'usb-storage,drive=drive-usb0,bootindex=1,removable=on'

args: -set drive.drive-scsi6.readonly=on -drive 'file=/mnt/prox/images/1111/vm-1111-disk-6.raw,if=none,id=drive-usb0,format=raw,cache=none,aio=io_uring,detect-zeroes=on' -device 'usb-storage,drive=drive-usb0,bootindex=1,removable=on'

args: -set drive.drive-scsi$VMSCSINUM.readonly=on -drive 'file=$VMDISKLOC/$VMNUM/vm-$VMNUM-disk-$VMSCSINUM.raw,if=none,id=drive-usb0,format=raw,cache=none,aio=io_uring,detect-zeroes=on' -device 'usb-storage,drive=drive-usb0,bootindex=1,removable=on'
 
Last edited:
I'm not sure whether I should be responding to a year-old thread but just wanted to share my findings because there aren't much available

I'm not completely sure whether the following GUID is defined as-is on the USB drive or whether Unraid generates it from other values. Anyhow, the GUID seems to be generated like this "{USB_idVendor}-{USB_idProduct}-{USB_iSerial_CUT}", where USB_iSerial_CUT is USB's iSerial's last 16 characters with dash (-) after the first 4 characters.

Unraid'd documentation states "You will also need a high-quality, named-brand USB flash device that is at least 2 GB in size, but no larger than 32 GB, that must contain a unique GUID (Globally Unique Identifier)." Which implies that they check at least the vendor id of the drive and therefore only changing the serial of the virtual drive will likely not be sufficient.

Qemu source code has vendor and product ids that cannot be changed: https://gitlab.com/qemu-project/qemu/-/blob/master/hw/usb/dev-storage.c?ref_type=heads#L165

If someone wants to continue the testing, my recommendation is to compile Qemu with real-world idVendor and idProduct (e.g. 0951:1666, which is a real usb drive I have successfully passed through)
 
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!