connect usb hardware to kvm

Since I’ve found really few documentation on connecting usb devices to kvm virtual machine without middle software like spice or libvirt I’ll post what I found here.

 

I’ve found two method but only the 2nd work with usb2serial adapter.

USBVIDPID=0403:6001
USBD=""
for line in $(lsusb | grep $USBVIDPID | sed -n "s/Bus 0*\([0-9]*\) Device 0*\([0-9]*\).*/-device usb-host,hostbus=\\1,hostaddr=\\2/p")
do
USBD="$USBD $line"
done
USBVIDPID=0403:6001
cnt=0
USBD=""
killall usbredirserver
for line in $(lsusb | grep $USBVIDPID | sed -n "s/Bus 0*\([0-9]*\) Device 0*\([0-9]*\).*/\\1-\\2/p")
do
/usr/sbin/usbredirserver -p $(( 4000 + $cnt )) $line >/var/log/kvm/${NAME}-usb-$line.log 2>&1 &
USBD="$USBD -chardev socket,id=usbredirchardev${cnt},host=localhost,port=$(( 4000 + $cnt )) \
-device usb-redir,chardev=usbredirchardev${cnt},id=usbredirdev${cnt},debug=3" #,bus=ehci.0,
let cnt=cnt+1
done

Leave a Reply

You must be logged in to post a comment.