From patchwork Sun Jun 3 02:21:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 924662 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=datacom.com.br Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40z1zc6mdnz9s02 for ; Sun, 3 Jun 2018 12:22:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id B48A1228C6; Sun, 3 Jun 2018 02:22:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F76cknPm+voX; Sun, 3 Jun 2018 02:21:58 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 88F4422706; Sun, 3 Jun 2018 02:21:58 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 22E661C0534 for ; Sun, 3 Jun 2018 02:21:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 1E68288589 for ; Sun, 3 Jun 2018 02:21:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1tnTRG0zq5bJ for ; Sun, 3 Jun 2018 02:21:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.datacom.com.br (mx.datacom.ind.br [177.66.5.10]) by whitealder.osuosl.org (Postfix) with ESMTPS id 20613884D3 for ; Sun, 3 Jun 2018 02:21:56 +0000 (UTC) Received: from mail.datacom.com.br (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTPS id 2DB971BA0A46; Sat, 2 Jun 2018 23:22:12 -0300 (-03) Received: from localhost (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTP id 1D0451BA0A2E; Sat, 2 Jun 2018 23:22:12 -0300 (-03) Received: from mail.datacom.com.br ([127.0.0.1]) by localhost (mail.datacom.com.br [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id J42iEaglX5qB; Sat, 2 Jun 2018 23:22:12 -0300 (-03) Received: from p7-1130br.casantos.org (200.175.213.72.dynamic.adsl.gvt.net.br [200.175.213.72]) by mail.datacom.com.br (Postfix) with ESMTPSA id B90121BA0A27; Sat, 2 Jun 2018 23:22:11 -0300 (-03) From: Carlos Santos To: buildroot@buildroot.org Date: Sat, 2 Jun 2018 23:21:45 -0300 Message-Id: <20180603022145.14222-1-casantos@datacom.com.br> X-Mailer: git-send-email 2.17.0 Subject: [Buildroot] [PATCH] fs: allow extra arguments to common tarball extraction X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.24 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas De Schampheleire MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Since commit 118534fe54b (fs: use a common tarball as base for the other filesystems) Buildroot creates a .tar filesystem image and re-extracts it in a private directory to create each format-specific image. Add an option to pass extra arguments to tar when that commom root image is extracted. This option is useful when the root filesystem is volatile (e.g. initrd) or read-only but a read-write subtree is still necessary for persistent data modified by programs as they run. For example, one can pass "--exclude='./var/lib/*'" to exclude that path from the rootfs image and use a post-fakeroot script to make a separate filesystem image for /var/lib. Signed-off-by: Carlos Santos --- Additional explanation This change solves a real-life problem of my current project. Before buildroot 2018.05 I had to use a trickier approach: 1. Add a post-fakeroot script to 1.1. Create a filesystem image (ext4) from $(TARGET_DIR)/var/lib. 1.2. Move $(TARGET_DIR)/var/lib to a backup path under $(BUILD_DIR). 1.3. Create an empty $(TARGET_DIR)/var/lib. 2. Add a post-image script to 2.1. Copy the rootfs and /var/lib images to the disk image. 2.2. Remove the empty $(TARGET_DIR)/var/lib. 2.3. Restore $(TARGET_DIR)/var/lib from the backup path. That solution is fragile: if something goes wrong during the execution of the post-image script it can lead to a cripled $(TARGET_DIR) with an empty var/lib subdir. Rebuilding a package without restoring the backup can easily cause a kaboom and force me to run a lengthy clean build. I added some protection mechanisms to stop the build if a stale /var/lib backup is found but quite frankly the whole thing stinks. The solution with custom extraction arguments, OTOH, is bullet-proof because it does not change $(TARGET_DIR), so it is always safe to run dirty builds. --- docs/manual/customize-rootfs.txt | 10 ++++++++++ fs/Config.in | 13 +++++++++++++ fs/common.mk | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/manual/customize-rootfs.txt b/docs/manual/customize-rootfs.txt index bb6d8da6bf..6dd9365723 100644 --- a/docs/manual/customize-rootfs.txt +++ b/docs/manual/customize-rootfs.txt @@ -121,6 +121,16 @@ This method is not recommended because it duplicates the entire skeleton, which prevents taking advantage of the fixes or improvements brought to the default skeleton in later Buildroot releases. +Rootfs tarball extraction arguments (+BR2_ROOTFS_COMMON_UNTAR_ARGS+):: ++ +Buildroot creates a .tar filesystem image and re-extracts it in a private + directory to create each format-specific image. Use this option to pass + extra arguments to tar when the commom root image is extracted. ++ +For example, you can pass "--exclude=\'./var/lib/*\'" to exclude that path from + the rootfs image and use a post-fakeroot script (see below) to create a + separate filesystem image for '/var/lib'. + Post-fakeroot scripts (+BR2_ROOTFS_POST_FAKEROOT_SCRIPT+):: + When aggregating the final images, some parts of the process requires diff --git a/fs/Config.in b/fs/Config.in index c25b01c3de..74487b1172 100644 --- a/fs/Config.in +++ b/fs/Config.in @@ -1,5 +1,18 @@ menu "Filesystem images" +config BR2_ROOTFS_COMMON_UNTAR_ARGS + string "Rootfs tarball extraction arguments" + help + Buildroot creates a .tar filesystem image and re-extracts it + in a private directory to create each format-specific image. + Use this option to pass extra arguments to tar when the commom + root image is extracted. + + For example, you can pass "--exclude='./var/lib/*'" to exclude + that path from the rootfs image and use a post-fakeroot script + (see BR2_ROOTFS_POST_FAKEROOT_SCRIPT) to create a separate + filesystem image for /var/lib. + source "fs/axfs/Config.in" source "fs/cloop/Config.in" source "fs/cpio/Config.in" diff --git a/fs/common.mk b/fs/common.mk index abf35418cb..33ad1ab2a9 100644 --- a/fs/common.mk +++ b/fs/common.mk @@ -50,9 +50,10 @@ define ROOTFS_COMMON_TAR_CMD endef # Command to extract the common tarball into the per-rootfs target directory +ROOTFS_COMMON_UNTAR_ARGS = $(call qstrip,$(BR2_ROOTFS_COMMON_UNTAR_ARGS)) define ROOTFS_COMMON_UNTAR_CMD mkdir -p $(TARGET_DIR) - tar xf $(ROOTFS_COMMON_TAR) -C $(TARGET_DIR) + tar xf $(ROOTFS_COMMON_TAR) -C $(TARGET_DIR) $(ROOTFS_COMMON_UNTAR_ARGS) endef .PHONY: rootfs-common