I’ve updated the script, since it was error-prone and with updated script you don’t need to specify the attached USB devices:
Disable sys-audio autostart.
Run these commands in dom0:
sudo mkdir /etc/libvirt/hooks/
cat << 'EOF' | sudo tee /etc/libvirt/hooks/libxl >/dev/null
#!/bin/bash
guest_name="$1"
libvirt_operation="$2"
timeout=60
guest_to_start_on_usb="sys-audio"
if [ "$guest_name" = "sys-usb" ] && [ "$libvirt_operation" = "started" ]; then
(
exec 0</dev/null
exec 1>/dev/null
exec 2>/dev/null
guest_attached_usb_list=$(qvm-usb list "$guest_to_start_on_usb" | awk '{ print $1 }')
for i in $(seq 1 $timeout);
do
if qvm-ls --running $guest_name | grep -q Running; then
present_usb_list=$(qvm-usb list | grep -w "$guest_to_start_on_usb" | awk '{ print $1 }')
if [ "$guest_attached_usb_list" = "$present_usb_list" ]; then
qvm-start --skip-if-running -q $guest_to_start_on_usb
break
fi
fi
sleep 1
done
) & disown
fi
EOF
sudo chmod +x /etc/libvirt/hooks/libxl
Reboot.
Related issue:
Require sys-usb to start before starting qubes with persistently attached USB devices · Issue #7498 · QubesOS/qubes-issues · GitHub