
Ich versuche derzeit, GPIO-Zugriff auf einen nicht privilegierten LXC-Anwendungscontainer zu erhalten. In Zukunft soll dieser Container eine Anwendung ausführen. Aber vorerst (während der Entwicklung) starte ich einfach eine normale Bash im Container:
sudo lxc-execute -n gpio-client -f /var/proj/gpio-client/lxc.conf -- bin/bash
Wenn ich dies mit einem privilegierten Container mache (d. h. meine lxc.conf enthält keine UID- oder GID-Zuordnung), kann ich die GPIOs verwenden. Auf
die GPIOs kann über Dateien in /sys/class/gpio zugegriffen werden (die folgende Ausgabe stammt von einer Bash innerhalb eines privilegierten Containers, der mit dem obigen Befehl gestartet wurde):
bash-4.3# cd /sys/class/gpio/
bash-4.3# ls -l
total 0
-rwxrwx--- 1 gpio-cli 1001 4096 Feb 20 12:41 export
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 12:41 gpiochip890 -> ../../devices/gpiochip2/gpio/gpiochip890
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 12:41 gpiochip898 -> ../../devices/gpiochip1/gpio/gpiochip898
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 12:41 gpiochip906 -> ../../devices/soc0/amba/e000a000.gpio/gpio/gpiochip906
-rwxrwx--- 1 gpio-cli 1001 4096 Feb 20 12:41 unexport
Beispielsweise kann ich einen GPIO exportieren:
bash-4.3# echo 898 > export
bash-4.3# ls -l
total 0
-rwxrwx--- 1 gpio-cli 1001 4096 Feb 20 14:06 export
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 14:06 gpio898 -> ../../devices/gpiochip1/gpio/gpio898
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 12:41 gpiochip890 -> ../../devices/gpiochip2/gpio/gpiochip890
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 12:41 gpiochip898 -> ../../devices/gpiochip1/gpio/gpiochip898
lrwxrwxrwx 1 gpio-cli 1001 0 Feb 20 12:41 gpiochip906 -> ../../devices/soc0/amba/e000a000.gpio/gpio/gpiochip906
-rwxrwx--- 1 gpio-cli 1001 4096 Feb 20 12:41 unexport
Wenn ich die laufenden Prozesse auf dem Host mit „ps -a“ ausdrucke, kann ich die laufende Bash als Root sehen:
587 root 0:00 lxc-execute -n gpio-client -f /var/proj/gpio-client/lxc.conf -- bin/bash
598 root 0:00 /init.lxc.static -- bin/bash
615 root 0:00 bin/bash
Aber wenn ich eine UID- und GID-Zuordnung in die lxc.conf einfüge (und auch die Subuids und Subgids in /etc/subuid und /etc/subgid), erhalte ich immer die Meldung „Zugriff verweigert“, wenn ich versuche, auf /sys/class/gpio zuzugreifen:
bash-4.3# cd /sys/class/
bash-4.3# ls -l
total 0
drwxrwx--- 2 65534 gpio 0 Feb 20 14:11 gpio
bash-4.3# cd gpio/
bash: cd: gpio/: Permission denied
Dies ist meine lxc.conf:
# *************************************************************************
# * general configuration
# *************************************************************************
# container name
lxc.utsname = gpio-client
# *************************************************************************
# * configure networking
# *************************************************************************
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = local_br0
lxc.network.name = lxcnet0
lxc.network.hwaddr = 4a:49:43:49:79:ac
lxc.network.ipv4 = 10.10.0.98
lxc.network.ipv4.gateway = 10.10.0.1
# *************************************************************************
# * configure container filesystem
# *************************************************************************
# set rootfs
lxc.rootfs = /var/proj/gpio-client/rootfs
# mount needed directories from host
lxc.mount.entry=/lib lib none ro,bind 0 0
lxc.mount.entry=/sys/class/gpio sys/class/gpio none rw,bind 0 0
lxc.mount.entry=/sys/devices sys/devices none rw,bind 0 0
lxc.mount.entry=/usr/lib usr/lib none ro,bind 0 0
lxc.mount.entry=/usr/bin usr/bin none ro,bind 0 0
lxc.mount.entry=/bin bin none ro,bind 0 0
# *************************************************************************
# * configure privileges of container
# *************************************************************************
# map user and group ids
lxc.include = /usr/share/lxc/config/userns.conf
# comment the following out for a privileged container:
lxc.id_map = u 0 1000000 65536
lxc.id_map = g 0 1000000 65536
Dies ist das laufende Linux-System:
zedboard-zynq7:/var/proj/gpio-client$ cat /proc/version
Linux version 4.6.0-rt1-xilinx-v2016.3 (sebastian@ubuntu1604vm) (gcc version 6.2.0 (GCC) ) #5 SMP PREEMPT RT Fri Apr 7 13:43:09 CEST 2017
Das System wurde mit Yocto für ein AVNET-Zedboard (das über ein Xilinx Zynq-SoC verfügt) erstellt.
Hat jemand eine Idee oder einen Rat, wie man das zum Laufen bekommt oder wo man die Lösung/Informationen dazu findet? Ich habe ein paar Stunden lang versucht, es zum Laufen zu bringen, aber leider habe ich es nicht geschafft...
Viele Grüße
Sebastian