From patchwork Tue Oct 18 19:43:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 1691681 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MsPRz2vhwz23jp for ; Wed, 19 Oct 2022 06:43:43 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F25D940B3A; Tue, 18 Oct 2022 19:43:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org F25D940B3A X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pb3uFZqFbd5T; Tue, 18 Oct 2022 19:43:40 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp2.osuosl.org (Postfix) with ESMTP id 081A1402C3; Tue, 18 Oct 2022 19:43:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 081A1402C3 X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id CD6DA1BF95F for ; Tue, 18 Oct 2022 19:43:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id B4FFD402C3 for ; Tue, 18 Oct 2022 19:43:17 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org B4FFD402C3 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2Pm2HntxAeSl for ; Tue, 18 Oct 2022 19:43:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 7751540111 Received: from relais-inet.orange.com (relais-inet.orange.com [80.12.70.35]) by smtp2.osuosl.org (Postfix) with ESMTPS id 7751540111 for ; Tue, 18 Oct 2022 19:43:16 +0000 (UTC) Received: from opfednr07.francetelecom.fr (unknown [xx.xx.xx.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by opfednr21.francetelecom.fr (ESMTP service) with ESMTPS id 4MsPRQ4mL5z5vtj; Tue, 18 Oct 2022 21:43:14 +0200 (CEST) Received: by tl-lnx-nyma7486 (sSMTP sendmail emulation); Tue, 18 Oct 2022 21:43:12 +0200 From: To: Date: Tue, 18 Oct 2022 21:43:05 +0200 Message-ID: <27491_1666122194_634F01D2_27491_495_1_cf89a104edc507c063e6f4716cc859891b489d27.1666122184.git.yann.morin@orange.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.115.26.52] X-ClientProxiedBy: OPE16NORMBX403.corporate.adroot.infra.ftgroup (10.115.26.16) To OPE16NORMBX305.corporate.adroot.infra.ftgroup (10.115.27.10) X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.com; s=ORANGE001; t=1666122194; bh=j/z9Kj0qKAHwtDz6LYw426triEzjbgilSVnpX3ts4+E=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; b=toEVklcPkq2mpRIasjKs14qVPY25cmA69Nm3W5qCmMFgYebestrsmRkFPSa3z3hsn turDz/fsh6hRzoHrXwQYA7ax8shxPPpr7YybrqU5AlYhTH2H2+p6ZDpVuw1JTizq7B nhTtVzMxB6Tsh04+WDsLTAe+y4v6SG75pwPHzSrmJL9OaUhRgcgq59PAfrA7Skj2vo F1TAY1CzVsPOGdIE1VD4D9UvlvUbXLJQwyyxdlXzjSTwDKpu/ZDcBG/HUemuQ5Cf1j GGbqCTK3L3WT5rxpZdxDjtXe1oesYThyg8cpP05gU3QKlsrs9KHuHITe+habgeUuE5 BconVs/2JOidg== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=orange.com header.i=@orange.com header.a=rsa-sha256 header.s=ORANGE001 header.b=toEVklcP Subject: [Buildroot] [PATCH 2/6 v3] package/skeleton-systemd: systemd-ify mounting /var tmpfs with ro rootfs X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Norbert Lange , yann.morin@orange.com, =?utf-8?q?Je?= =?utf-8?q?=CC=81re=CC=81my_Rosen?= , Romain Naour , "Yann E . MORIN" Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" To mount our /var tmpfs when the rootfs is mounted read-only (really, not remounted reqd-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 ordeting other systemd units until after /var is mounted 5not 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). We add an explicit reverse dependency to systemd-tmpfiles-setup.service, to ensure /var is mounted before we try to populate it. This has two side effects: - as hinted previously, it simplifies writing other systemd units to order them after /var is mounted - 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 --- .../skeleton-init-systemd.mk | 3 ++- package/skeleton-init-systemd/var.mount | 18 ++++++++++++++++++ 2 files changed, 20 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 7b66732ef4..970951d553 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/buildroot-factory.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..6b165dff6d --- /dev/null +++ b/package/skeleton-init-systemd/var.mount @@ -0,0 +1,18 @@ +# 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=basic.target local-fs.target umount.target systemd-tmpfiles-setup.service +After=swap.target + +[Mount] +What=tmpfs +Where=/var +Type=tmpfs +Options=mode=1777,strictatime,nosuid,nodev,size=50%%,nr_inodes=1m + +[Install] +WantedBy=basic.target