This is intended to fix the issue of kvm+qemu not having an usb device reappear inside the vm if the usb bus or device number changes on the host (e.g. due to replugging or a faulty controller) and thus home assistant running inside the vm looses connection to otbr-rcp, rflink, zigbee, ...
- Place the udev rule, e.g. as
/etc/udev/rules.d/50-home-assistant.rules
, and add all the relevant usb dongles with its vendor and device id (get the right ones withlsusb
). - Place the script, e.g. as
/usr/sbin/hoas-usb-reattach.sh
. Make sure to have the right path to the script in the udev rules file. chmod +x /usr/sbin/hoas-usb-reattach.sh
udevadm control --reload-rules && udevadm trigger
Also make sure the usb devices have been added "normally" to the virsh config before,
e.g. through virsh edit ...
or graphically through virt-manager
(to be entirely safe while the machine is off).
They will look something like this:
<hostdev mode="subsystem" type="usb" managed="yes">
<source>
<vendor id="0x2341"/>
<product id="0x0042"/>
</source>
<address type="usb" bus="0" port="5"/>
</hostdev>
Also make sure to remove old definitions like these:
<serial type='dev'>
<source path='/dev/serial/by-id/usb-Arduino__www.arduino.cc__0042_2433331393035111F092-if00'/>
<target type='usb-serial' port='5'>
<model name='usb-serial'/>
</target>
<address type='usb' bus='0' port='5'/>
</serial>
The advantage of using the former over the latter is also that inside the vm devices will
appear with some sensical name like /dev/serial/by-id/usb-Arduino__www.arduino.cc__0042_2433331393035111F092-if00
instead of some cryptic kvm generated non-useful name (so exactly the same name as on the host).