An open API service indexing awesome lists of open source software.

https://github.com/kvaps/usbredirtools

Collection of scripts for passing through the usb-devices to VMs
https://github.com/kvaps/usbredirtools

Last synced: 3 months ago
JSON representation

Collection of scripts for passing through the usb-devices to VMs

Awesome Lists containing this project

README

          

usbredirtools
=============
These scripts help you passthrough many identical usb-devices (with the same vendorid:productid pair) for selected virtual machines, using [usbredir](http://www.spice-space.org/page/UsbRedir) protocol in daemon mode, without using spice.

## USB Server install
- Install **usbredirserver**, **inotifywait** and **fuser** packages, it is required
- Install units and script:
```bash
curl -o /etc/systemd/system/usbredirserver\@.service https://raw.githubusercontent.com/kvaps/usbredirtools/master/usbredirserver%40.service
curl -o /etc/systemd/system/usbredirserver.service https://raw.githubusercontent.com/kvaps/usbredirtools/master/usbredirserver.service
curl -o /bin/usbredirserver.sh https://raw.githubusercontent.com/kvaps/usbredirtools/master/usbredirserver.sh
chmod +x /bin/usbredirserver.sh
```
- `mkdir /var/lib/usbredirserver/`

#### Export usb-devce
- run `lsusb`, find your device:
```
Bus 003 Device 090: ID 125f:c82a A-DATA Technology Co., Ltd.
```
- run `udevadm info -a -n /dev/bus/usb/003/090 | grep 'ATTR{serial}\|KERNEL[^S]'`
```
KERNEL=="3-2"
ATTR{serial}=="11C130317234004B"
```
- `vim /etc/udev/rules.d/99-usb-serial.rules`
```
# by serial number
ACTION=="add", ATTR{serial}=="11C130317234004B", RUN+="/bin/bash -c 'PORT=4000; echo -e BUS=$attr{busnum}\\nDEV=$attr{devnum} > /var/lib/usbredirserver/$PORT'"
# by phisical port
ACTION=="add", KERNEL=="3-2", RUN+="/bin/bash -c 'PORT=4000; echo -e BUS=$attr{busnum}\\nDEV=$attr{devnum} > /var/lib/usbredirserver/$PORT'"
```
- `udevadm control --reload-rules`
- Start and enable usbredirserver service:
```bash
systemctl start usbredirserver.service
systemctl enable usbredirserver.service
```

## Hypervisor install (opennebula)

#### hook setup
- `curl https://raw.githubusercontent.com/kvaps/usbredirtools/master/usbredir_hook.sh -o /var/lib/one/remotes/hooks/usbredir_hook.sh`
- `chmod +x /var/lib/one/remotes/hooks/usbredir_hook.sh`
- Declare hook in `/etc/one/oned.conf`:
```
VM_HOOK = [
name = "usbredir_connect",
on = "RUNNING",
command = "usbredir_hook.sh",
arguments = "connect $ID $TEMPLATE" ]

VM_HOOK = [
name = "usbredir_disconnect",
on = "CUSTOM",
state = "ACTIVE",
lcm_state = "SAVE_SUSPEND",
command = "usbredir_hook.sh",
arguments = "disconnect $ID $TEMPLATE" ]
```
- `systemctl restart opennebula`

#### vm setup
- add this code to your template, into kvm raw data section:
```xml




```
- add your usb devices into your template, like:
```
USBREDIR0="192.168.1.123:4000"
USBREDIR1="192.168.1.123:4001"
```

## Hypervisor install (proxmox)

#### qemu setup
- `curl http://cgit.freedesktop.org/spice/qemu/plain/docs/ich9-ehci-uhci.cfg --create-dirs -o /etc/qemu/ich9-ehci-uhci.cfg`

#### vm setup
- add this options to start command in virtual machine config file into `args` section:
```
-readconfig /etc/qemu/ich9-ehci-uhci.cfg
-chardev socket,id=charredir3,port=4000,host=192.168.1.123
-device usb-redir,chardev=charredir3,id=redir3,bus=usb.0
```

## Watchdog service

Optionally, you may install usbredirwatchdog service on your hypervisors, it will reconnect the usb-devices if they was disconnected for some reasons.

It works this way:
Every `n` times, watchdog script calls `ps aux` and checks for running virtual machines with chadredir parameters.
After this watchdog script check the status of each chardev and reconnect it if it does not exist or disconnected.
The frequency is configured as the first script argument, by default it is 10 seconds.
Warning: this watchdog does not work with devices connected via opennebula hook.

#### Install instructions
- For proxmox you need install **expect** package.
- `curl https://raw.githubusercontent.com/kvaps/usbredirtools/master/usbredirwatchdog.sh -o /usr/local/bin/usbredirwatchdog.sh`
- `chmod +x /usr/local/bin/usbredirwatchdog.sh`
- `curl https://raw.githubusercontent.com/kvaps/usbredirtools/master/usbredirwatchdog.service -o /etc/systemd/system/usbredirwatchdog.service`
- `systemctl enable usbredirwatchdog`
- `systemctl start usbredirwatchdog`