Last active
December 16, 2024 17:23
-
-
Save nickpegg/417cf5024b765c3c92cbfbd725310091 to your computer and use it in GitHub Desktop.
KVM USB auto-passthrough using udev
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File location: /etc/udev/rules.d/90-libvirt-usb.rules | |
ACTION=="bind", \ | |
SUBSYSTEM=="usb", \ | |
ENV{ID_VENDOR_ID}=="6b62", \ | |
ENV{ID_MODEL_ID}=="6869", \ | |
RUN+="/usr/local/bin/kvm-udev attach <domain>" | |
ACTION=="remove", \ | |
SUBSYSTEM=="usb", \ | |
ENV{ID_VENDOR_ID}=="6b62", \ | |
ENV{ID_MODEL_ID}=="6869", \ | |
RUN+="/usr/local/bin/kvm-udev detach <domain>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# File location: /usr/local/bin/kvm-udev.sh | |
# Usage: ./kvm-udev.sh attach|detach <domain> | |
set -e | |
ACTION=$1 | |
DOMAIN=$2 | |
CONF_FILE=$(mktemp --suffix=.kvm-udev) | |
cat << EOF >$CONF_FILE | |
<hostdev mode='subsystem' type='${SUBSYSTEM}'> | |
<source> | |
<vendor id='0x${ID_VENDOR_ID}' /> | |
<product id='0x${ID_MODEL_ID}' /> | |
</source> | |
</hostdev> | |
EOF | |
virsh "${ACTION}-device" "$DOMAIN" "$conf_file" | |
rm "$CONF_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment