From patchwork Sun Jan 15 12:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Norbert Lange X-Patchwork-Id: 1726704 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.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nvw8C4dzXz23g1 for ; Sun, 15 Jan 2023 23:54:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E98466059A; Sun, 15 Jan 2023 12:54:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org E98466059A 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 PFNNkx-GncET; Sun, 15 Jan 2023 12:54:01 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 1337761194; Sun, 15 Jan 2023 12:54:00 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 1337761194 X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id D24261BF29D for ; Sun, 15 Jan 2023 12:53:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B632D415DF for ; Sun, 15 Jan 2023 12:53:11 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B632D415DF X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7msb1pN9i6Sw for ; Sun, 15 Jan 2023 12:53:10 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 341BF4167D Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by smtp4.osuosl.org (Postfix) with ESMTPS id 341BF4167D for ; Sun, 15 Jan 2023 12:53:10 +0000 (UTC) Received: by mail-ej1-x62f.google.com with SMTP id qx13so3896041ejb.13 for ; Sun, 15 Jan 2023 04:53:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mk5A43aGuSWnzp3jC3JgZ4eZkg6iZJt7fFF/rxhysdE=; b=XEd8uoPXLe68Hc4hntkRT+tyHdgfIlvfxvatekS1dlSLdzN6KtxpdwMIRcOl93IR5D wlECf+DzASykAIlTGooZAQ10EVjmaQgHwAoIRRrxL0dA07kziyCYJw+eIuPyiteIOSoU CCuYy2w1lyuuZpW+am1zgtRzQtK5GiYF5zl/5Zl4htJx/NPBHQprv6iEV84I55h21XD6 o3piJWzFZVsVFLhqWKxN7tASL0Yraq9JYDpv2NE/3zDZCeYyXZ/YGVYUe4bWus15ipkb /TiE2gkMPqoF8eGZD8R4bsTelwOMbI/a3hCWHg56DWOzNtP6qrgzx2gTg1NBopN2i00T t7Sw== X-Gm-Message-State: AFqh2kodAOl29Hy/8PYE9awa1+BdVPAgHA5jT++vMDfvwZlZ+USUQssq i1XSCt0KtTAG56BwWg+CeTNkKaPS8Sw= X-Google-Smtp-Source: AMrXdXsiJbdsd++SfeYI/qLCRWUPI0+5zP1o11aHeuKiBjhSuISejPW3x7er34shKFg6kISMI7aSGg== X-Received: by 2002:a17:907:674e:b0:78d:f455:b5d4 with SMTP id qm14-20020a170907674e00b0078df455b5d4mr14549387ejc.20.1673787189761; Sun, 15 Jan 2023 04:53:09 -0800 (PST) Received: from debian-noppl.. (84-113-221-34.cable.dynamic.surfer.at. [84.113.221.34]) by smtp.gmail.com with ESMTPSA id r18-20020a1709061bb200b0084cd08e5cb5sm10581673ejg.159.2023.01.15.04.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 04:53:09 -0800 (PST) From: Norbert Lange To: buildroot@buildroot.org Date: Sun, 15 Jan 2023 13:52:49 +0100 Message-Id: <20230115125253.280257-5-nolange79@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230115125253.280257-1-nolange79@gmail.com> References: <20230115125253.280257-1-nolange79@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Mk5A43aGuSWnzp3jC3JgZ4eZkg6iZJt7fFF/rxhysdE=; b=COlgYZeHRhiiDT1Xh1TprR1NnXNkMpnOgMquMAVxC+ppASIkvgTveq6bXJuXKQM+qX gqiavqPaCT0PbjCpnr/6P6rMgwuLBe118oAFxr79yVbl/iQeYoNH1iNj19AsJJmBjz7a UezDZhduI5oEdQqSv/2TfxO/W6eKwzeNlkCO/UbtZO+GmXo9uUyNmwVpNPERZp8Pxbfy 8QUz5PsKPwuJATMWfMQuE71NWM1zgB//2pOcMb9JjmyILlemzUhaDbH7/6ZdzzFpiM1h 2B9UZ7gslFwevRzSq/wSqGJpD7Mdsh3JRihJUk9Qz9dGZpjpQZBarXpFebkSm1Vruj6Q Th/Q== X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=COlgYZeH Subject: [Buildroot] [PATCH 4/7] system: add systemd generator for /var 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 , =?utf-8?q?Je=CC=81re=CC=81my_Rosen?= , "Yann E . MORIN" , Romain Naour Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" This commit adds an alternative that has the following characteristics: - Dont depend on anything being available, except the API File Systems [1]. - Be a clean drop-in, that can be trivially added / removed. - Runs before systemd loads its configuration. Could be extended to handle more tricky paths like /etc. For more explaination, see the commit introducing the overlay method. The implementation doesnt focus on being expandable but simple, in the future there could be an attempt to source shell scripts for configuration. So that multiple paths can be covered (/etc), or the mounts and handling specified (do-nothing, copy-over or overlay original contents). The intent is to have a direct replacement for the var factory method. [1] - https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems/ Cc: Yann E. MORIN Cc: Romain Naour Cc: Jérémy Rosen Signed-off-by: Norbert Lange --- .../generator/br-mount-generator | 19 +++++++++++++++++++ .../skeleton-init-systemd.mk | 10 +++++++++- system/Config.in | 13 +++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 package/skeleton-init-systemd/generator/br-mount-generator diff --git a/package/skeleton-init-systemd/generator/br-mount-generator b/package/skeleton-init-systemd/generator/br-mount-generator new file mode 100755 index 0000000000..fd10659c1c --- /dev/null +++ b/package/skeleton-init-systemd/generator/br-mount-generator @@ -0,0 +1,19 @@ +#!/bin/sh +set -e +# SPDX-License-Identifier: MIT +# Note: doing heavy stuff here is not recommended, but this way +# the ordering is guaranteed. Be quick about everything. +# Know that the generator can be run again later. + +[ "${SYSTEMD_IN_INITRD-0}" = 1 ] && exit +grep '^tmpfs_br_var /var tmpfs' /proc/self/mounts >/dev/null && exit + +TMPMOUNT=/run/.br/.tmpvar +trap "umount -l $TMPMOUNT || :; rmdir $TMPMOUNT || :" 0 + +mkdir -m755 -p $TMPMOUNT +mount -n -t tmpfs -o nosuid,nodev,size=50% tmpfs_br_var $TMPMOUNT + +cp -r -p /var/. $TMPMOUNT +# this is a shared mount so --move wont work +mount -n --bind $TMPMOUNT /var diff --git a/package/skeleton-init-systemd/skeleton-init-systemd.mk b/package/skeleton-init-systemd/skeleton-init-systemd.mk index f431ec4612..b9b8492f58 100644 --- a/package/skeleton-init-systemd/skeleton-init-systemd.mk +++ b/package/skeleton-init-systemd/skeleton-init-systemd.mk @@ -69,11 +69,19 @@ define SKELETON_INIT_SYSTEMD_POST_INSTALL_VAR_OVERLAYFS $(TARGET_DIR)/usr/lib/systemd/system/br-bindmount-run@.service $(INSTALL) -D -m 0644 $(SKELETON_INIT_SYSTEMD_PKGDIR)/overlayfs/br-overlay-prepare@.service \ $(TARGET_DIR)/usr/lib/systemd/system/br-overlay-prepare@.service - # /var mount gets pulled in automatically by basic.target + # var.mount gets pulled in automatically by basic.target endef SKELETON_INIT_SYSTEMD_POST_INSTALL_TARGET_HOOKS += SKELETON_INIT_SYSTEMD_POST_INSTALL_VAR_OVERLAYFS endif # BR2_INIT_SYSTEMD_VAR_OVERLAYFS +ifeq ($(BR2_INIT_SYSTEMD_VAR_GENERATOR),y) +define SKELETON_INIT_SYSTEMD_POST_INSTALL_VAR_GENERATOR + $(INSTALL) -D -m 0755 $(SKELETON_INIT_SYSTEMD_PKGDIR)/generator/br-mount-generator \ + $(TARGET_DIR)/usr/lib/systemd/system-generators/br-var-mount-generator +endef +SKELETON_INIT_SYSTEMD_POST_INSTALL_TARGET_HOOKS += SKELETON_INIT_SYSTEMD_POST_INSTALL_VAR_GENERATOR +endif # BR2_INIT_SYSTEMD_VAR_GENERATOR + endif # BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW ifeq ($(BR2_INIT_SYSTEMD_POPULATE_TMPFILES),y) diff --git a/system/Config.in b/system/Config.in index cdf383d0d4..14fefbf283 100644 --- a/system/Config.in +++ b/system/Config.in @@ -200,6 +200,19 @@ config BR2_INIT_SYSTEMD_VAR_OVERLAYFS ExecStart= ExecStart=/bin/mount --make-private -n /dev/sdc1 ${OVERLAY_DIR} +config BR2_INIT_SYSTEMD_VAR_GENERATOR + bool "use a systemd generator to mount and populate a tmpfs" + help + Mount an tmpfs on /var, with the the original contents copied. + + The logic is contained in a systemd generator, to ensure this + is done early and ordered before anything can access /var. + + Unlike the var factory, nothing needs to be prepared and + the populating happens before any unit accesses /var. + + Unlike the var factory, it does not need an overlayfs. + config BR2_INIT_SYSTEMD_VAR_NONE bool "do nothing" help