[SOLVED] LXC and device passthrough

yarii

Renowned Member
Mar 24, 2014
150
8
83
Hi all,

I tried to passthrough /dev/ttyS0 and /dev/ttyUSB0 to container by:

lxc-device add -n 204 /dev/ttyS0
lxc-device add -n 204 /dev/ttyUSB0

It works well.

For making it avaible after container restart I added this to /var/lib/lxc/204/config by adding lines:
lxc.cgroup.devices.allow = c 4:64 rwm
lxc.cgroup.devices.allow = c 188:0 rwm

After container restart there is old config without changes.

How to properly do /dev/USB and /dev/ttyS0 passthrough?

Regards.
JK
 
  • Like
Reactions: undertone2230
Do I need to do something more?

After rebooting container ...
204#
ls -la /dev/ | grep ttyS0
doesn't show anything.
 
I added this:
mknod /dev/ttyS0 c 4 64
chown root.dialout /dev/ttyS0
chmod 0644 /dev/ttyS0

to my rc.local.

And it is OK right now.
 
I did:
mknod /dev/ttyS0 c 4 64
chown root.dialout /dev/ttyS0
chmod 0644 /dev/ttyS0

It is OK right now.
the "lxc.cgroup.devices.allow" lines only tell lxc to setup the container's cgroup to allow access to or creation of the specified device nodes (see https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt for the gory details ;)). You need to create the device nodes yourself in the container (either manually, or using an init script, or using an autodev hook).