[Buildroot] [git commit] package/skeleton-systemd: systemd-ify mounting /var tmpfs with ro rootfs
Yann E. MORIN
yann.morin.1998 at free.fr
Wed Dec 21 21:10:44 UTC 2022
commit: https://git.buildroot.net/buildroot/commit/?id=8cbfbe487ac6fb00c037475ed8aaca3d89899769
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/master
To mount our /var tmpfs when the rootfs is mounted read-only (really,
not remounted read-write), we use an entry in fstab.
However, /etc could also be a tmpfs (for full state-less systems, or
easy factory-reset, see [0]). It also prevents easily ordering other
systemd units until after /var is mounted (not impossible, but less
easy).
So, we register /var as a systemd mount unit, so that we can also have
the /var factory populated and functional even when /etc is empty. The
var.mount unit is heavily modelled after systemd's own tmp.mount one, so
we carry the same license for that file (in case that may apply).
This has two side effects:
- as hinted previously, it simplifies writing other systemd units to
order them after /var is mounted
- user can easily replace it with their own, which mounts an actual
filesystem
[0] http://0pointer.de/blog/projects/stateless.html
Signed-off-by: Yann E. MORIN <yann.morin at orange.com>
Cc: Norbert Lange <nolange79 at gmail.com>
Cc: Romain Naour <romain.naour at smile.fr>
Cc: JeÌreÌmy Rosen <jeremy.rosen at smile.fr>
[yann.morin.1998 at free.fr:
- split original patch in two
- this one only handles converting /var mounting into a systemd unit
- adapt commit log accordingly
]
Signed-off-by: Yann E. MORIN <yann.morin.1998 at free.fr>
Reviewed-by: Norbert Lange <nolange79 at gmail.com>
[yann.morin.1998 at free.fr (as suggested by Norbert):
- fix Before= dependencies
- drop [Install] section
]
Signed-off-by: Yann E. MORIN <yann.morin.1998 at free.fr>
---
package/skeleton-init-systemd/skeleton-init-systemd.mk | 3 ++-
package/skeleton-init-systemd/var.mount | 15 +++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/package/skeleton-init-systemd/skeleton-init-systemd.mk b/package/skeleton-init-systemd/skeleton-init-systemd.mk
index ec908b4fac..ff8bc528c0 100644
--- a/package/skeleton-init-systemd/skeleton-init-systemd.mk
+++ b/package/skeleton-init-systemd/skeleton-init-systemd.mk
@@ -30,7 +30,6 @@ else
# back there by the tmpfiles.d mechanism.
define SKELETON_INIT_SYSTEMD_ROOT_RO_OR_RW
echo "/dev/root / auto ro 0 1" >$(TARGET_DIR)/etc/fstab
- echo "tmpfs /var tmpfs mode=1777 0 0" >>$(TARGET_DIR)/etc/fstab
endef
define SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR
@@ -52,6 +51,8 @@ define SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR
|| exit 1; \
fi; \
done >$(TARGET_DIR)/usr/lib/tmpfiles.d/00-buildroot-var.conf
+ $(INSTALL) -D -m 0644 $(SKELETON_INIT_SYSTEMD_PKGDIR)/var.mount \
+ $(TARGET_DIR)/usr/lib/systemd/system/var.mount
endef
SKELETON_INIT_SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR
diff --git a/package/skeleton-init-systemd/var.mount b/package/skeleton-init-systemd/var.mount
new file mode 100644
index 0000000000..e97accef93
--- /dev/null
+++ b/package/skeleton-init-systemd/var.mount
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# Modelled after systemd's tmp.mount
+
+[Unit]
+Description=Buildroot /var tmpfs
+DefaultDependencies=no
+Conflicts=umount.target
+Before=local-fs.target umount.target
+After=swap.target
+
+[Mount]
+What=tmpfs
+Where=/var
+Type=tmpfs
+Options=mode=1777,strictatime,nosuid,nodev,size=50%%,nr_inodes=1m
More information about the buildroot
mailing list