[SOLVED] Mount Block/File as USB in Guest

Oct 16, 2021
14
2
8
Hello,

I am trying to automate the installation of pfSense via the use of their ECL feature (stick a USB in with the config during installation and it automatically restores every boot).
https://docs.netgate.com/pfsense/en...-using-the-external-configuration-locator-ecl

I am struggling on how exactly to achive this on Proxmox other than having a single USB device plugged into a physical host.

Is there a way I can simply attach a USB device to a guest then point it at VHD file?

Any help would be massively appreciated. :)
 
Last edited:
I have also looked at trying something like emulating USB on Debian which sounded promising.
https://unix.stackexchange.com/questions/338026/centos-how-to-emulate-a-usb-flashdrive

i.e. something like this (but the dummy_hcd kernel module not being included in 5.13.19-6-pve stops me. :(
modprobe dummy_hcd modprobe: FATAL: Module dummy_hcd not found in directory /lib/modules/5.13.19-6-pve
then
modprobe g_mass_storage file=/path/to/backing_file idVendor=0x1d6b idProduct=0x0104 iManufacturer=Myself iProduct=VirtualBlockDevice iSerialNumber=123
 
Last edited:
Thanks for the reply @leesteken !

I have added
args: -drive if=none,id=stick,format=raw,file=/var/lib/vz/template/iso/pfconfig-test.img -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick
as documented in
https://qemu-project.gitlab.io/qemu/system/devices/usb.html

The VM seems to see the device during boot but fails with
Root mount waiting for : CAM (for many lines)
then
CAM status: CCB request completed with an error

I am thinking perhaps mkfs.fat -F 16 pfconfig-test.img or mkfs.fat -F 32 pfconfig-test.img aren't enough and I need to give the .img a partition structure like /dev/sda1 to format? Not sure how to do that but will update if I find anything more and manage to get it working.
 
I got this working with the below for anyone who comes across the same issue.

dd if=/dev/zero of=/tmp/pfsense-config.img count=204800 apt install multipath-tools kpartx -a /tmp/pfsense-config.img mkfs.vfat -F 32 /dev/mapper/loop0p1 mkdir /tmp/pfsense-config-temp-mount mount /dev/mapper/loop0p1 /tmp/pfsense-config-temp-mount mkdir /tmp/pfsense-config-temp-mount/config cp yourpfsenseconfig.xml /tmp/pfsense-config-temp-mount/config/config.xml umount /tmp/pfsense-config-temp-mount rmdir /tmp/pfsense-config-temp-mount kpartx -d /dev/loop0 mv /tmp/pfsense-config.img /var/lib/vz/private/pfsense-config.img

Then add this to /etc/pve/qeum_server/<vmid>.conf.
args: -drive if=none,id=stick,format=raw,file=/var/lib/vz/private/pfconfig-test.img -device nec-usb-xhci,id=xhci -device usb-storage,bus=xhci.0,drive=stick
 
Last edited:
  • Like
Reactions: leesteken
I got this working with the below for anyone who comes across the same issue.

I am trying to follow these steps but am unsure what /dev/mapper/loop0p1 is meant to be. I have tried referencing /tmp/pfsense-config.img instead and it seemed to work okay...

On my mac, I am able to mount the .img and see the config file in it.

pfsense setup though hangs very long at zfsboot while saying probing devices.

Any hints what I might be doing wrong?
 
Last edited: