Connecting Zwave Stick Under LXC

A better way to mount /dev/ttyACM0 into the container
September 20, 2018
aeon z-wave lxc

I have an intermittent problem with the Aeon Z-Wave stick not showing up correctly under LXC. I discovered it had happened again tonight when all of the motion-controlled lights stopped working. I’m running Home Assistant, and its UI told me that no Z-Wave devices had been online for the last 11 hours. In order to have the USB dongle show up when I created the container, I had to expressly tell Proxmox to bind-mount it from the host:

lxc.cgroup.devices.allow: c 166:* rwm
lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file

This works, but sometimes the device resets or something happens that causes the bind-mount to fail. In those instances the device shows up in the container mode 000:

c--------- 1 root dialout 166, 0 Sep 21 02:45 /dev/ttyACM0

This shows up in HA’s OZW_Log.txt as a mess of errors complaining about not being able to write to the device.

As usual, I poked at it for a few minutes and looked around to see if others are having similar issues. I came across this post, where Stéphane Graber recommends using mknod to create the device file in a different directory that exists alongside the entry in /dev and bind-mount that instead. The result should be that the non-/dev entry maintains permissions when the /dev entry resets, and the bind-mount entry inside of the container doesn’t reset to 000.

I created /var/lib/lxc/112/devices and then executed this:

mknod -m 660 ttyACM0 c 166 0

This gave me the correct character file. I then modified the container’s config file in /etc/pve/lxc:

lxc.mount.entry: /var/lib/lxc/112/devices/ttyACM0 dev/ttyACM0 none bind,optional,create=file

After rebooting the container the mount works correctly. Time will tell if it survives the random reset issue.