LXC Container mit Readonly RootFS

stickybit

New Member
Dec 10, 2021
6
0
1
46
Hallo,

ich versuche Proxmox zu überreden, den LXC Container readonly zu mounten.

In der Config habe ich entdprechend definiert:

/etc/pve/lxc/9999.conf

Code:
rootfs: local-zfs:subvol-9999-disk-0,mountoptions=lazytime;noatime,ro=1,size=10G

Lt. Doku https://pve.proxmox.com/wiki/Linux_Container sollte das möglich sein.
Allerdings scheitert das Starten des Containers

Code:
run_buffer: 321 Script exited with status 1
lxc_init: 847 Failed to run lxc.hook.pre-start for container "9999"
__lxc_start: 2008 Failed to initialize container "9999"
TASK ERROR: startup for container '9999' failed

DEBUG:

Code:
lxc-start 9999 20230110182021.504 WARN     start - ../src/lxc/start.c:lxc_check_inherited:332 - Inherited fd 9
lxc-start 9999 20230110182021.504 WARN     start - ../src/lxc/start.c:lxc_check_inherited:332 - Inherited fd 11
lxc-start 9999 20230110182021.504 INFO     lsm - ../src/lxc/lsm/lsm.c:lsm_init_static:38 - Initialized LSM security driver AppArmor
lxc-start 9999 20230110182021.504 INFO     conf - ../src/lxc/conf.c:run_script_argv:337 - Executing script "/usr/share/lxc/hooks/lxc-pve-prestart-hook" for container "9999", config section "lxc"
lxc-start 9999 20230110182021.994 DEBUG    conf - ../src/lxc/conf.c:run_buffer:310 - Script exec /usr/share/lxc/hooks/lxc-pve-prestart-hook 9999 lxc pre-start produced output: unable to open file '/fastboot.tmp.3168860' - Read-only file
system

Es wird versucht /fastboot.tmp.3168860 im LXC-Root anzulegen.

Gibt es da einen Trick oder geht das grundsätzlich nicht?

VG
Andre
 
Bei der Recherche bin ich schon auf overlay gestoßen. Nur eben nicht in Verbindung mit XLC.
Das Thema scheint irgendwie nicht populär zu sein ;-)
 
Du kannst das aber mal in einem Testcontainer ganz simpel ausprobieren.

Mal direkt das deb file von
http://launchpadlibrarian.net/493868580/overlayroot_0.47ubuntu1_all.deb
versuchen, und mit
Bash:
apt install -y ./overlayroot_0.47ubuntu1_all.deb
installieren. Ansonsten könntest du dir das auch selbst kompelieren.

Kannst dann auch einfach mittels:
Bash:
sudo overlayroot-chroot
wieder auf das beschreibbare FS zugreifen.

Infos z.B. hier: https://wiki.ubuntuusers.de/overlayroot/

Habe das auf Live-Maschinen in Produktion laufen bei denen einfach der Stecker gezogen wird, kein Problem. Aber noch nicht probiert ob das auch in nem Container läuft :)
Läuft bei mir unter Debian11, Ubuntu sollte ja kein Problem sein, andere ist die Frage...
 
Last edited:
apt install wie beschrieben hat zwar funktioniert, aber hat wohl keine Wirkung, auch nach Konfiguration.

...und

Bash:
root@dev:~# overlayroot-chroot
ERROR: Unable to find an overlayroot filesystem

:eek:
 
Hast du die /etc/overlayroof.conf konfiguriert und neu gestartet?

Im Grunde brauchst du nur:
Code:
overlayroot_cfgdisk="disabled"
overlayroot="tmpfs"
setzen, dann sollte alles read only sein beim nächsten start.
 
wie gesagt, konfiguiert

overlayroot_cfgdisk="disabled" overlayroot="tmpfs"

und neu gestartet. Das Ergebnis ist bekannt :cool:
 
Hi,
ich hatte die gleiche Anforderung und konnte es lösen, indem ich ein AppArmor Profil dafür angelegt habe.
Siehe dazu
https://unix.stackexchange.com/ques...containers-to-mount-nfs-shares-on-the-network

