I want to access special USB device (not a simple flash drive) from inside container.
I bind /dev/bus/usb
inside container, lsusb
lists USBs effortlessly:
$ lsusb
...
Bus 002 Device 002: ID 0a89:0009
...
but my program can't interact with this device.
Best Answer
systemd-nspawn
handles permissions for devices through cgroups. By default, any container is granted with permissions only for common devices like/dev/null
,/dev/zero
, etc, and additionally to any device passed directly to--bind
argument like--bind=/dev/vcs
. This won't work with USB because/dev/bus/usb
is a directory.To grant permission for currently running container named
my_container
(supposedly you started it withsystemd-nspawn
directly from command line) execute as root:c 189:* rwm
means read write modify permissions for any character device with type (identificator) 189 and any subtype. You can find type and subtype of device withfile
:This permission will only last while container is running.
If you are using
systemd-nspawn@.service
or want to persist permissions with it, createor
(depending on whether you want access to USB from any
systemd-nspawn
container or only frommy_container
correspondingly) with the following content:usb_device
is an alias. You can find other in/proc/devices
.