summaryrefslogtreecommitdiffstats
path: root/projectroot
diff options
context:
space:
mode:
authorJuergen Borleis <jbe@pengutronix.de>2019-06-28 09:48:07 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-06-28 10:07:10 +0200
commit6e1b162fb9f03c18ea7e865659b4d44ee48a371b (patch)
tree0d04285c0554b12bc396eb2b9a88ff8af7d66911 /projectroot
parent3f50dc5310c31297772c8f2326bbaee7df3d8a1f (diff)
downloadptxdist-6e1b162fb9f03c18ea7e865659b4d44ee48a371b.tar.gz
ptxdist-6e1b162fb9f03c18ea7e865659b4d44ee48a371b.tar.xz
rootfs: keep /var writable, even if the rootfs is read-only
Having a read-only root filesystem is always a source of pain and trouble. Many applications and tools expect to be able to store their state or caching data or at least their logs somewhere in the filesystem. The '/var' directory tree has a well known structure according to the "File System Hierarchy Standard" and is used by all carefully designed programs. Thus, this change provides a way to have this '/var' directory tree writable, even if the main root filesystem is mounted read-only. It uses an overlay filesystem and by default a RAM disk to store changed and added data to this directory tree in a non persistent manner. Due to the nature of the overlay filesystem the underlaying files from the main root filesystem can still be accessed. This approach requires the overlay filesystem support from the Linux kernel. In order to use it, the feature CONFIG_OVERLAY_FS must be enabled. The ugly details to establish the required overlaying filesystem are hidden behind a "mount helper" for a dummy filesystem (here called 'varoverlayfs'). Thus, a BSP can change the overlaying filesystem by providing its own 'run-varoverlay.mount' in order to restrict the default RAM disk differently or to switch to a different local storage. The '/etc/fstab' file gets touched in this change, to enable some already used RAM disks on demand, to gain backward compatibility if no overlay approach is used. Signed-off-by: Juergen Borleis <jbe@pengutronix.de> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'projectroot')
-rw-r--r--projectroot/etc/fstab6
-rw-r--r--projectroot/usr/lib/systemd/system/run-varoverlayfs.mount9
-rw-r--r--projectroot/usr/lib/systemd/system/var.mount11
-rw-r--r--projectroot/usr/sbin/mount.varoverlayfs11
4 files changed, 34 insertions, 3 deletions
diff --git a/projectroot/etc/fstab b/projectroot/etc/fstab
index 0121c3076..364b495a9 100644
--- a/projectroot/etc/fstab
+++ b/projectroot/etc/fstab
@@ -11,6 +11,6 @@ debugfs /sys/kernel/debug debugfs noauto 0 0
# ramdisks
tmpfs /tmp tmpfs nosuid,nodev,mode=1777,size=20% 0 0
tmpfs /run tmpfs nosuid,nodev,strictatime,mode=0755 0 0
-tmpfs /var/log tmpfs nosuid,nodev,noexec,mode=0755,size=10% 0 0
-tmpfs /var/lock tmpfs nosuid,nodev,noexec,mode=0755,size=1M 0 0
-tmpfs /var/tmp tmpfs nosuid,nodev,mode=1777,size=20% 0 0
+@VAR_OVERLAYFS@tmpfs /var/log tmpfs nosuid,nodev,noexec,mode=0755,size=10% 0 0
+@VAR_OVERLAYFS@tmpfs /var/lock tmpfs nosuid,nodev,noexec,mode=0755,size=1M 0 0
+@VAR_OVERLAYFS@tmpfs /var/tmp tmpfs nosuid,nodev,mode=1777,size=20% 0 0
diff --git a/projectroot/usr/lib/systemd/system/run-varoverlayfs.mount b/projectroot/usr/lib/systemd/system/run-varoverlayfs.mount
new file mode 100644
index 000000000..c067b9b96
--- /dev/null
+++ b/projectroot/usr/lib/systemd/system/run-varoverlayfs.mount
@@ -0,0 +1,9 @@
+[Unit]
+Description=Overlay for '/var'
+Before=local-fs.target
+
+[Mount]
+Where=/run/varoverlayfs
+What=tmpfs
+Type=tmpfs
+Options=size=20%
diff --git a/projectroot/usr/lib/systemd/system/var.mount b/projectroot/usr/lib/systemd/system/var.mount
new file mode 100644
index 000000000..bd6350237
--- /dev/null
+++ b/projectroot/usr/lib/systemd/system/var.mount
@@ -0,0 +1,11 @@
+[Unit]
+Description=Writable support for '/var'
+After=run-varoverlayfs.mount
+Before=local-fs.target
+
+[Mount]
+Where=/var
+# note: this is a dummy filesystem only to trigger the corresponding mount helper
+What=varoverlayfs
+Type=varoverlayfs
+Options=metacopy=on
diff --git a/projectroot/usr/sbin/mount.varoverlayfs b/projectroot/usr/sbin/mount.varoverlayfs
new file mode 100644
index 000000000..f8fc8c88f
--- /dev/null
+++ b/projectroot/usr/sbin/mount.varoverlayfs
@@ -0,0 +1,11 @@
+#!/bin/sh -e
+# Mount helper tool to mount some kind of writable filesystem over '/var'
+# (which might be read-only).
+# What kind of filesystem is used to mount over '/var' can be controlled via
+# the 'run-varoverlayfs.mount' mount unit and is usually a RAM disk.
+
+mkdir -p /run/varoverlayfs/upper
+mkdir -p /run/varoverlayfs/work
+mount -t overlay -olowerdir=/var,upperdir=/run/varoverlayfs/upper,workdir=/run/varoverlayfs/work "${@}"
+systemctl stop run-varoverlayfs.mount
+rmdir /run/varoverlayfs