Im Wesentlichen
cp -pf /etc/apparmor.d/lxc/lxc-default-with-nesting /etc/apparmor.d/lxc/lxc-default-with-readonlyrootfs
vim /etc/apparmor.d/lxc/lxc-default-with-readonlyrootfs
und hinten vor der geschwungenen Klammer einfügen:
deny /** w,

Danach dann
systemctl reload apparmor

und zum Schluss (Achtung: 201 durch die eigene CTID anpassen)
echo "lxc.apparmor.profile: lxc-container-default-with-readonlyrootfs" >> /etc/pve/lxc/201.conf

pct start --debug 1 201

Hinweis: beim Login per Console/Shell wird z. B. /root/.profile geschrieben. Man muss nun also noch das ein oder andere deaktivieren oder explizit im AppArmor Profil freischalten.

VG
Uni
 
So einfach war es übrigens doch nicht. Zwar klappte das, wenn der Container bereits lief, aber beim Neustarten gab's dann Probleme. Dies ist also mein aktuelles Profil:

profile lxc-container-default-with-readonlyrootfs flags=(attach_disconnected,mediate_deleted) {
#include <abstractions/lxc/container-base>
#include <abstractions/lxc/start-container>

deny /dev/.lxc/proc/** rw,
deny /dev/.lxc/sys/** rw,
mount fstype=proc -> /var/cache/lxc/**,
mount fstype=sysfs -> /var/cache/lxc/**,
mount options=(rw,bind),
mount fstype=cgroup -> /sys/fs/cgroup/**,
mount fstype=cgroup2 -> /sys/fs/cgroup/**,
mount fstype=ramfs options=(rw, nosuid, nodev, noexec) -> /dev/shm/,
mount options=(rw, rbind) -> /run/systemd/unit-root/,
mount options=(ro, remount, noatime, bind) -> /run/systemd/unit-root/,
mount options=(rw, rbind) -> /run/systemd/unit-root/boot/,
mount options=(ro, remount, noatime, bind) -> /run/systemd/unit-root/boot/,
mount options=(rw, rbind) -> /run/systemd/unit-root/etc/,
mount options=(ro, remount, noatime, bind) -> /run/systemd/unit-root/etc/,
mount options=(rw, rbind) -> /run/systemd/unit-root/home/,
mount options=(rw, rbind) -> /run/systemd/unit-root/root/,
mount options=(ro, remount, noatime, bind) -> /run/systemd/unit-root/root/,
mount options=(rw, rbind) -> /run/systemd/unit-root/run/credentials/,
mount options=(rw, rbind) -> /run/systemd/unit-root/usr/,
mount options=(rw, rbind) -> /run/systemd/unit-root/run/user/,
mount options=(ro, remount, noatime, bind) -> /run/systemd/unit-root/usr/,
mount options=(rw, rbind) -> /run/systemd/unit-root/proc/kmsg,
mount options=(rw, rbind) -> /run/systemd/unit-root/tmp/,
mount options=(rw, rbind) -> /run/systemd/unit-root/run/systemd/netif/,
mount options=(rw, rbind) -> /run/systemd/unit-root/var/tmp/,
mount fstype=configfs options=(rw, nosuid, nodev, noexec) -> /sys/kernel/config/,
mount fstype=proc options=(rw, nosuid, nodev, noexec) -> /run/systemd/unit-root/proc/,
mount options=(rw, nosuid, nodev, noexec, remount, bind) -> /run/systemd/unit-root/proc/,
mount options=(rw, nosuid, nodev, noexec, remount, bind) -> /run/systemd/unit-root/sys/fs/fuse/connections/,
mount options=(rw, nosuid, nodev, noexec, remount, bind) -> /run/systemd/unit-root/sys/devices/system/cpu/,
mount options=(rw, nosuid, nodev, noexec, remount, bind) -> /run/systemd/unit-root/sys/devices/virtual/net/,
mount options=(ro, remount, noatime, bind) -> /run/systemd/unit-root/home/,

# if you have mounted a directory via pct create ...
# or afterwards with
# pct set $id -mp0 "/somewhereonthehost",mp=/data,size=0,ro=0,"mountoptions=noatime;nodev;nosuid;noexec"
# mount options=(ro, nosuid, nodev, noexec, remount, noatime, bind) -> /run/systemd/unit-root/data/,


allow /fastboot w,
deny /* w,
deny /boot/* w,
#deny /dev/** w,
deny /etc/** w,
deny /home/** w,
deny /lost+found/** w,
deny /media/** w,
deny /mnt/** w,
deny /mount/** w,
deny /opt/** w,
deny /root/** w,
#deny /run/** w,
deny /srv/** w,
#deny /sys/** w,
deny /tmp/** w,
deny /usr/** w,
allow /var/tmp/** w,
deny /var/** w,

# symlinks (to be safe)
deny /bin/** w,
deny /lib/** w,
deny /lib32/** w,
deny /lib64/** w,
deny /libx32/** w,
deny /sbin/** w,
}
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!