From 8cbfbe487ac6fb00c037475ed8aaca3d89899769 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Tue, 18 Oct 2022 21:43:05 +0200 Subject: [PATCH] package/skeleton-systemd: systemd-ify mounting /var tmpfs with ro rootfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Norbert Lange Cc: Romain Naour Cc: Jérémy Rosen [yann.morin.1998@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 Reviewed-by: Norbert Lange [yann.morin.1998@free.fr (as suggested by Norbert): - fix Before= dependencies - drop [Install] section ] Signed-off-by: Yann E. MORIN --- .../skeleton-init-systemd.mk | 3 ++- package/skeleton-init-systemd/var.mount | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 package/skeleton-init-systemd/var.mount 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