From patchwork Mon Jul 4 12:24:08 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: 1651978 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lc4jx2DgGz9sFr for ; Mon, 4 Jul 2022 22:24:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 1F3B460E68; Mon, 4 Jul 2022 12:24:17 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 1F3B460E68 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Kjt-oc8Ti-q1; Mon, 4 Jul 2022 12:24:16 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id D515F60E4E; Mon, 4 Jul 2022 12:24:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org D515F60E4E 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 1DF631BF368 for ; Mon, 4 Jul 2022 12:24:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 058854048C for ; Mon, 4 Jul 2022 12:24:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 058854048C 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 2NUkNDt_XNRH for ; Mon, 4 Jul 2022 12:24:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A5576401A2 Received: from relais-inet.orange.com (relais-inet.orange.com [80.12.70.35]) by smtp2.osuosl.org (Postfix) with ESMTPS id A5576401A2 for ; Mon, 4 Jul 2022 12:24:12 +0000 (UTC) Received: from opfednr01.francetelecom.fr (unknown [xx.xx.xx.65]) (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 opfednr24.francetelecom.fr (ESMTP service) with ESMTPS id 4Lc4jk4Q1Lz1yR8; Mon, 4 Jul 2022 14:24:10 +0200 (CEST) Received: by tl-lnx-nyma7486 (sSMTP sendmail emulation); Mon, 04 Jul 2022 14:24:08 +0200 From: To: Date: Mon, 4 Jul 2022 14:24:08 +0200 Message-ID: <30214_1656937450_62C2DBEA_30214_425_1_ebc1b4a9ba79f014485eb6c21d96956d9ebc3f5d.1656937448.git.yann.morin@orange.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.115.27.53] X-ClientProxiedBy: OPE16NORMBX301.corporate.adroot.infra.ftgroup (10.115.26.10) 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=1656937450; bh=82B+lMN3Gq+YeSjdyip0Nsmf9S2r8Ps4q4Wn6ewaMlE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; b=fo1aPncofMN8RlMhKI7T4kgZjGEGLbcrY+g5q71mMVBQLu6gX+AfE3dLF5cmlptwY aoKfrrb9CSdfFUnHazulGu8LqcmCf21yfm3PND1nJ3p7edsHCFZkP7687ckPz/sHRd QYZPaRGrDt+iy2lu3VHDNCKU+95cuCgir1beNXyljrQ/tyjNPKkhywFXPiygQjumcd dR6m1k096l2a4jVkY/YTbP/EvmKy4ie6u//1YmC/XimzKZp1oC9Mhur2KDA5YpK+sY hr5FzDayCKc2+PuiZJVmuPoPkcjhwYpOgFJuR78+Z9+WymBYgkcN5B+eg5hQ2exXVJ LXI5nrd4qI/xw== 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=fo1aPnco Subject: [Buildroot] [PATCH] package/skeleton-systemd: systemd-ify /var on a read-only 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 E. MORIN" , =?utf-8?q?Je=CC=81re=CC=81my_Rosen?= , Romain Naour Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" From: "Yann E. MORIN" When the rootfs is not remounted read-write (thus assuming a read-only rootfs like squashfs), we create a tmpfiles.d factory for /var. However, we register those in /etc/tmpfiles.d/, but /etc could also be a tmpfs (for full state-less systems, or easy factory-reset, see [0]). So, we move our var factory to /usr/lib/tmpfiles.d/, which is also the lcoation where systemd itself places its own tmpfiles, and where we already put all our other tmpfiles (see audit, avahi, cryptsetup, dhcp, lighttpd, nfs-utils, quagga, samba4, swupdate) and our handling of systemd's catalog files too. We also rename the file to a better name, so that it is obvious it is generated by us (systemd already installs a var.conf of its own, so we want to avoid name clashing). Additionally, since /etc may be empty, we might not have an fstab available to actually mount /var as a tmpfs. So, we register /var as aa systemd mount, 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. Even though we could have split the two changes in two patches, one for moving the tmpfiles unit away from /etc, and one for adding a systemd mount unit, the two really make sense together as part of having an empty /etc, so we made that a single change. [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 --- .../skeleton-init-systemd.mk | 7 ++++--- package/skeleton-init-systemd/var.mount | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) 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 795a171809..970951d553 100644 --- a/package/skeleton-init-systemd/skeleton-init-systemd.mk +++ b/package/skeleton-init-systemd/skeleton-init-systemd.mk @@ -29,15 +29,14 @@ else # a real (but empty) directory, and the "factory files" will be copied # back there by the tmpfiles.d mechanism. define SKELETON_INIT_SYSTEMD_ROOT_RO_OR_RW - mkdir -p $(TARGET_DIR)/etc/systemd/tmpfiles.d 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 rm -rf $(TARGET_DIR)/usr/share/factory/var mv $(TARGET_DIR)/var $(TARGET_DIR)/usr/share/factory/var mkdir -p $(TARGET_DIR)/var + mkdir -p $(TARGET_DIR)/usr/lib/tmpfiles.d for i in $(TARGET_DIR)/usr/share/factory/var/* \ $(TARGET_DIR)/usr/share/factory/var/lib/* \ $(TARGET_DIR)/usr/share/factory/var/lib/systemd/*; do \ @@ -51,7 +50,9 @@ define SKELETON_INIT_SYSTEMD_PRE_ROOTFS_VAR printf "C! %s - - - -\n" "$${j}" \ || exit 1; \ fi; \ - done >$(TARGET_DIR)/etc/tmpfiles.d/var-factory.conf + 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