unpriviligierter LXC-Container startet nicht

Alle weiteren Dienste, die nicht in die drei oberen Foren gehören.
Antworten
Benutzeravatar
nyami
Beiträge: 373
Registriert: 14.01.2003 13:30:28
Lizenz eigener Beiträge: GNU General Public License

unpriviligierter LXC-Container startet nicht

Beitrag von nyami » 04.03.2023 07:14:55

Hallo,

LXC als priviligierte Version läuft bei mit schon länger einwandfrei.
Nun habe ich mich wieder an die unpriviligierte Version gemacht und bekomme den Testcontainer
einfach nicht mit Netzwerk zum laufen. Was habe ich gemacht:

Installation mit

Code: Alles auswählen

apt-get update
apt-get dist-upgrade
apt-get install lxc systemd uidmap
dann die uid's und gid's setzen:

Code: Alles auswählen

usermod --add-subuids 100000-165536 $USER
usermod --add-subgids 100000-165536 $USER
chmod +x $HOME
Eine Konfigurationsdatei anlegen:

Code: Alles auswählen

~/.config/lxc/default.conf
und befüllen mit

Code: Alles auswählen

# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template: -d debian -r bullseye -a amd64
# For additional config options, please look at lxc.container.conf(5)

# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)

# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.include = /usr/share/lxc/config/userns.conf
lxc.arch = linux64

# Container specific configuration
lxc.net.0.type = veth
lxc.net.0.link = br0
lxc.net.0.flags = up
lxc.net.0..hwaddr = 00:16:3e:55:xx:xx
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
lxc.rootfs.path = dir:/home/xxxxx/.local/share/lxc/p1/rootfs
lxc.uts.name = p1

#Netzwerkkonfiguration lokal und internet
lxc.net.0.type = macvlan
lxc.net.0.flags = up
lxc.net.0.link = br0
lxc.net.0.macvlan.mode = bridge
lxc.net.0.name = eth1
lxc.net.0.mtu = 1500
lxc.net.0.hwaddr = 00:16:3e:55:xx:xx
lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1

Code: Alles auswählen

/etc/lxc/lxc-usernet                                  Row 1    Col 1   
$USER macvlan br0 10
Die Netzwerkeinstellung für Veth die immer als Beispiel gegeben ist habe ich auskommentiert!

Die Installation eines Containers geht:

Code: Alles auswählen

lxc-create -t download -n p1 -d debian -r bullseye -a amd64
Der Start nicht, ausser ich kommentiere die Netzwerkeinstellungen aus!
Die Mac-Adresse ist dann natürlich eine gültige!
Der Start schlägt fehl, egal ob mit veth, oder macvlan.

Code: Alles auswählen

xc-unpriv-start -n p1
Running scope as unit: run-rb712340243d148489d6a7be67b005555.scope
lxc-start: p1: lxccontainer.c: wait_on_daemonized_start: 859 Received container state "ABORTING" instead of "RUNNING"
lxc-start: p1: tools/lxc_start.c: main: 308 The container failed to start
lxc-start: p1: tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode
lxc-start: p1: tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options
Wenn alle Netzwerkdefinitionen ausgeschaltet sind funktioniert es:

Code: Alles auswählen

lxc-unpriv-attach -n p1
Running scope as unit: run-r260f8d8f213f44f88078516dec7c12fd.scope
root@p1:/# ls
bin   dev  home  lib32	libx32	mnt  proc  run	 srv  tmp  var
boot  etc  lib	 lib64	media	opt  root  sbin  sys  usr
root@p1:/# exit
exit
diverse Hardware...

Benutzeravatar
nyami
Beiträge: 373
Registriert: 14.01.2003 13:30:28
Lizenz eigener Beiträge: GNU General Public License

Re: unpriviligierter LXC-Container startet nicht

Beitrag von nyami » 04.03.2023 17:58:33

nach Ergänzung in der

Code: Alles auswählen

/etc/lxc/lxc-usernet                                  Row 2    Col 1   
$USER macvlan br0 10
$USER veth br0 10
und einem

Code: Alles auswählen

systemctl restart lxc-net
startet der Container

Code: Alles auswählen

$ lxc-unpriv-start -n p1
Running scope as unit: run-rb80c8317ad7c42e3bdea702024cf6670.scope
$ lxc-unpriv-attach -n p1
Running scope as unit: run-r9179d0cb31ae42a7bc6f6544edaac623.scope
root@p1:/# 
root@p1:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:xx:xx:xx brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.2.140/24 brd 192.168.2.255 scope global dynamic eth0
       valid_lft 86360sec preferred_lft 86360sec
    inet6 fe80::216:3eff:fe55:eb82/64 scope link 
       valid_lft forever preferred_lft forever
root@p1:/# ping www.google.de
PING www.google.de (142.250.181.195) 56(84) bytes of data.
64 bytes from ham02s21-in-f3.1e100.net (142.250.181.195): icmp_seq=1 ttl=119 time=17.0 ms
64 bytes from ham02s21-in-f3.1e100.net (142.250.181.195): icmp_seq=2 ttl=119 time=16.1 ms
64 bytes from ham02s21-in-f3.1e100.net (142.250.181.195): icmp_seq=3 ttl=119 time=16.3 ms
^C
--- www.google.de ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 16.074/16.451/17.022/0.410 ms
Alles soweit gut. Ich möchte aber mit macvlan fahren. Wer kann mir helfen?

Hier nochmal die config mit der er wie oben beschrieben bisher läuft:

Code: Alles auswählen

# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template: -d debian -r bullseye -a amd64
# For additional config options, please look at lxc.container.conf(5)

# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)

# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.include = /usr/share/lxc/config/userns.conf
#lxc.arch = linux64

# Container specific configuration
lxc.net.0.type = veth
lxc.net.0.link = br0
lxc.net.0.flags = up
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
lxc.rootfs.path = dir:/home/$USER/.local/share/lxc/p1/rootfs
lxc.uts.name = p1

lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx

lxc.apparmor.profile = unconfined
#lxc.apparmor.profile = generated
#lxc.apparmor.allow_nesting = 1
diverse Hardware...

Antworten