udev hotplug script for proxmox. plug a disk into the host and it automatically shows up inside a vm as raw passthrough.
it skips the host boot disk, waits a few seconds for the device to settle, resolves the stable /dev/disk/by-id path, counts the existing scsi entries on the vm to find the next free slot, then attaches the disk with qm set.
to use it, set VMID and BOOT_DISK_PATTERN at the top of the script, drop it in /usr/local/bin and make it executable, then add a udev rule that runs it on block device add events with the kernel name as the argument. for example in /etc/udev/rules.d/99-disk-passthrough.rules:
ACTION=="add", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", RUN+="/usr/local/bin/disk-passthrough.sh %k"
note that unplugging the disk does not remove it from the vm config, you have to delete the scsi entry yourself if you want it gone.