usb-libvirt-hotplug
Initially this script was a clone of this project: https://github.com/olavmrk/usb-libvirt-hotplug But in my case I could not attache USB device over UDEV rules. My script does not need any modification to UDEV rules, it uses the lsusb command instead.
The main daemon checks once in every five seconds if the host machine is running. If yes it starts the main script to serve the USB connections. The main script checks every second the USB devices and if it finds the matching device from the listing file it connects this device to host machine. If the device is unplugged the main script removes the device from the host machine. On the turning off the host machine the all connected USB devices are removed automatically. You can edit the listing file anytime even when your host machine is running. All the information will be updated uptime. How it works
How to install (Ubuntu and family members)
- copy the files to any folder on the server
-
open the configuration file config.sh and edit the needed information:
DOMAIN="win7-64-modules" you host domain name SC=usb-libvirt-hotplug.sh the main script name - you can keep the original name DIR=/SAMBA/4T/eldar/AQEMU/usb-devices the absolute path to the folder where are the all the scripts located USBALLOW=/etc/libvirt/${DOMAIN}.usb the location of the file with the list of the all the USB devices you want to be connected to your host machine - the listing file cmdUSB=${DIR}/${SC} the path and the script name to launch when your host machine is running
-
the content of the file with the list of USB devices to be connected to you host machine (i.e. the file /etc/libvirt/${DOMAIN}.usb) consists of the values of DeviceID:VendorID:
2013:0001 2013:0002 0416:9391 1908:2070
You can get the needed values of DeviceID:VendorID of your USB device from lsusb command:root@mice:/home/eldar/build# lsusb Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 005: ID 2013:0001 PCTV Systems Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
- open file usb-libvirt-hotplug.service for editing:
[Unit] Description=usb-libvirt-hotplug bg listener
[Service] User=root Group=root Type=idle
WorkingDirectory=/SAMBA/4T/eldar/AQEMU/usb-devices/ the absolute path to the folder where are the all the scripts located ExecStart=/SAMBA/4T/eldar/AQEMU/usb-devices/usb-libvirt-hotplug.run.sh the location of the file with the list of the all the USB devices you want to be connected to your host machine
[Install] WantedBy=multi-user.target
- start up the script on server booting
cp usb-libvirt-hotplug.service /lib/systemd/system/ systemctl enable usb-libvirt-hotplug.service systemctl daemon-reload service usb-libvirt-hotplug start
#Virtual_manager, #QEMU, #USB