All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH next v5 1/3] package/dracut: new host package
@ 2022-08-15 11:17 Arnout Vandecappelle (Essensium/Mind)
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool Arnout Vandecappelle (Essensium/Mind)
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Arnout Vandecappelle (Essensium/Mind) @ 2022-08-15 11:17 UTC (permalink / raw)
  To: buildroot; +Cc: Thierry Bultel, Adam Duskett

From: Thierry Bultel <thierry.bultel@linatsea.fr>

Dracut is the tool used by desktop distributions to build initrds.

In the embedded world, it can be very useful, too, for instance when
wanting to create an initramfs for a system recovery mode.
Whereas it is definitively possible to achieve this with buildroot, the
process is to have a dedicated buildroot configuration for that, and
perform a full build. Instead of doing that, dracut can pick the needed
binaries/shared libraries, configuration files, or kernel modules from
the 'target' directory.
The advantage is to save build time, and also to have a consistency
between the packages versions taken for the recovery and the production
filesystem.

The principle of dracut is based on the so-called 'dracut modules'. The
modules determine what will be included in the initramfs. For example,
one of dracut's modules checks the kernel modules that are included and
also includes the corresponding firmware blobs.
On the host, they are on host/lib/dracut/modules.d
Each directory as a prefix number for the order of execution, and
at least a "module-setup.sh" script.

Dracut sources all of them, and typically calls the "check()" function,
which is the placeholder for required binaries (that are aimed to be
polulated in the initrd), then the "depends()" function, that lists
other modules to depend on, and the "install()" function, that makes
the actual work.

Dracut was initially thought to work with systems using systemd,
but it can also work without it. Do to so, every "systemd-xxx"
module must be disabled in the dracut configuration file. For
convenience, the 05busybox-init module is provided, to support
busybox init system. Note that this module should *not* be enabled when
using systemd init. It is therefore only installed if busybox init is
selected.

Musl and uClibc make assumptions about the existence of some symlinks
that are not discoverable with readelf. Therefore, another module
05libc-links is provided that creates those links. The module is
installed regardless of which libc is used - the script itself discovers
if the links need to be installed based on which libc is found.

Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Cc: Adam Duskett <aduskett@gmail.com>
---
Changes v1 -> v2 (all suggested by Arnout)
  - added a wrapper script
Changes v2 -> v3
  - added modules for:
     - supporting busybox system init type
     - fixing a missing symlink for uClibc
Changes v3 -> v4
  - some explanations on the dracut modules in the commit log
  - fixed a bug on the 'require_binary' line in busybox module
  - expanded variables with double quotes and curly braces
  - removed commented out code
  - fixes for 'fakeroot' and 'uclibc' and 'musl' as patches
  - musl and uclibc dynamic fix
  - renamed dracut wrapper
  - disabled when using another init system than systemd or busybox
Changes v4 -> v5
  - add hash file;
  - add DEVELOPERS entries;
  - replace patch 0001 with an intree file and copy in post-install;
  - properly format patch 0000, add signoff, rename to 0001;
  - rename busybox-buildroot to busybox-init;
  - correct the symlink creation for musl and uclibc;
  - remove directory part from the extra modules;
  - remove unused dracut script (identical to dracut_wrapper);
  - switch to prelink-cross instead of cross-ldd;
  - make dracut_wrapper script relocatable;
  - don't set sysroot in wrapper script, expect it to be passed as
    --sysroot argument;
  - call the wrapper script bin/dracut instead of sbin/dracut, and
    rename the original to dracut.real;
  - fix shellcheck warnings in the module scripts.
---
 DEVELOPERS                                    |  2 +
 package/Config.in.host                        |  1 +
 ...001-dracut.sh-don-t-unset-LD_PRELOAD.patch | 29 +++++++++
 package/dracut/Config.in.host                 |  9 +++
 package/dracut/busybox-init-module-setup.sh   | 62 +++++++++++++++++++
 package/dracut/dracut.hash                    |  3 +
 package/dracut/dracut.mk                      | 47 ++++++++++++++
 package/dracut/dracut_wrapper.sh              | 33 ++++++++++
 package/dracut/libc-links-module-setup.sh     | 27 ++++++++
 9 files changed, 213 insertions(+)
 create mode 100644 package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
 create mode 100644 package/dracut/Config.in.host
 create mode 100644 package/dracut/busybox-init-module-setup.sh
 create mode 100644 package/dracut/dracut.hash
 create mode 100644 package/dracut/dracut.mk
 create mode 100644 package/dracut/dracut_wrapper.sh
 create mode 100755 package/dracut/libc-links-module-setup.sh

diff --git a/DEVELOPERS b/DEVELOPERS
index d2bd0d809a..4287fd9cf7 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -225,6 +225,7 @@ F:	package/espeak/
 N:	Arnout Vandecappelle <arnout@mind.be>
 F:	package/arp-scan/
 F:	package/dehydrated/
+F:	package/dracut/
 F:	package/freescale-imx/firmware-imx/
 F:	package/freescale-imx/imx-lib/
 F:	package/libpagekite/
@@ -2796,6 +2797,7 @@ F:	configs/beagleboardx15_defconfig
 F:	package/pugixml/
 
 N:	Thierry Bultel <tbultel@free.fr>
+F:	package/dracut/
 F:	package/mpd-mpc/
 
 N:	Thijs Vermeir <thijsvermeir@gmail.com>
diff --git a/package/Config.in.host b/package/Config.in.host
index 99edeafece..f437ef680c 100644
--- a/package/Config.in.host
+++ b/package/Config.in.host
@@ -19,6 +19,7 @@ menu "Host utilities"
 	source "package/dos2unix/Config.in.host"
 	source "package/dosfstools/Config.in.host"
 	source "package/doxygen/Config.in.host"
+	source "package/dracut/Config.in.host"
 	source "package/dtc/Config.in.host"
 	source "package/e2fsprogs/Config.in.host"
 	source "package/e2tools/Config.in.host"
diff --git a/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
new file mode 100644
index 0000000000..87083d2cef
--- /dev/null
+++ b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
@@ -0,0 +1,29 @@
+From bb12f15856911d8532b569116da7dab4cbf107be Mon Sep 17 00:00:00 2001
+From: Thierry Bultel <thierry.bultel@linatsea.fr>
+Date: Mon, 10 Jan 2022 09:09:43 +0100
+Subject: [PATCH] dracut.sh: don't unset LD_PRELOAD
+
+LD_PRELOAD is needed to run under fakeroot.
+
+Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
+Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
+---
+ dracut.sh | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/dracut.sh b/dracut.sh
+index 60ac46f4..37f25b38 100755
+--- a/dracut.sh
++++ b/dracut.sh
+@@ -868,8 +868,6 @@ export LC_ALL=C
+ export LANG=C
+ unset LC_MESSAGES
+ unset LC_CTYPE
+-unset LD_LIBRARY_PATH
+-unset LD_PRELOAD
+ unset GREP_OPTIONS
+ 
+ export DRACUT_LOG_LEVEL=warning
+-- 
+2.37.1
+
diff --git a/package/dracut/Config.in.host b/package/dracut/Config.in.host
new file mode 100644
index 0000000000..18f562b310
--- /dev/null
+++ b/package/dracut/Config.in.host
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_HOST_DRACUT
+	bool
+	select BR2_PACKAGE_HOST_KMOD
+	help
+	  dracut is used to create an initramfs image by
+	  copying tools and files from an installed system
+	  and combining it with the dracut framework.
+
+	  https://dracut.wiki.kernel.org
diff --git a/package/dracut/busybox-init-module-setup.sh b/package/dracut/busybox-init-module-setup.sh
new file mode 100644
index 0000000000..2667f866d1
--- /dev/null
+++ b/package/dracut/busybox-init-module-setup.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+check() {
+	require_binaries busybox || return 1
+	return 0
+}
+
+depends() {
+	return 0
+}
+
+install_busybox_links() {
+	dir=$1
+	linkname=$2
+
+	(cd "${dracutsysrootdir?}${dir}" &&
+	for x in *; do
+		if [ "$(readlink "$x")" = "${linkname}" ]; then
+			ln -sf "${linkname}" "${initdir?}/${dir}/$x"
+		fi
+	done
+	)
+}
+
+install() {
+	inst_multiple /bin/busybox
+
+	# wrapper script for early console; will launch /sbin/init
+	# after having mounted devtmpfs
+	inst_multiple /init
+
+	ln -s ../bin/busybox "${initdir?}"/sbin/init
+
+	if [ -e "${dracutsysrootdir?}/lib64" ]; then
+		ln -sf lib "${initdir?}/lib64"
+		ln -sf lib "${initdir?}/usr/lib64"
+	fi
+
+	if [ -e "${dracutsysrootdir?}/lib32" ]; then
+		ln -sf lib "${initdir?}/lib32"
+		ln -sf lib "${initdir?}/usr/lib32"
+	fi
+
+	install_busybox_links "/bin" "busybox"
+	install_busybox_links "/sbin" "../bin/busybox"
+	if [ ! -L /bin ]; then
+		install_busybox_links "/usr/bin" "../../bin/busybox"
+		install_busybox_links "/usr/sbin" "../../bin/busybox"
+	fi
+
+	inst_multiple \
+		/etc/inittab	\
+		/etc/init.d/rcS \
+		/etc/init.d/rcK \
+		/etc/issue	\
+		/etc/fstab	\
+		/etc/group	\
+		/etc/passwd	\
+		/etc/shadow	\
+		/etc/hostname
+}
+
diff --git a/package/dracut/dracut.hash b/package/dracut/dracut.hash
new file mode 100644
index 0000000000..3cda736856
--- /dev/null
+++ b/package/dracut/dracut.hash
@@ -0,0 +1,3 @@
+# Locally computed
+sha256  4baa08206cceeb124dbf1075a0daf774b5a8f144ce2e01d82a144af3020fd65b  dracut-055.tar.xz
+sha256  8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643  COPYING
diff --git a/package/dracut/dracut.mk b/package/dracut/dracut.mk
new file mode 100644
index 0000000000..7afec80c0e
--- /dev/null
+++ b/package/dracut/dracut.mk
@@ -0,0 +1,47 @@
+################################################################################
+#
+# dracut
+#
+################################################################################
+
+DRACUT_VERSION = 055
+DRACUT_SOURCE = dracut-$(DRACUT_VERSION).tar.xz
+DRACUT_SITE = $(BR2_KERNEL_MIRROR)/linux/utils/boot/dracut
+DRACUT_LICENSE = GPL-2.0
+DRACUT_LICENSE_FILES = COPYING
+
+HOST_DRACUT_DEPENDENCIES = host-pkgconf host-kmod host-prelink-cross
+
+define HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
+	mv $(HOST_DIR)/bin/dracut $(HOST_DIR)/bin/dracut.real
+	install -D -m 0755 $(HOST_DRACUT_PKGDIR)/dracut_wrapper.sh $(HOST_DIR)/bin/dracut
+endef
+HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
+
+# When using uClibc or musl, there must be "ls-uClibc.so.1" or
+# "ld-musl-x.so" symlinks, respectively - else the init process cannot
+# start
+define HOST_DRACUT_POST_INSTALL_LIBC_LINKS_MODULE
+	$(INSTALL) -D -m 0755 package/dracut/libc-links-module-setup.sh \
+		$(HOST_DIR)/lib/dracut/modules.d/05libc-links/module-setup.sh
+endef
+HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_LIBC_LINKS_MODULE
+
+ifeq ($(BR2_INIT_BUSYBOX),y)
+# Dracut does not support busybox init (systemd init is assumed to work
+# out of the box, though). It provides a busybox module, that does not
+# use the same paths as buildroot, and is not meant to be used as an init
+# system.
+# So it is simpler for users to disable the standard 'busybox' module in
+# the configuration file, and enable the "busybox-init' module instead.
+# Note that setting the script as executable (0755) is not mandatory,
+# but this is what dracut does on all its modules, so lets just conform
+# to it.
+define HOST_DRACUT_POST_INSTALL_BUSYBOX_INIT_MODULE
+	$(INSTALL) -D -m 0755 package/dracut/busybox-init-module-setup.sh \
+		$(HOST_DIR)/lib/dracut/modules.d/05busybox-init/module-setup.sh
+endef
+HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_BUSYBOX_INIT_MODULE
+endif
+
+$(eval $(host-autotools-package))
diff --git a/package/dracut/dracut_wrapper.sh b/package/dracut/dracut_wrapper.sh
new file mode 100644
index 0000000000..3f58b0907e
--- /dev/null
+++ b/package/dracut/dracut_wrapper.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+set -e
+
+# Find the --sysroot argument
+sysroot=
+next_arg=
+for arg; do
+	if [ "$next_arg" = 1 ]; then
+		next_arg=
+		sysroot="$arg"
+		continue
+	fi
+
+	case "$arg" in
+	--sysroot=*)
+		sysroot="${arg#*=}"
+		;;
+	--sysroot)
+		next_arg=1
+		;;
+	esac
+done
+if [ -z "$sysroot" ]; then
+	echo "$0: --sysroot argument must be given." 1>&2
+	exit 1
+fi
+
+topdir="$(dirname "$(realpath "$(dirname "$0")")")"
+export DRACUT_LDD="$topdir/sbin/prelink-rtld --root='${sysroot}'"
+export DRACUT_INSTALL="$topdir/lib/dracut/dracut-install"
+export DRACUT_LDCONFIG=/bin/true
+export dracutbasedir="$topdir/lib/dracut"
+exec "$topdir/bin/dracut.real" "$@"
diff --git a/package/dracut/libc-links-module-setup.sh b/package/dracut/libc-links-module-setup.sh
new file mode 100755
index 0000000000..e15b216e6e
--- /dev/null
+++ b/package/dracut/libc-links-module-setup.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Adds the missing links for uClibc or musl, if needed
+
+check() {
+	return 0
+}
+
+depends() {
+	return 0
+}
+
+install() {
+	# Despite of the fact that the listed dependency (reported by readelf -d)
+	# is purely /lib/libc.so, the musl symlink is needed anyway.
+	musl_link="$(find "${dracutsysrootdir?}/lib" -name "ld-musl-*.so*")"
+	if [ -n "$musl_link" ] ; then
+		ln -s libc.so "${initdir?}/lib/$(basename "${musl_link}")"
+	fi
+
+	# Same for uClibc, the listed dependency
+	# is ld-uClibc.so.1, the loader needs the ld-uClibc.so.0, too
+	uclibc_link="$(find "${dracutsysrootdir?}/lib" -name "ld-uClibc-*.so*")"
+	if [ -n "$uclibc_link" ] ; then
+		ln -s ld-uClibc.so.1 "${initdir?s}/lib/ld-uClibc.so.0"
+	fi
+}
-- 
2.37.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool
  2022-08-15 11:17 [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Arnout Vandecappelle (Essensium/Mind)
@ 2022-08-15 11:17 ` Arnout Vandecappelle (Essensium/Mind)
  2022-08-15 13:05   ` Yann E. MORIN
  2022-08-18 21:09   ` Yann E. MORIN
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 3/3] support/testing/tests/fs/test_cpio.py: new runtime test Arnout Vandecappelle (Essensium/Mind)
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Arnout Vandecappelle (Essensium/Mind) @ 2022-08-15 11:17 UTC (permalink / raw)
  To: buildroot; +Cc: Thierry Bultel, Adam Duskett

From: Thierry Bultel <thierry.bultel@linatsea.fr>

Adds an option to invoke the dracut host tool, providing
a configuration file, instead of having a full cpio archive
of the whole target directory.

A default configuration file is provided. It assumes busybox init.
ideally, a different default should be used in case of systemd init, but
that's left for future work.

Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
Changes v1 -> v2 (suggested by Arnout and Yann)
  - was a new fs type, now an option of cpio
  - deals with the case of a build with no kernel
  - gets the kernel name in a smarter way
  - checks for the name of dracut configuration file
Changes v2 -> v3
  - fixed a typo on the --no-kernel option for dracut
  - removed the unneeded dependency to kernel
  - added tests for cpio, for both full, and dracut modes
Changes v3 -> v4
  - Config.in: applied Yann's comments on syntax and option in choice
  - do no export TARGET_CROSS but give it in command line instead
  - use $(ROOTFS_CPIO_DIR) as base for tmp directory
  - let original, full cpio, first in the code, and dracut mode after
  - removed unwanted comment in dracut.conf (in tests)
Changes v4 -> v5 (Arnout)
  - move runtime test to separate patch;
  - fix check-package errors;
  - add default dracut.conf file, the one from the runtime test;
  - remove bash from dracut.conf;
  - remove dependency on busybox or systemd init;
  - add help text to BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE;
  - use our compression instead of dracut's;
  - still allow uimage;
  - add --sysroot option in dracut call;
  - adapt paths and environment according to changes in previous commit;
  - use : instead of . to separate ifeq conditions;
  - add support for reproducible (shared with cpio);
  - use ROOTFS_CPIO_OPTS instead of ROOTFS_CPIO_DRACUT_CMD_OPTS;
  - remove --keep option, isn't needed.
---
 fs/cpio/Config.in   | 34 +++++++++++++++++
 fs/cpio/cpio.mk     | 33 ++++++++++++++++
 fs/cpio/dracut.conf | 93 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
 create mode 100644 fs/cpio/dracut.conf

diff --git a/fs/cpio/Config.in b/fs/cpio/Config.in
index c1151a2881..de83aaad65 100644
--- a/fs/cpio/Config.in
+++ b/fs/cpio/Config.in
@@ -7,6 +7,40 @@ config BR2_TARGET_ROOTFS_CPIO
 
 if BR2_TARGET_ROOTFS_CPIO
 
+choice
+	prompt "cpio type"
+	default BR2_TARGET_ROOTFS_CPIO_FULL
+
+config BR2_TARGET_ROOTFS_CPIO_FULL
+	bool "cpio the whole root filesystem"
+	help
+	  Build a cpio archive containing the whole the root filesystem.
+
+config BR2_TARGET_ROOTFS_CPIO_DRACUT
+	bool "Invoke dracut to make a partial initramfs"
+	select BR2_PACKAGE_HOST_DRACUT
+	select BR2_PACKAGE_HOST_UBOOT_TOOLS
+	help
+	  Build an additional initramfs using dracut. This only contains
+	  a subset of the rootfs, as determined by the configuration
+	  file.
+	  This can be useful to create a recovery system, for instance.
+
+endchoice
+
+if BR2_TARGET_ROOTFS_CPIO_DRACUT
+config BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE
+	string "dracut configuration file"
+	default "fs/cpio/dracut.conf"
+	help
+	  Dracut configuration file. It determines which parts of the
+	  rootfs get included in the cpio image. See dracut.conf(5) or
+	  https://github.com/dracutdevs/dracut/blob/master/man/dracut.conf.5.asc
+
+	  The default configuration file is suitable for busybox init.
+	  It doesn't, however, pivot_root into a full rootfs.
+endif
+
 choice
 	prompt "Compression method"
 	default BR2_TARGET_ROOTFS_CPIO_NONE
diff --git a/fs/cpio/cpio.mk b/fs/cpio/cpio.mk
index 81f8c393d1..b62d804ad8 100644
--- a/fs/cpio/cpio.mk
+++ b/fs/cpio/cpio.mk
@@ -36,6 +36,8 @@ ROOTFS_CPIO_DEPENDENCIES += host-cpio
 ROOTFS_CPIO_OPTS += --reproducible
 endif
 
+ifeq ($(BR2_TARGET_ROOTFS_CPIO_FULL),y)
+
 define ROOTFS_CPIO_CMD
 	cd $(TARGET_DIR) && \
 	find . \
@@ -44,6 +46,37 @@ define ROOTFS_CPIO_CMD
 	> $@
 endef
 
+else ifeq ($(BR2_TARGET_ROOTFS_CPIO_DRACUT),y)
+
+ROOTFS_CPIO_DEPENDENCIES += host-dracut
+
+ifeq ($(BR_BUILDING):$(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE),y:)
+$(error No dracut config file name specified, check your BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE setting)
+endif
+
+ifeq ($(BR2_LINUX_KERNEL),y)
+ROOTFS_CPIO_DEPENDENCIES += linux
+ROOTFS_CPIO_OPTS += --kver $(LINUX_VERSION_PROBED)
+else
+ROOTFS_CPIO_OPTS += --no-kernel
+endif
+
+define ROOTFS_CPIO_CMD
+	mkdir -p $(ROOTFS_CPIO_DIR)/tmp
+
+	$(HOST_DIR)/bin/dracut \
+		$(ROOTFS_CPIO_OPTS) \
+		-c $(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE) \
+		--sysroot $(TARGET_DIR) \
+		--tmpdir $(ROOTFS_CPIO_DIR)/tmp \
+		-M \
+		--force \
+		--no-compress \
+		$@
+endef
+
+endif #BR2_TARGET_ROOTFS_CPIO_DRACUT
+
 ifeq ($(BR2_TARGET_ROOTFS_CPIO_UIMAGE),y)
 ROOTFS_CPIO_DEPENDENCIES += host-uboot-tools
 define ROOTFS_CPIO_UBOOT_MKIMAGE
diff --git a/fs/cpio/dracut.conf b/fs/cpio/dracut.conf
new file mode 100644
index 0000000000..6184457723
--- /dev/null
+++ b/fs/cpio/dracut.conf
@@ -0,0 +1,93 @@
+#Simple dracut config for a system without systemd
+
+#Dracut configuration
+
+show_modules=yes
+i18n_install_all=no
+lvmconf=no
+mdadmconf=no
+early_microcode=no
+hostonly=no
+hostonly_cmdline=no
+use_fstab=no
+kernel_cmdline="rd.break=initqueue"
+do_strip=no
+
+# Dracut modules needed
+add_dracutmodules+=" \
+busybox-init
+"
+
+# Modules to ignore
+omit_dracutmodules+=" \
+bash \
+biosdevname \
+btrfs \
+bluetooth \
+busybox \
+caps \
+cifs \
+crypt \
+crypt-gpg \
+dash \
+dbus-broker \
+dbus-daemon \
+dm \
+dmraid \
+dmsquash-live-ntfs \
+dracut-systemd \
+fcoe \
+fcoe-uefi \
+fs-lib \
+iscsi \
+i18n \
+lvmmerge \
+lvm \
+lunmask \
+mdraid \
+memstrack \
+mksh \
+modsign \
+mount-root \
+multipath \
+nbd \
+network-legacy \
+network-wicked \
+nfs \
+nvdimm \
+nvmf \
+parse-lunmask \
+qemu \
+qemu-net \
+resume \
+rootfs-block \
+rngd \
+systemd \
+systemd-udevd \
+systemd-coredump \
+systemd-ask-password \
+systemd-timedated \
+systemd-rfkill \
+systemd-resolved \
+systemd-hostnamed \
+systemd-initrd \
+systemd-journald \
+systemd-ldconfig \
+systemd-networkd \
+systemd-timesyncd \
+systemd-veritysetup \
+systemd-modules-load \
+systemd-sysctl \
+systemd-repart \
+systemd-sysext \
+systemd-sysusers \
+systemd-tmpfiles \
+squash \
+ssh-client \
+stratis \
+tpm2-tss \
+udev-rules \
+url-lib \
+usrmount \
+"
+
-- 
2.37.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Buildroot] [PATCH next v5 3/3] support/testing/tests/fs/test_cpio.py: new runtime test
  2022-08-15 11:17 [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Arnout Vandecappelle (Essensium/Mind)
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool Arnout Vandecappelle (Essensium/Mind)
@ 2022-08-15 11:17 ` Arnout Vandecappelle (Essensium/Mind)
  2022-08-18 21:10   ` Yann E. MORIN
  2022-08-15 12:36 ` [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Yann E. MORIN
  2022-08-18 21:09 ` Yann E. MORIN
  3 siblings, 1 reply; 10+ messages in thread
From: Arnout Vandecappelle (Essensium/Mind) @ 2022-08-15 11:17 UTC (permalink / raw)
  To: buildroot; +Cc: Thierry Bultel, Adam Duskett

From: Thierry Bultel <thierry.bultel@linatsea.fr>

It includes a simple test for the full cpio image, and a test of the
dracut image. To validate that the dracut image is a subset of the full
image, 'pv' is added to the image, and the test verifies that pv is not
part of the image. Note that the real rootfs is not mounted at the
moment, so pv is never available in the running image.

Systemd and other init systems are currently untested.

Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
Changes v4 -> v5 (Arnout)
  - move runtime test to separate patch;
  - add tests for all libcs;
  - remove tar;
  - add pv and test that it's not included in cpio.
---
 support/testing/tests/fs/test_cpio.py | 93 +++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)
 create mode 100644 support/testing/tests/fs/test_cpio.py

diff --git a/support/testing/tests/fs/test_cpio.py b/support/testing/tests/fs/test_cpio.py
new file mode 100644
index 0000000000..98620ebc06
--- /dev/null
+++ b/support/testing/tests/fs/test_cpio.py
@@ -0,0 +1,93 @@
+import os
+import infra.basetest
+import subprocess
+
+CHECK_FS_CMD = "mount | grep 'rootfs on / type rootfs'"
+
+
+def boot_img(emulator, builddir):
+    img = os.path.join(builddir, "images", "rootfs.cpio")
+    emulator.boot(arch="armv7",
+                  kernel="builtin",
+                  options=["-initrd", "{}".format(img)])
+    emulator.login()
+    _, exit_code = emulator.run(CHECK_FS_CMD)
+    return exit_code
+
+
+class TestCpioFull(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_INIT_BUSYBOX=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        BR2_TARGET_ROOTFS_CPIO_FULL=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+
+        exit_code = boot_img(self.emulator,
+                             self.builddir)
+        self.assertEqual(exit_code, 0)
+
+
+class TestCpioDracutBase(infra.basetest.BRTest):
+    config = \
+        """
+        BR2_arm=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
+        BR2_INIT_BUSYBOX=y
+        BR2_PACKAGE_PV=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        BR2_TARGET_ROOTFS_CPIO_DRACUT=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def check_dracut(self):
+        out = subprocess.check_output(["cpio", "--list"],
+                                      stdin=open(os.path.join(self.builddir, "images/rootfs.cpio")),
+                                      stderr=open(os.devnull, "w"),
+                                      cwd=self.builddir,
+                                      env={"LANG": "C"},
+                                      universal_newlines=True)
+        # pv should *not* be included in cpio image
+        self.assertEqual(out.find("bin/pv"), -1)
+
+        exit_code = boot_img(self.emulator,
+                             self.builddir)
+        self.assertEqual(exit_code, 0)
+
+        # No pivot_root is done, so pv shouldn't be there
+        _, exit_code = self.emulator.run("ls -l /usr/bin/pv")
+        self.assertNotEqual(exit_code, 0)
+
+
+class TestCpioDracutUclibc(TestCpioDracutBase):
+    config = TestCpioDracutBase.config + \
+        """
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_UCLIBC_STABLE=y
+        """
+
+    def test_run(self):
+        self.check_dracut()
+
+
+class TestCpioDracutGlibc(TestCpioDracutBase):
+    config = TestCpioDracutBase.config + \
+        """
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
+        """
+
+    def test_run(self):
+        self.check_dracut()
+
+
+class TestCpioDracutMusl(TestCpioDracutBase):
+    config = TestCpioDracutBase.config + \
+        """
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_MUSL_STABLE=y
+        """
+
+    def test_run(self):
+        self.check_dracut()
-- 
2.37.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 1/3] package/dracut: new host package
  2022-08-15 11:17 [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Arnout Vandecappelle (Essensium/Mind)
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool Arnout Vandecappelle (Essensium/Mind)
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 3/3] support/testing/tests/fs/test_cpio.py: new runtime test Arnout Vandecappelle (Essensium/Mind)
@ 2022-08-15 12:36 ` Yann E. MORIN
  2022-08-15 16:27   ` Arnout Vandecappelle via buildroot
  2022-08-18 21:09 ` Yann E. MORIN
  3 siblings, 1 reply; 10+ messages in thread
From: Yann E. MORIN @ 2022-08-15 12:36 UTC (permalink / raw)
  To: Arnout Vandecappelle (Essensium/Mind)
  Cc: Adam Duskett, Thierry Bultel, buildroot

Arnout, All,

On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
> From: Thierry Bultel <thierry.bultel@linatsea.fr>
> Dracut is the tool used by desktop distributions to build initrds.
[--SNIP--]
> diff --git a/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
> new file mode 100644
> index 0000000000..87083d2cef
> --- /dev/null
> +++ b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
> @@ -0,0 +1,29 @@
> +From bb12f15856911d8532b569116da7dab4cbf107be Mon Sep 17 00:00:00 2001
> +From: Thierry Bultel <thierry.bultel@linatsea.fr>
> +Date: Mon, 10 Jan 2022 09:09:43 +0100
> +Subject: [PATCH] dracut.sh: don't unset LD_PRELOAD
> +
> +LD_PRELOAD is needed to run under fakeroot.

We also need LD_LIBRARY_PATH to actually find our lifakeroot.so (as
discussed on IRC).

[--SNIP--]
> diff --git a/package/dracut/busybox-init-module-setup.sh b/package/dracut/busybox-init-module-setup.sh
> new file mode 100644
> index 0000000000..2667f866d1
> --- /dev/null
> +++ b/package/dracut/busybox-init-module-setup.sh
> @@ -0,0 +1,62 @@
> +#!/bin/bash
> +
> +check() {
> +	require_binaries busybox || return 1
> +	return 0

return 0 is not needed: a shell function returns with the exit code from
the last command it ran. In this case, the previous command succeeded,
or we'd have already returned with 1, so the return code would be 0.

Still, we can keep it if that makes it consistent with the rest of the
dracut modules.

> +}
> +
> +depends() {
> +	return 0

Here, a colon should be enough:  depends() { :; }
Yet, consistency? ;-)

> +}
> +
> +install_busybox_links() {
> +	dir=$1
> +	linkname=$2
> +
> +	(cd "${dracutsysrootdir?}${dir}" &&
> +	for x in *; do
> +		if [ "$(readlink "$x")" = "${linkname}" ]; then

Always expand between curly braces, even single-char variables.

> +			ln -sf "${linkname}" "${initdir?}/${dir}/$x"

Ditto.

> +		fi
> +	done
> +	)
> +}
> +
> +install() {
> +	inst_multiple /bin/busybox
> +
> +	# wrapper script for early console; will launch /sbin/init
> +	# after having mounted devtmpfs
> +	inst_multiple /init
> +
> +	ln -s ../bin/busybox "${initdir?}"/sbin/init

Isn't that already covered by the second install_busybox_links call,
below?

> +	if [ -e "${dracutsysrootdir?}/lib64" ]; then
> +		ln -sf lib "${initdir?}/lib64"
> +		ln -sf lib "${initdir?}/usr/lib64"
> +	fi
> +
> +	if [ -e "${dracutsysrootdir?}/lib32" ]; then
> +		ln -sf lib "${initdir?}/lib32"
> +		ln -sf lib "${initdir?}/usr/lib32"
> +	fi
> +
> +	install_busybox_links "/bin" "busybox"
> +	install_busybox_links "/sbin" "../bin/busybox"

This one should catch the /sbin/init -> /bin/busybox symlink, no?

> +	if [ ! -L /bin ]; then
> +		install_busybox_links "/usr/bin" "../../bin/busybox"
> +		install_busybox_links "/usr/sbin" "../../bin/busybox"
> +	fi
> +
> +	inst_multiple \
> +		/etc/inittab	\
> +		/etc/init.d/rcS \
> +		/etc/init.d/rcK \
> +		/etc/issue	\
> +		/etc/fstab	\
> +		/etc/group	\
> +		/etc/passwd	\
> +		/etc/shadow	\
> +		/etc/hostname
> +}
> +

Spurious empty line at EOF.

> diff --git a/package/dracut/dracut.mk b/package/dracut/dracut.mk
> new file mode 100644
> index 0000000000..7afec80c0e
> --- /dev/null
> +++ b/package/dracut/dracut.mk
> @@ -0,0 +1,47 @@
> +################################################################################
> +#
> +# dracut
> +#
> +################################################################################
> +
> +DRACUT_VERSION = 055

056 is tarball-released, and 057 is github-tagged now. We can bump in a
later commit, of course.

> +DRACUT_SOURCE = dracut-$(DRACUT_VERSION).tar.xz
> +DRACUT_SITE = $(BR2_KERNEL_MIRROR)/linux/utils/boot/dracut

So, what is the canonical source? Kernel.org has 056, but not 057. Their
README.md hints that github is the official source:

    Currently dracut is developed on [github.com](https://github.com/dracutdevs/dracut).

    The release tarballs are [here](https://github.com/dracutdevs/dracut/releases).

> +DRACUT_LICENSE = GPL-2.0
> +DRACUT_LICENSE_FILES = COPYING
> +
> +HOST_DRACUT_DEPENDENCIES = host-pkgconf host-kmod host-prelink-cross
> +
> +define HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
> +	mv $(HOST_DIR)/bin/dracut $(HOST_DIR)/bin/dracut.real
> +	install -D -m 0755 $(HOST_DRACUT_PKGDIR)/dracut_wrapper.sh $(HOST_DIR)/bin/dracut

There is no reason to add the '.sh' suffix to any executable shell
script, since what matters is the shebang line, especially since it
is eventually installed as a non-suffixed name.

> +endef
> +HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
> +
> +# When using uClibc or musl, there must be "ls-uClibc.so.1" or
                                              ,^^
s/ls/ld/ ------------------------------------'

[--SNIP--]
> diff --git a/package/dracut/dracut_wrapper.sh b/package/dracut/dracut_wrapper.sh
> new file mode 100644
> index 0000000000..3f58b0907e
> --- /dev/null
> +++ b/package/dracut/dracut_wrapper.sh
> @@ -0,0 +1,33 @@
> +#!/bin/bash
> +set -e
> +
> +# Find the --sysroot argument
> +sysroot=
> +next_arg=
> +for arg; do
> +	if [ "$next_arg" = 1 ]; then

For such a situation, there is a construct that I started to like and
use, is to use 'true' and 'false' instead of markers in variables, so
that we can actually test the variable directly:

    sysroot
    next_arg=false
    for arg; do
        if ${next_arg}; then
            next_arg=false
            sysroot="${arg}"
            continue  # not break, in case there are more than one
        fi
        case "${arg}" in
          (--sysroot)
            next_arg=true
            continue
            ;;
          (--sysroot=*)
            sysroot="${arg#*=}"
            continue  # not break, in case there are more than one
            ;;
        esac
    done

> +		next_arg=
> +		sysroot="$arg"
> +		continue
> +	fi
> +
> +	case "$arg" in
> +	--sysroot=*)
> +		sysroot="${arg#*=}"
> +		;;
> +	--sysroot)
> +		next_arg=1
> +		;;
> +	esac
> +done
> +if [ -z "$sysroot" ]; then

Curly-braces for expansion.

> +	echo "$0: --sysroot argument must be given." 1>&2
> +	exit 1
> +fi
> +
> +topdir="$(dirname "$(realpath "$(dirname "$0")")")"

You can avoid a call to dirname, with just: ${0%/*}

Also, always expand variables with curly braces, even positional
arguments.

> +export DRACUT_LDD="$topdir/sbin/prelink-rtld --root='${sysroot}'"
                       ^^^^^^
Always expand variables between curly braces, especially since there is
already such an expansion on the same line (also valid below).

> +export DRACUT_INSTALL="$topdir/lib/dracut/dracut-install"
> +export DRACUT_LDCONFIG=/bin/true
> +export dracutbasedir="$topdir/lib/dracut"
> +exec "$topdir/bin/dracut.real" "$@"
> diff --git a/package/dracut/libc-links-module-setup.sh b/package/dracut/libc-links-module-setup.sh
> new file mode 100755
> index 0000000000..e15b216e6e
> --- /dev/null
> +++ b/package/dracut/libc-links-module-setup.sh
> @@ -0,0 +1,27 @@
> +#!/bin/bash
> +
> +# Adds the missing links for uClibc or musl, if needed
> +
> +check() {
> +	return 0
> +}
> +
> +depends() {
> +	return 0
> +}
> +
> +install() {
> +	# Despite of the fact that the listed dependency (reported by readelf -d)
> +	# is purely /lib/libc.so, the musl symlink is needed anyway.
> +	musl_link="$(find "${dracutsysrootdir?}/lib" -name "ld-musl-*.so*")"
> +	if [ -n "$musl_link" ] ; then
> +		ln -s libc.so "${initdir?}/lib/$(basename "${musl_link}")"

Besides the usual curly-braces expansion comment, you don't need to use
basename here: ${musl_link##*/}

All of those are minor and can be fixed when applying, but there are a
few where a reply/confirmation would still be welcome.

> +	fi
> +
> +	# Same for uClibc, the listed dependency
> +	# is ld-uClibc.so.1, the loader needs the ld-uClibc.so.0, too
> +	uclibc_link="$(find "${dracutsysrootdir?}/lib" -name "ld-uClibc-*.so*")"
> +	if [ -n "$uclibc_link" ] ; then
> +		ln -s ld-uClibc.so.1 "${initdir?s}/lib/ld-uClibc.so.0"
> +	fi
> +}
> -- 
> 2.37.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool Arnout Vandecappelle (Essensium/Mind)
@ 2022-08-15 13:05   ` Yann E. MORIN
  2022-08-15 16:37     ` Arnout Vandecappelle
  2022-08-18 21:09   ` Yann E. MORIN
  1 sibling, 1 reply; 10+ messages in thread
From: Yann E. MORIN @ 2022-08-15 13:05 UTC (permalink / raw)
  To: Arnout Vandecappelle (Essensium/Mind)
  Cc: Adam Duskett, Thierry Bultel, buildroot

Arnout, All,

On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
> From: Thierry Bultel <thierry.bultel@linatsea.fr>
> 
> Adds an option to invoke the dracut host tool, providing
> a configuration file, instead of having a full cpio archive
> of the whole target directory.
[--SNIP--]
> diff --git a/fs/cpio/Config.in b/fs/cpio/Config.in
> index c1151a2881..de83aaad65 100644
> --- a/fs/cpio/Config.in
> +++ b/fs/cpio/Config.in
> @@ -7,6 +7,40 @@ config BR2_TARGET_ROOTFS_CPIO
>  
>  if BR2_TARGET_ROOTFS_CPIO
>  
> +choice
> +	prompt "cpio type"
> +	default BR2_TARGET_ROOTFS_CPIO_FULL
> +
> +config BR2_TARGET_ROOTFS_CPIO_FULL
> +	bool "cpio the whole root filesystem"
> +	help
> +	  Build a cpio archive containing the whole the root filesystem.
> +
> +config BR2_TARGET_ROOTFS_CPIO_DRACUT
> +	bool "Invoke dracut to make a partial initramfs"
> +	select BR2_PACKAGE_HOST_DRACUT
> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS

As seen on IRC, host-uboot-tools are not required just for dracut.

> +if BR2_TARGET_ROOTFS_CPIO_DRACUT

Empty line after an 'if'...

> +config BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE
> +	string "dracut configuration file"
> +	default "fs/cpio/dracut.conf"
> +	help
> +	  Dracut configuration file. It determines which parts of the
> +	  rootfs get included in the cpio image. See dracut.conf(5) or
> +	  https://github.com/dracutdevs/dracut/blob/master/man/dracut.conf.5.asc
> +
> +	  The default configuration file is suitable for busybox init.
> +	  It doesn't, however, pivot_root into a full rootfs.

... and before an 'endif'.

> +endif
> +
>  choice
>  	prompt "Compression method"
>  	default BR2_TARGET_ROOTFS_CPIO_NONE
> diff --git a/fs/cpio/cpio.mk b/fs/cpio/cpio.mk
> index 81f8c393d1..b62d804ad8 100644
> --- a/fs/cpio/cpio.mk
> +++ b/fs/cpio/cpio.mk
> @@ -36,6 +36,8 @@ ROOTFS_CPIO_DEPENDENCIES += host-cpio
>  ROOTFS_CPIO_OPTS += --reproducible
>  endif
>  
> +ifeq ($(BR2_TARGET_ROOTFS_CPIO_FULL),y)
> +
>  define ROOTFS_CPIO_CMD

We customarily do not define the _CMD (or _CMDS) conditionally. Instead,
we define conditional macros, and we expand them all in an unconditional
_CMD (or _CMDS) macro.

>  	cd $(TARGET_DIR) && \
>  	find . \
> @@ -44,6 +46,37 @@ define ROOTFS_CPIO_CMD
>  	> $@
>  endef
>  
> +else ifeq ($(BR2_TARGET_ROOTFS_CPIO_DRACUT),y)
> +
> +ROOTFS_CPIO_DEPENDENCIES += host-dracut
> +
> +ifeq ($(BR_BUILDING):$(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE),y:)
> +$(error No dracut config file name specified, check your BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE setting)
> +endif
> +
> +ifeq ($(BR2_LINUX_KERNEL),y)
> +ROOTFS_CPIO_DEPENDENCIES += linux
> +ROOTFS_CPIO_OPTS += --kver $(LINUX_VERSION_PROBED)
> +else
> +ROOTFS_CPIO_OPTS += --no-kernel
> +endif
> +
> +define ROOTFS_CPIO_CMD
> +	mkdir -p $(ROOTFS_CPIO_DIR)/tmp
> +
> +	$(HOST_DIR)/bin/dracut \
> +		$(ROOTFS_CPIO_OPTS) \
> +		-c $(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE) \
> +		--sysroot $(TARGET_DIR) \

Hrmm.. --sysroot is misleading in our situation. Also, it can be spelt
-r so our wrapper must also cope with it (in case it is called from a
post-image script).

[--SNIP--]
> diff --git a/fs/cpio/dracut.conf b/fs/cpio/dracut.conf
> new file mode 100644
> index 0000000000..6184457723
> --- /dev/null
> +++ b/fs/cpio/dracut.conf
> @@ -0,0 +1,93 @@
[--SNIP--]
> +"
> +

Spurious emoty line at EOF.

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 1/3] package/dracut: new host package
  2022-08-15 12:36 ` [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Yann E. MORIN
@ 2022-08-15 16:27   ` Arnout Vandecappelle via buildroot
  0 siblings, 0 replies; 10+ messages in thread
From: Arnout Vandecappelle via buildroot @ 2022-08-15 16:27 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: Adam Duskett, Thierry Bultel, buildroot



On 15/08/2022 14:36, Yann E. MORIN wrote:
> Arnout, All,
> 
> On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
>> From: Thierry Bultel <thierry.bultel@linatsea.fr>
>> Dracut is the tool used by desktop distributions to build initrds.
> [--SNIP--]
>> diff --git a/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
>> new file mode 100644
>> index 0000000000..87083d2cef
>> --- /dev/null
>> +++ b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
>> @@ -0,0 +1,29 @@
>> +From bb12f15856911d8532b569116da7dab4cbf107be Mon Sep 17 00:00:00 2001
>> +From: Thierry Bultel <thierry.bultel@linatsea.fr>
>> +Date: Mon, 10 Jan 2022 09:09:43 +0100
>> +Subject: [PATCH] dracut.sh: don't unset LD_PRELOAD
>> +
>> +LD_PRELOAD is needed to run under fakeroot.
> 
> We also need LD_LIBRARY_PATH to actually find our lifakeroot.so (as
> discussed on IRC).
> 
> [--SNIP--]
>> diff --git a/package/dracut/busybox-init-module-setup.sh b/package/dracut/busybox-init-module-setup.sh
>> new file mode 100644
>> index 0000000000..2667f866d1
>> --- /dev/null
>> +++ b/package/dracut/busybox-init-module-setup.sh
>> @@ -0,0 +1,62 @@
>> +#!/bin/bash
>> +
>> +check() {
>> +	require_binaries busybox || return 1
>> +	return 0
> 
> return 0 is not needed: a shell function returns with the exit code from
> the last command it ran. In this case, the previous command succeeded,
> or we'd have already returned with 1, so the return code would be 0.
> 
> Still, we can keep it if that makes it consistent with the rest of the
> dracut modules.

  Yes, other dracut modules all have an explicit return. Usually "return 255" in 
the check function though. That indicates that the module should only be 
included if it's depended on by something else.

>> +}
>> +
>> +depends() {
>> +	return 0
> 
> Here, a colon should be enough:  depends() { :; }
> Yet, consistency? ;-)

  Exactly.


>> +}
>> +
>> +install_busybox_links() {
>> +	dir=$1
>> +	linkname=$2
>> +
>> +	(cd "${dracutsysrootdir?}${dir}" &&
>> +	for x in *; do
>> +		if [ "$(readlink "$x")" = "${linkname}" ]; then
> 
> Always expand between curly braces, even single-char variables.

  We don't do that consistently at the moment, so I didn't realize this was a thing.

  Is it something that shellcheck can verify?

>> +			ln -sf "${linkname}" "${initdir?}/${dir}/$x"
> 
> Ditto.
> 
>> +		fi
>> +	done
>> +	)
>> +}
>> +
>> +install() {
>> +	inst_multiple /bin/busybox
>> +
>> +	# wrapper script for early console; will launch /sbin/init
>> +	# after having mounted devtmpfs
>> +	inst_multiple /init
>> +
>> +	ln -s ../bin/busybox "${initdir?}"/sbin/init
> 
> Isn't that already covered by the second install_busybox_links call,
> below?

  Ah, yes, it should be.


>> +	if [ -e "${dracutsysrootdir?}/lib64" ]; then

  BTW, I should probably have mentioned in the commit message that the ? here is 
to indicate variables that are pre-defined by dracut and that shellcheck errors 
out on. dracut itself completely excludes the check of undefined variables, but 
I prefer not to do that.

>> +		ln -sf lib "${initdir?}/lib64"
>> +		ln -sf lib "${initdir?}/usr/lib64"
>> +	fi
>> +
>> +	if [ -e "${dracutsysrootdir?}/lib32" ]; then
>> +		ln -sf lib "${initdir?}/lib32"
>> +		ln -sf lib "${initdir?}/usr/lib32"
>> +	fi
>> +
>> +	install_busybox_links "/bin" "busybox"
>> +	install_busybox_links "/sbin" "../bin/busybox"
> 
> This one should catch the /sbin/init -> /bin/busybox symlink, no?
> 
>> +	if [ ! -L /bin ]; then
>> +		install_busybox_links "/usr/bin" "../../bin/busybox"
>> +		install_busybox_links "/usr/sbin" "../../bin/busybox"
>> +	fi
>> +
>> +	inst_multiple \
>> +		/etc/inittab	\
>> +		/etc/init.d/rcS \
>> +		/etc/init.d/rcK \
>> +		/etc/issue	\
>> +		/etc/fstab	\
>> +		/etc/group	\
>> +		/etc/passwd	\
>> +		/etc/shadow	\
>> +		/etc/hostname
>> +}
>> +
> 
> Spurious empty line at EOF.
> 
>> diff --git a/package/dracut/dracut.mk b/package/dracut/dracut.mk
>> new file mode 100644
>> index 0000000000..7afec80c0e
>> --- /dev/null
>> +++ b/package/dracut/dracut.mk
>> @@ -0,0 +1,47 @@
>> +################################################################################
>> +#
>> +# dracut
>> +#
>> +################################################################################
>> +
>> +DRACUT_VERSION = 055
> 
> 056 is tarball-released, and 057 is github-tagged now. We can bump in a
> later commit, of course.
> 
>> +DRACUT_SOURCE = dracut-$(DRACUT_VERSION).tar.xz
>> +DRACUT_SITE = $(BR2_KERNEL_MIRROR)/linux/utils/boot/dracut
> 
> So, what is the canonical source? Kernel.org has 056, but not 057. Their
> README.md hints that github is the official source:
> 
>      Currently dracut is developed on [github.com](https://github.com/dracutdevs/dracut).
> 
>      The release tarballs are [here](https://github.com/dracutdevs/dracut/releases).

  I hadn't seen that.


>> +DRACUT_LICENSE = GPL-2.0
>> +DRACUT_LICENSE_FILES = COPYING
>> +
>> +HOST_DRACUT_DEPENDENCIES = host-pkgconf host-kmod host-prelink-cross
>> +
>> +define HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
>> +	mv $(HOST_DIR)/bin/dracut $(HOST_DIR)/bin/dracut.real
>> +	install -D -m 0755 $(HOST_DRACUT_PKGDIR)/dracut_wrapper.sh $(HOST_DIR)/bin/dracut
> 
> There is no reason to add the '.sh' suffix to any executable shell
> script, since what matters is the shebang line, especially since it
> is eventually installed as a non-suffixed name.

  Well, I hope that we will at some point extend check-package to run shellcheck 
on everything that ends with .sh (in addition to the init scripts).

>> +endef
>> +HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
>> +
>> +# When using uClibc or musl, there must be "ls-uClibc.so.1" or
>                                                ,^^
> s/ls/ld/ ------------------------------------'

  Oops :-)

> 
> [--SNIP--]
>> diff --git a/package/dracut/dracut_wrapper.sh b/package/dracut/dracut_wrapper.sh
>> new file mode 100644
>> index 0000000000..3f58b0907e
>> --- /dev/null
>> +++ b/package/dracut/dracut_wrapper.sh
>> @@ -0,0 +1,33 @@
>> +#!/bin/bash
>> +set -e
>> +
>> +# Find the --sysroot argument
>> +sysroot=
>> +next_arg=
>> +for arg; do
>> +	if [ "$next_arg" = 1 ]; then
> 
> For such a situation, there is a construct that I started to like and
> use, is to use 'true' and 'false' instead of markers in variables, so
> that we can actually test the variable directly:
> 
>      sysroot
>      next_arg=false
>      for arg; do
>          if ${next_arg}; then

  Oh yes, better. Note that shellcheck will probably want you to add quotes.

>              next_arg=false
>              sysroot="${arg}"
>              continue  # not break, in case there are more than one

  And thanks for the comment :-)

>          fi
>          case "${arg}" in
>            (--sysroot)
>              next_arg=true
>              continue
>              ;;
>            (--sysroot=*)
>              sysroot="${arg#*=}"
>              continue  # not break, in case there are more than one
>              ;;
>          esac
>      done
> 
>> +		next_arg=
>> +		sysroot="$arg"
>> +		continue
>> +	fi
>> +
>> +	case "$arg" in
>> +	--sysroot=*)
>> +		sysroot="${arg#*=}"
>> +		;;
>> +	--sysroot)
>> +		next_arg=1
>> +		;;
>> +	esac
>> +done
>> +if [ -z "$sysroot" ]; then
> 
> Curly-braces for expansion.
> 
>> +	echo "$0: --sysroot argument must be given." 1>&2
>> +	exit 1
>> +fi
>> +
>> +topdir="$(dirname "$(realpath "$(dirname "$0")")")"
> 
> You can avoid a call to dirname, with just: ${0%/*}

  Since we anyway need the outer dirname, I prefer to use dirname for the inner 
one as well.

> 
> Also, always expand variables with curly braces, even positional
> arguments.
> 
>> +export DRACUT_LDD="$topdir/sbin/prelink-rtld --root='${sysroot}'"
>                         ^^^^^^
> Always expand variables between curly braces, especially since there is
> already such an expansion on the same line (also valid below).
> 
>> +export DRACUT_INSTALL="$topdir/lib/dracut/dracut-install"
>> +export DRACUT_LDCONFIG=/bin/true
>> +export dracutbasedir="$topdir/lib/dracut"
>> +exec "$topdir/bin/dracut.real" "$@"
>> diff --git a/package/dracut/libc-links-module-setup.sh b/package/dracut/libc-links-module-setup.sh
>> new file mode 100755
>> index 0000000000..e15b216e6e
>> --- /dev/null
>> +++ b/package/dracut/libc-links-module-setup.sh
>> @@ -0,0 +1,27 @@
>> +#!/bin/bash
>> +
>> +# Adds the missing links for uClibc or musl, if needed
>> +
>> +check() {
>> +	return 0
>> +}
>> +
>> +depends() {
>> +	return 0
>> +}
>> +
>> +install() {
>> +	# Despite of the fact that the listed dependency (reported by readelf -d)
>> +	# is purely /lib/libc.so, the musl symlink is needed anyway.
>> +	musl_link="$(find "${dracutsysrootdir?}/lib" -name "ld-musl-*.so*")"
>> +	if [ -n "$musl_link" ] ; then
>> +		ln -s libc.so "${initdir?}/lib/$(basename "${musl_link}")"
> 
> Besides the usual curly-braces expansion comment, you don't need to use
> basename here: ${musl_link##*/}

  Yes, here it's definitely better to do it in the expansion itself.

  Regards,
  Arnout


> 
> All of those are minor and can be fixed when applying, but there are a
> few where a reply/confirmation would still be welcome.
> 
>> +	fi
>> +
>> +	# Same for uClibc, the listed dependency
>> +	# is ld-uClibc.so.1, the loader needs the ld-uClibc.so.0, too
>> +	uclibc_link="$(find "${dracutsysrootdir?}/lib" -name "ld-uClibc-*.so*")"
>> +	if [ -n "$uclibc_link" ] ; then
>> +		ln -s ld-uClibc.so.1 "${initdir?s}/lib/ld-uClibc.so.0"
>> +	fi
>> +}
>> -- 
>> 2.37.1
>>
>> _______________________________________________
>> buildroot mailing list
>> buildroot@buildroot.org
>> https://lists.buildroot.org/mailman/listinfo/buildroot
> 
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool
  2022-08-15 13:05   ` Yann E. MORIN
@ 2022-08-15 16:37     ` Arnout Vandecappelle
  0 siblings, 0 replies; 10+ messages in thread
From: Arnout Vandecappelle @ 2022-08-15 16:37 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: Adam Duskett, Thierry Bultel, buildroot



On 15/08/2022 15:05, Yann E. MORIN wrote:
> Arnout, All,
> 
> On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
>> From: Thierry Bultel <thierry.bultel@linatsea.fr>
>>
>> Adds an option to invoke the dracut host tool, providing
>> a configuration file, instead of having a full cpio archive
>> of the whole target directory.
> [--SNIP--]
>> diff --git a/fs/cpio/Config.in b/fs/cpio/Config.in
>> index c1151a2881..de83aaad65 100644
>> --- a/fs/cpio/Config.in
>> +++ b/fs/cpio/Config.in
>> @@ -7,6 +7,40 @@ config BR2_TARGET_ROOTFS_CPIO
>>   
>>   if BR2_TARGET_ROOTFS_CPIO
>>   
>> +choice
>> +	prompt "cpio type"
>> +	default BR2_TARGET_ROOTFS_CPIO_FULL
>> +
>> +config BR2_TARGET_ROOTFS_CPIO_FULL
>> +	bool "cpio the whole root filesystem"
>> +	help
>> +	  Build a cpio archive containing the whole the root filesystem.
>> +
>> +config BR2_TARGET_ROOTFS_CPIO_DRACUT
>> +	bool "Invoke dracut to make a partial initramfs"
>> +	select BR2_PACKAGE_HOST_DRACUT
>> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS
> 
> As seen on IRC, host-uboot-tools are not required just for dracut.
> 
>> +if BR2_TARGET_ROOTFS_CPIO_DRACUT
> 
> Empty line after an 'if'...

  That was kind of intentional, to make it more clear that the condition is just 
around this one symbol. But perhaps it would be better to turn it into a depends 
on instead.

> 
>> +config BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE
>> +	string "dracut configuration file"
>> +	default "fs/cpio/dracut.conf"
>> +	help
>> +	  Dracut configuration file. It determines which parts of the
>> +	  rootfs get included in the cpio image. See dracut.conf(5) or
>> +	  https://github.com/dracutdevs/dracut/blob/master/man/dracut.conf.5.asc
>> +
>> +	  The default configuration file is suitable for busybox init.
>> +	  It doesn't, however, pivot_root into a full rootfs.
> 
> ... and before an 'endif'.
> 
>> +endif
>> +
>>   choice
>>   	prompt "Compression method"
>>   	default BR2_TARGET_ROOTFS_CPIO_NONE
>> diff --git a/fs/cpio/cpio.mk b/fs/cpio/cpio.mk
>> index 81f8c393d1..b62d804ad8 100644
>> --- a/fs/cpio/cpio.mk
>> +++ b/fs/cpio/cpio.mk
>> @@ -36,6 +36,8 @@ ROOTFS_CPIO_DEPENDENCIES += host-cpio
>>   ROOTFS_CPIO_OPTS += --reproducible
>>   endif
>>   
>> +ifeq ($(BR2_TARGET_ROOTFS_CPIO_FULL),y)
>> +
>>   define ROOTFS_CPIO_CMD
> 
> We customarily do not define the _CMD (or _CMDS) conditionally. Instead,
> we define conditional macros, and we expand them all in an unconditional
> _CMD (or _CMDS) macro.

  That would be weird in this case - you'd have something like

define ROOTFS_CPIO_CMD
	$(ROOTFS_CPIO_CPIO_CMD)
	$(ROOTFS_CPIO_DRACUT_CMD)
endif

but the two are mutually exclusive... In this case, IMHO it's much more logical 
to define the _CMD directly in the two conditions.

  I'm not going to look for an example, but I can imagine that we do do 
something similar for _INSTALL_TARGET_CMDS when there are two completely 
different installation processes depending on a config option.

  OK, I was stubborn and did look for an example: imx-mkimage.


>>   	cd $(TARGET_DIR) && \
>>   	find . \
>> @@ -44,6 +46,37 @@ define ROOTFS_CPIO_CMD
>>   	> $@
>>   endef
>>   
>> +else ifeq ($(BR2_TARGET_ROOTFS_CPIO_DRACUT),y)
>> +
>> +ROOTFS_CPIO_DEPENDENCIES += host-dracut
>> +
>> +ifeq ($(BR_BUILDING):$(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE),y:)
>> +$(error No dracut config file name specified, check your BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE setting)
>> +endif
>> +
>> +ifeq ($(BR2_LINUX_KERNEL),y)
>> +ROOTFS_CPIO_DEPENDENCIES += linux
>> +ROOTFS_CPIO_OPTS += --kver $(LINUX_VERSION_PROBED)
>> +else
>> +ROOTFS_CPIO_OPTS += --no-kernel
>> +endif
>> +
>> +define ROOTFS_CPIO_CMD
>> +	mkdir -p $(ROOTFS_CPIO_DIR)/tmp
>> +
>> +	$(HOST_DIR)/bin/dracut \
>> +		$(ROOTFS_CPIO_OPTS) \
>> +		-c $(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE) \
>> +		--sysroot $(TARGET_DIR) \
> 
> Hrmm.. --sysroot is misleading in our situation.

  Well, that's the name of the option, what are we going to do about it?

> Also, it can be spelt
> -r so our wrapper must also cope with it (in case it is called from a
> post-image script).

  Arg good catch!

  And annoying GNU getopt extension allows both -rfoo and -r foo so it's even 
more complicated :-/


  Regards,
  Arnout

> [--SNIP--]
>> diff --git a/fs/cpio/dracut.conf b/fs/cpio/dracut.conf
>> new file mode 100644
>> index 0000000000..6184457723
>> --- /dev/null
>> +++ b/fs/cpio/dracut.conf
>> @@ -0,0 +1,93 @@
> [--SNIP--]
>> +"
>> +
> 
> Spurious emoty line at EOF.
> 
> Regards,
> Yann E. MORIN.
> 
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 1/3] package/dracut: new host package
  2022-08-15 11:17 [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Arnout Vandecappelle (Essensium/Mind)
                   ` (2 preceding siblings ...)
  2022-08-15 12:36 ` [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Yann E. MORIN
@ 2022-08-18 21:09 ` Yann E. MORIN
  3 siblings, 0 replies; 10+ messages in thread
From: Yann E. MORIN @ 2022-08-18 21:09 UTC (permalink / raw)
  To: Arnout Vandecappelle (Essensium/Mind)
  Cc: Adam Duskett, Thierry Bultel, buildroot

ARnout, Thierry, All,

On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
> From: Thierry Bultel <thierry.bultel@linatsea.fr>
> 
> Dracut is the tool used by desktop distributions to build initrds.
> 
> In the embedded world, it can be very useful, too, for instance when
> wanting to create an initramfs for a system recovery mode.
> Whereas it is definitively possible to achieve this with buildroot, the
> process is to have a dedicated buildroot configuration for that, and
> perform a full build. Instead of doing that, dracut can pick the needed
> binaries/shared libraries, configuration files, or kernel modules from
> the 'target' directory.
> The advantage is to save build time, and also to have a consistency
> between the packages versions taken for the recovery and the production
> filesystem.
> 
> The principle of dracut is based on the so-called 'dracut modules'. The
> modules determine what will be included in the initramfs. For example,
> one of dracut's modules checks the kernel modules that are included and
> also includes the corresponding firmware blobs.
> On the host, they are on host/lib/dracut/modules.d
> Each directory as a prefix number for the order of execution, and
> at least a "module-setup.sh" script.
> 
> Dracut sources all of them, and typically calls the "check()" function,
> which is the placeholder for required binaries (that are aimed to be
> polulated in the initrd), then the "depends()" function, that lists
> other modules to depend on, and the "install()" function, that makes
> the actual work.
> 
> Dracut was initially thought to work with systems using systemd,
> but it can also work without it. Do to so, every "systemd-xxx"
> module must be disabled in the dracut configuration file. For
> convenience, the 05busybox-init module is provided, to support
> busybox init system. Note that this module should *not* be enabled when
> using systemd init. It is therefore only installed if busybox init is
> selected.
> 
> Musl and uClibc make assumptions about the existence of some symlinks
> that are not discoverable with readelf. Therefore, another module
> 05libc-links is provided that creates those links. The module is
> installed regardless of which libc is used - the script itself discovers
> if the links need to be installed based on which libc is found.
> 
> Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> Cc: Adam Duskett <aduskett@gmail.com>

Applied to next, with all the changes we discussed in this thread and
on IRC, thanks.

Regards,
Yann E. MORIN.

> ---
> Changes v1 -> v2 (all suggested by Arnout)
>   - added a wrapper script
> Changes v2 -> v3
>   - added modules for:
>      - supporting busybox system init type
>      - fixing a missing symlink for uClibc
> Changes v3 -> v4
>   - some explanations on the dracut modules in the commit log
>   - fixed a bug on the 'require_binary' line in busybox module
>   - expanded variables with double quotes and curly braces
>   - removed commented out code
>   - fixes for 'fakeroot' and 'uclibc' and 'musl' as patches
>   - musl and uclibc dynamic fix
>   - renamed dracut wrapper
>   - disabled when using another init system than systemd or busybox
> Changes v4 -> v5
>   - add hash file;
>   - add DEVELOPERS entries;
>   - replace patch 0001 with an intree file and copy in post-install;
>   - properly format patch 0000, add signoff, rename to 0001;
>   - rename busybox-buildroot to busybox-init;
>   - correct the symlink creation for musl and uclibc;
>   - remove directory part from the extra modules;
>   - remove unused dracut script (identical to dracut_wrapper);
>   - switch to prelink-cross instead of cross-ldd;
>   - make dracut_wrapper script relocatable;
>   - don't set sysroot in wrapper script, expect it to be passed as
>     --sysroot argument;
>   - call the wrapper script bin/dracut instead of sbin/dracut, and
>     rename the original to dracut.real;
>   - fix shellcheck warnings in the module scripts.
> ---
>  DEVELOPERS                                    |  2 +
>  package/Config.in.host                        |  1 +
>  ...001-dracut.sh-don-t-unset-LD_PRELOAD.patch | 29 +++++++++
>  package/dracut/Config.in.host                 |  9 +++
>  package/dracut/busybox-init-module-setup.sh   | 62 +++++++++++++++++++
>  package/dracut/dracut.hash                    |  3 +
>  package/dracut/dracut.mk                      | 47 ++++++++++++++
>  package/dracut/dracut_wrapper.sh              | 33 ++++++++++
>  package/dracut/libc-links-module-setup.sh     | 27 ++++++++
>  9 files changed, 213 insertions(+)
>  create mode 100644 package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
>  create mode 100644 package/dracut/Config.in.host
>  create mode 100644 package/dracut/busybox-init-module-setup.sh
>  create mode 100644 package/dracut/dracut.hash
>  create mode 100644 package/dracut/dracut.mk
>  create mode 100644 package/dracut/dracut_wrapper.sh
>  create mode 100755 package/dracut/libc-links-module-setup.sh
> 
> diff --git a/DEVELOPERS b/DEVELOPERS
> index d2bd0d809a..4287fd9cf7 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -225,6 +225,7 @@ F:	package/espeak/
>  N:	Arnout Vandecappelle <arnout@mind.be>
>  F:	package/arp-scan/
>  F:	package/dehydrated/
> +F:	package/dracut/
>  F:	package/freescale-imx/firmware-imx/
>  F:	package/freescale-imx/imx-lib/
>  F:	package/libpagekite/
> @@ -2796,6 +2797,7 @@ F:	configs/beagleboardx15_defconfig
>  F:	package/pugixml/
>  
>  N:	Thierry Bultel <tbultel@free.fr>
> +F:	package/dracut/
>  F:	package/mpd-mpc/
>  
>  N:	Thijs Vermeir <thijsvermeir@gmail.com>
> diff --git a/package/Config.in.host b/package/Config.in.host
> index 99edeafece..f437ef680c 100644
> --- a/package/Config.in.host
> +++ b/package/Config.in.host
> @@ -19,6 +19,7 @@ menu "Host utilities"
>  	source "package/dos2unix/Config.in.host"
>  	source "package/dosfstools/Config.in.host"
>  	source "package/doxygen/Config.in.host"
> +	source "package/dracut/Config.in.host"
>  	source "package/dtc/Config.in.host"
>  	source "package/e2fsprogs/Config.in.host"
>  	source "package/e2tools/Config.in.host"
> diff --git a/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
> new file mode 100644
> index 0000000000..87083d2cef
> --- /dev/null
> +++ b/package/dracut/0001-dracut.sh-don-t-unset-LD_PRELOAD.patch
> @@ -0,0 +1,29 @@
> +From bb12f15856911d8532b569116da7dab4cbf107be Mon Sep 17 00:00:00 2001
> +From: Thierry Bultel <thierry.bultel@linatsea.fr>
> +Date: Mon, 10 Jan 2022 09:09:43 +0100
> +Subject: [PATCH] dracut.sh: don't unset LD_PRELOAD
> +
> +LD_PRELOAD is needed to run under fakeroot.
> +
> +Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
> +Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> +---
> + dracut.sh | 2 --
> + 1 file changed, 2 deletions(-)
> +
> +diff --git a/dracut.sh b/dracut.sh
> +index 60ac46f4..37f25b38 100755
> +--- a/dracut.sh
> ++++ b/dracut.sh
> +@@ -868,8 +868,6 @@ export LC_ALL=C
> + export LANG=C
> + unset LC_MESSAGES
> + unset LC_CTYPE
> +-unset LD_LIBRARY_PATH
> +-unset LD_PRELOAD
> + unset GREP_OPTIONS
> + 
> + export DRACUT_LOG_LEVEL=warning
> +-- 
> +2.37.1
> +
> diff --git a/package/dracut/Config.in.host b/package/dracut/Config.in.host
> new file mode 100644
> index 0000000000..18f562b310
> --- /dev/null
> +++ b/package/dracut/Config.in.host
> @@ -0,0 +1,9 @@
> +config BR2_PACKAGE_HOST_DRACUT
> +	bool
> +	select BR2_PACKAGE_HOST_KMOD
> +	help
> +	  dracut is used to create an initramfs image by
> +	  copying tools and files from an installed system
> +	  and combining it with the dracut framework.
> +
> +	  https://dracut.wiki.kernel.org
> diff --git a/package/dracut/busybox-init-module-setup.sh b/package/dracut/busybox-init-module-setup.sh
> new file mode 100644
> index 0000000000..2667f866d1
> --- /dev/null
> +++ b/package/dracut/busybox-init-module-setup.sh
> @@ -0,0 +1,62 @@
> +#!/bin/bash
> +
> +check() {
> +	require_binaries busybox || return 1
> +	return 0
> +}
> +
> +depends() {
> +	return 0
> +}
> +
> +install_busybox_links() {
> +	dir=$1
> +	linkname=$2
> +
> +	(cd "${dracutsysrootdir?}${dir}" &&
> +	for x in *; do
> +		if [ "$(readlink "$x")" = "${linkname}" ]; then
> +			ln -sf "${linkname}" "${initdir?}/${dir}/$x"
> +		fi
> +	done
> +	)
> +}
> +
> +install() {
> +	inst_multiple /bin/busybox
> +
> +	# wrapper script for early console; will launch /sbin/init
> +	# after having mounted devtmpfs
> +	inst_multiple /init
> +
> +	ln -s ../bin/busybox "${initdir?}"/sbin/init
> +
> +	if [ -e "${dracutsysrootdir?}/lib64" ]; then
> +		ln -sf lib "${initdir?}/lib64"
> +		ln -sf lib "${initdir?}/usr/lib64"
> +	fi
> +
> +	if [ -e "${dracutsysrootdir?}/lib32" ]; then
> +		ln -sf lib "${initdir?}/lib32"
> +		ln -sf lib "${initdir?}/usr/lib32"
> +	fi
> +
> +	install_busybox_links "/bin" "busybox"
> +	install_busybox_links "/sbin" "../bin/busybox"
> +	if [ ! -L /bin ]; then
> +		install_busybox_links "/usr/bin" "../../bin/busybox"
> +		install_busybox_links "/usr/sbin" "../../bin/busybox"
> +	fi
> +
> +	inst_multiple \
> +		/etc/inittab	\
> +		/etc/init.d/rcS \
> +		/etc/init.d/rcK \
> +		/etc/issue	\
> +		/etc/fstab	\
> +		/etc/group	\
> +		/etc/passwd	\
> +		/etc/shadow	\
> +		/etc/hostname
> +}
> +
> diff --git a/package/dracut/dracut.hash b/package/dracut/dracut.hash
> new file mode 100644
> index 0000000000..3cda736856
> --- /dev/null
> +++ b/package/dracut/dracut.hash
> @@ -0,0 +1,3 @@
> +# Locally computed
> +sha256  4baa08206cceeb124dbf1075a0daf774b5a8f144ce2e01d82a144af3020fd65b  dracut-055.tar.xz
> +sha256  8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643  COPYING
> diff --git a/package/dracut/dracut.mk b/package/dracut/dracut.mk
> new file mode 100644
> index 0000000000..7afec80c0e
> --- /dev/null
> +++ b/package/dracut/dracut.mk
> @@ -0,0 +1,47 @@
> +################################################################################
> +#
> +# dracut
> +#
> +################################################################################
> +
> +DRACUT_VERSION = 055
> +DRACUT_SOURCE = dracut-$(DRACUT_VERSION).tar.xz
> +DRACUT_SITE = $(BR2_KERNEL_MIRROR)/linux/utils/boot/dracut
> +DRACUT_LICENSE = GPL-2.0
> +DRACUT_LICENSE_FILES = COPYING
> +
> +HOST_DRACUT_DEPENDENCIES = host-pkgconf host-kmod host-prelink-cross
> +
> +define HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
> +	mv $(HOST_DIR)/bin/dracut $(HOST_DIR)/bin/dracut.real
> +	install -D -m 0755 $(HOST_DRACUT_PKGDIR)/dracut_wrapper.sh $(HOST_DIR)/bin/dracut
> +endef
> +HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
> +
> +# When using uClibc or musl, there must be "ls-uClibc.so.1" or
> +# "ld-musl-x.so" symlinks, respectively - else the init process cannot
> +# start
> +define HOST_DRACUT_POST_INSTALL_LIBC_LINKS_MODULE
> +	$(INSTALL) -D -m 0755 package/dracut/libc-links-module-setup.sh \
> +		$(HOST_DIR)/lib/dracut/modules.d/05libc-links/module-setup.sh
> +endef
> +HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_LIBC_LINKS_MODULE
> +
> +ifeq ($(BR2_INIT_BUSYBOX),y)
> +# Dracut does not support busybox init (systemd init is assumed to work
> +# out of the box, though). It provides a busybox module, that does not
> +# use the same paths as buildroot, and is not meant to be used as an init
> +# system.
> +# So it is simpler for users to disable the standard 'busybox' module in
> +# the configuration file, and enable the "busybox-init' module instead.
> +# Note that setting the script as executable (0755) is not mandatory,
> +# but this is what dracut does on all its modules, so lets just conform
> +# to it.
> +define HOST_DRACUT_POST_INSTALL_BUSYBOX_INIT_MODULE
> +	$(INSTALL) -D -m 0755 package/dracut/busybox-init-module-setup.sh \
> +		$(HOST_DIR)/lib/dracut/modules.d/05busybox-init/module-setup.sh
> +endef
> +HOST_DRACUT_POST_INSTALL_HOOKS += HOST_DRACUT_POST_INSTALL_BUSYBOX_INIT_MODULE
> +endif
> +
> +$(eval $(host-autotools-package))
> diff --git a/package/dracut/dracut_wrapper.sh b/package/dracut/dracut_wrapper.sh
> new file mode 100644
> index 0000000000..3f58b0907e
> --- /dev/null
> +++ b/package/dracut/dracut_wrapper.sh
> @@ -0,0 +1,33 @@
> +#!/bin/bash
> +set -e
> +
> +# Find the --sysroot argument
> +sysroot=
> +next_arg=
> +for arg; do
> +	if [ "$next_arg" = 1 ]; then
> +		next_arg=
> +		sysroot="$arg"
> +		continue
> +	fi
> +
> +	case "$arg" in
> +	--sysroot=*)
> +		sysroot="${arg#*=}"
> +		;;
> +	--sysroot)
> +		next_arg=1
> +		;;
> +	esac
> +done
> +if [ -z "$sysroot" ]; then
> +	echo "$0: --sysroot argument must be given." 1>&2
> +	exit 1
> +fi
> +
> +topdir="$(dirname "$(realpath "$(dirname "$0")")")"
> +export DRACUT_LDD="$topdir/sbin/prelink-rtld --root='${sysroot}'"
> +export DRACUT_INSTALL="$topdir/lib/dracut/dracut-install"
> +export DRACUT_LDCONFIG=/bin/true
> +export dracutbasedir="$topdir/lib/dracut"
> +exec "$topdir/bin/dracut.real" "$@"
> diff --git a/package/dracut/libc-links-module-setup.sh b/package/dracut/libc-links-module-setup.sh
> new file mode 100755
> index 0000000000..e15b216e6e
> --- /dev/null
> +++ b/package/dracut/libc-links-module-setup.sh
> @@ -0,0 +1,27 @@
> +#!/bin/bash
> +
> +# Adds the missing links for uClibc or musl, if needed
> +
> +check() {
> +	return 0
> +}
> +
> +depends() {
> +	return 0
> +}
> +
> +install() {
> +	# Despite of the fact that the listed dependency (reported by readelf -d)
> +	# is purely /lib/libc.so, the musl symlink is needed anyway.
> +	musl_link="$(find "${dracutsysrootdir?}/lib" -name "ld-musl-*.so*")"
> +	if [ -n "$musl_link" ] ; then
> +		ln -s libc.so "${initdir?}/lib/$(basename "${musl_link}")"
> +	fi
> +
> +	# Same for uClibc, the listed dependency
> +	# is ld-uClibc.so.1, the loader needs the ld-uClibc.so.0, too
> +	uclibc_link="$(find "${dracutsysrootdir?}/lib" -name "ld-uClibc-*.so*")"
> +	if [ -n "$uclibc_link" ] ; then
> +		ln -s ld-uClibc.so.1 "${initdir?s}/lib/ld-uClibc.so.0"
> +	fi
> +}
> -- 
> 2.37.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool Arnout Vandecappelle (Essensium/Mind)
  2022-08-15 13:05   ` Yann E. MORIN
@ 2022-08-18 21:09   ` Yann E. MORIN
  1 sibling, 0 replies; 10+ messages in thread
From: Yann E. MORIN @ 2022-08-18 21:09 UTC (permalink / raw)
  To: Arnout Vandecappelle (Essensium/Mind)
  Cc: Adam Duskett, Thierry Bultel, buildroot

Arnout, Thierry, All,

On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
> From: Thierry Bultel <thierry.bultel@linatsea.fr>
> 
> Adds an option to invoke the dracut host tool, providing
> a configuration file, instead of having a full cpio archive
> of the whole target directory.
> 
> A default configuration file is provided. It assumes busybox init.
> ideally, a different default should be used in case of systemd init, but
> that's left for future work.
> 
> Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

Applied to next, with all the changes we discussed in this thread and
on IRC, thanks.

Regards,
Yann E. MORIN.

> ---
> Changes v1 -> v2 (suggested by Arnout and Yann)
>   - was a new fs type, now an option of cpio
>   - deals with the case of a build with no kernel
>   - gets the kernel name in a smarter way
>   - checks for the name of dracut configuration file
> Changes v2 -> v3
>   - fixed a typo on the --no-kernel option for dracut
>   - removed the unneeded dependency to kernel
>   - added tests for cpio, for both full, and dracut modes
> Changes v3 -> v4
>   - Config.in: applied Yann's comments on syntax and option in choice
>   - do no export TARGET_CROSS but give it in command line instead
>   - use $(ROOTFS_CPIO_DIR) as base for tmp directory
>   - let original, full cpio, first in the code, and dracut mode after
>   - removed unwanted comment in dracut.conf (in tests)
> Changes v4 -> v5 (Arnout)
>   - move runtime test to separate patch;
>   - fix check-package errors;
>   - add default dracut.conf file, the one from the runtime test;
>   - remove bash from dracut.conf;
>   - remove dependency on busybox or systemd init;
>   - add help text to BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE;
>   - use our compression instead of dracut's;
>   - still allow uimage;
>   - add --sysroot option in dracut call;
>   - adapt paths and environment according to changes in previous commit;
>   - use : instead of . to separate ifeq conditions;
>   - add support for reproducible (shared with cpio);
>   - use ROOTFS_CPIO_OPTS instead of ROOTFS_CPIO_DRACUT_CMD_OPTS;
>   - remove --keep option, isn't needed.
> ---
>  fs/cpio/Config.in   | 34 +++++++++++++++++
>  fs/cpio/cpio.mk     | 33 ++++++++++++++++
>  fs/cpio/dracut.conf | 93 +++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 160 insertions(+)
>  create mode 100644 fs/cpio/dracut.conf
> 
> diff --git a/fs/cpio/Config.in b/fs/cpio/Config.in
> index c1151a2881..de83aaad65 100644
> --- a/fs/cpio/Config.in
> +++ b/fs/cpio/Config.in
> @@ -7,6 +7,40 @@ config BR2_TARGET_ROOTFS_CPIO
>  
>  if BR2_TARGET_ROOTFS_CPIO
>  
> +choice
> +	prompt "cpio type"
> +	default BR2_TARGET_ROOTFS_CPIO_FULL
> +
> +config BR2_TARGET_ROOTFS_CPIO_FULL
> +	bool "cpio the whole root filesystem"
> +	help
> +	  Build a cpio archive containing the whole the root filesystem.
> +
> +config BR2_TARGET_ROOTFS_CPIO_DRACUT
> +	bool "Invoke dracut to make a partial initramfs"
> +	select BR2_PACKAGE_HOST_DRACUT
> +	select BR2_PACKAGE_HOST_UBOOT_TOOLS
> +	help
> +	  Build an additional initramfs using dracut. This only contains
> +	  a subset of the rootfs, as determined by the configuration
> +	  file.
> +	  This can be useful to create a recovery system, for instance.
> +
> +endchoice
> +
> +if BR2_TARGET_ROOTFS_CPIO_DRACUT
> +config BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE
> +	string "dracut configuration file"
> +	default "fs/cpio/dracut.conf"
> +	help
> +	  Dracut configuration file. It determines which parts of the
> +	  rootfs get included in the cpio image. See dracut.conf(5) or
> +	  https://github.com/dracutdevs/dracut/blob/master/man/dracut.conf.5.asc
> +
> +	  The default configuration file is suitable for busybox init.
> +	  It doesn't, however, pivot_root into a full rootfs.
> +endif
> +
>  choice
>  	prompt "Compression method"
>  	default BR2_TARGET_ROOTFS_CPIO_NONE
> diff --git a/fs/cpio/cpio.mk b/fs/cpio/cpio.mk
> index 81f8c393d1..b62d804ad8 100644
> --- a/fs/cpio/cpio.mk
> +++ b/fs/cpio/cpio.mk
> @@ -36,6 +36,8 @@ ROOTFS_CPIO_DEPENDENCIES += host-cpio
>  ROOTFS_CPIO_OPTS += --reproducible
>  endif
>  
> +ifeq ($(BR2_TARGET_ROOTFS_CPIO_FULL),y)
> +
>  define ROOTFS_CPIO_CMD
>  	cd $(TARGET_DIR) && \
>  	find . \
> @@ -44,6 +46,37 @@ define ROOTFS_CPIO_CMD
>  	> $@
>  endef
>  
> +else ifeq ($(BR2_TARGET_ROOTFS_CPIO_DRACUT),y)
> +
> +ROOTFS_CPIO_DEPENDENCIES += host-dracut
> +
> +ifeq ($(BR_BUILDING):$(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE),y:)
> +$(error No dracut config file name specified, check your BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE setting)
> +endif
> +
> +ifeq ($(BR2_LINUX_KERNEL),y)
> +ROOTFS_CPIO_DEPENDENCIES += linux
> +ROOTFS_CPIO_OPTS += --kver $(LINUX_VERSION_PROBED)
> +else
> +ROOTFS_CPIO_OPTS += --no-kernel
> +endif
> +
> +define ROOTFS_CPIO_CMD
> +	mkdir -p $(ROOTFS_CPIO_DIR)/tmp
> +
> +	$(HOST_DIR)/bin/dracut \
> +		$(ROOTFS_CPIO_OPTS) \
> +		-c $(BR2_TARGET_ROOTFS_CPIO_DRACUT_CONF_FILE) \
> +		--sysroot $(TARGET_DIR) \
> +		--tmpdir $(ROOTFS_CPIO_DIR)/tmp \
> +		-M \
> +		--force \
> +		--no-compress \
> +		$@
> +endef
> +
> +endif #BR2_TARGET_ROOTFS_CPIO_DRACUT
> +
>  ifeq ($(BR2_TARGET_ROOTFS_CPIO_UIMAGE),y)
>  ROOTFS_CPIO_DEPENDENCIES += host-uboot-tools
>  define ROOTFS_CPIO_UBOOT_MKIMAGE
> diff --git a/fs/cpio/dracut.conf b/fs/cpio/dracut.conf
> new file mode 100644
> index 0000000000..6184457723
> --- /dev/null
> +++ b/fs/cpio/dracut.conf
> @@ -0,0 +1,93 @@
> +#Simple dracut config for a system without systemd
> +
> +#Dracut configuration
> +
> +show_modules=yes
> +i18n_install_all=no
> +lvmconf=no
> +mdadmconf=no
> +early_microcode=no
> +hostonly=no
> +hostonly_cmdline=no
> +use_fstab=no
> +kernel_cmdline="rd.break=initqueue"
> +do_strip=no
> +
> +# Dracut modules needed
> +add_dracutmodules+=" \
> +busybox-init
> +"
> +
> +# Modules to ignore
> +omit_dracutmodules+=" \
> +bash \
> +biosdevname \
> +btrfs \
> +bluetooth \
> +busybox \
> +caps \
> +cifs \
> +crypt \
> +crypt-gpg \
> +dash \
> +dbus-broker \
> +dbus-daemon \
> +dm \
> +dmraid \
> +dmsquash-live-ntfs \
> +dracut-systemd \
> +fcoe \
> +fcoe-uefi \
> +fs-lib \
> +iscsi \
> +i18n \
> +lvmmerge \
> +lvm \
> +lunmask \
> +mdraid \
> +memstrack \
> +mksh \
> +modsign \
> +mount-root \
> +multipath \
> +nbd \
> +network-legacy \
> +network-wicked \
> +nfs \
> +nvdimm \
> +nvmf \
> +parse-lunmask \
> +qemu \
> +qemu-net \
> +resume \
> +rootfs-block \
> +rngd \
> +systemd \
> +systemd-udevd \
> +systemd-coredump \
> +systemd-ask-password \
> +systemd-timedated \
> +systemd-rfkill \
> +systemd-resolved \
> +systemd-hostnamed \
> +systemd-initrd \
> +systemd-journald \
> +systemd-ldconfig \
> +systemd-networkd \
> +systemd-timesyncd \
> +systemd-veritysetup \
> +systemd-modules-load \
> +systemd-sysctl \
> +systemd-repart \
> +systemd-sysext \
> +systemd-sysusers \
> +systemd-tmpfiles \
> +squash \
> +ssh-client \
> +stratis \
> +tpm2-tss \
> +udev-rules \
> +url-lib \
> +usrmount \
> +"
> +
> -- 
> 2.37.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Buildroot] [PATCH next v5 3/3] support/testing/tests/fs/test_cpio.py: new runtime test
  2022-08-15 11:17 ` [Buildroot] [PATCH next v5 3/3] support/testing/tests/fs/test_cpio.py: new runtime test Arnout Vandecappelle (Essensium/Mind)
@ 2022-08-18 21:10   ` Yann E. MORIN
  0 siblings, 0 replies; 10+ messages in thread
From: Yann E. MORIN @ 2022-08-18 21:10 UTC (permalink / raw)
  To: Arnout Vandecappelle (Essensium/Mind)
  Cc: Adam Duskett, Thierry Bultel, buildroot

Arnout, Thierry, All,

On 2022-08-15 13:17 +0200, Arnout Vandecappelle (Essensium/Mind) spake thusly:
> From: Thierry Bultel <thierry.bultel@linatsea.fr>
> 
> It includes a simple test for the full cpio image, and a test of the
> dracut image. To validate that the dracut image is a subset of the full
> image, 'pv' is added to the image, and the test verifies that pv is not
> part of the image. Note that the real rootfs is not mounted at the
> moment, so pv is never available in the running image.
> 
> Systemd and other init systems are currently untested.
> 
> Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

Applied to next, with all the changes we discussed in this thread and
on IRC, thanks.

Regards,
Yann E. MORIN.

> ---
> Changes v4 -> v5 (Arnout)
>   - move runtime test to separate patch;
>   - add tests for all libcs;
>   - remove tar;
>   - add pv and test that it's not included in cpio.
> ---
>  support/testing/tests/fs/test_cpio.py | 93 +++++++++++++++++++++++++++
>  1 file changed, 93 insertions(+)
>  create mode 100644 support/testing/tests/fs/test_cpio.py
> 
> diff --git a/support/testing/tests/fs/test_cpio.py b/support/testing/tests/fs/test_cpio.py
> new file mode 100644
> index 0000000000..98620ebc06
> --- /dev/null
> +++ b/support/testing/tests/fs/test_cpio.py
> @@ -0,0 +1,93 @@
> +import os
> +import infra.basetest
> +import subprocess
> +
> +CHECK_FS_CMD = "mount | grep 'rootfs on / type rootfs'"
> +
> +
> +def boot_img(emulator, builddir):
> +    img = os.path.join(builddir, "images", "rootfs.cpio")
> +    emulator.boot(arch="armv7",
> +                  kernel="builtin",
> +                  options=["-initrd", "{}".format(img)])
> +    emulator.login()
> +    _, exit_code = emulator.run(CHECK_FS_CMD)
> +    return exit_code
> +
> +
> +class TestCpioFull(infra.basetest.BRTest):
> +    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> +        """
> +        BR2_INIT_BUSYBOX=y
> +        BR2_TARGET_ROOTFS_CPIO=y
> +        BR2_TARGET_ROOTFS_CPIO_FULL=y
> +        # BR2_TARGET_ROOTFS_TAR is not set
> +        """
> +
> +    def test_run(self):
> +
> +        exit_code = boot_img(self.emulator,
> +                             self.builddir)
> +        self.assertEqual(exit_code, 0)
> +
> +
> +class TestCpioDracutBase(infra.basetest.BRTest):
> +    config = \
> +        """
> +        BR2_arm=y
> +        BR2_TOOLCHAIN_EXTERNAL=y
> +        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
> +        BR2_INIT_BUSYBOX=y
> +        BR2_PACKAGE_PV=y
> +        BR2_TARGET_ROOTFS_CPIO=y
> +        BR2_TARGET_ROOTFS_CPIO_DRACUT=y
> +        # BR2_TARGET_ROOTFS_TAR is not set
> +        """
> +
> +    def check_dracut(self):
> +        out = subprocess.check_output(["cpio", "--list"],
> +                                      stdin=open(os.path.join(self.builddir, "images/rootfs.cpio")),
> +                                      stderr=open(os.devnull, "w"),
> +                                      cwd=self.builddir,
> +                                      env={"LANG": "C"},
> +                                      universal_newlines=True)
> +        # pv should *not* be included in cpio image
> +        self.assertEqual(out.find("bin/pv"), -1)
> +
> +        exit_code = boot_img(self.emulator,
> +                             self.builddir)
> +        self.assertEqual(exit_code, 0)
> +
> +        # No pivot_root is done, so pv shouldn't be there
> +        _, exit_code = self.emulator.run("ls -l /usr/bin/pv")
> +        self.assertNotEqual(exit_code, 0)
> +
> +
> +class TestCpioDracutUclibc(TestCpioDracutBase):
> +    config = TestCpioDracutBase.config + \
> +        """
> +        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_UCLIBC_STABLE=y
> +        """
> +
> +    def test_run(self):
> +        self.check_dracut()
> +
> +
> +class TestCpioDracutGlibc(TestCpioDracutBase):
> +    config = TestCpioDracutBase.config + \
> +        """
> +        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_GLIBC_STABLE=y
> +        """
> +
> +    def test_run(self):
> +        self.check_dracut()
> +
> +
> +class TestCpioDracutMusl(TestCpioDracutBase):
> +    config = TestCpioDracutBase.config + \
> +        """
> +        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV5_EABI_MUSL_STABLE=y
> +        """
> +
> +    def test_run(self):
> +        self.check_dracut()
> -- 
> 2.37.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-08-18 21:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 11:17 [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Arnout Vandecappelle (Essensium/Mind)
2022-08-15 11:17 ` [Buildroot] [PATCH next v5 2/3] fs/cpio: new option to use dracut tool Arnout Vandecappelle (Essensium/Mind)
2022-08-15 13:05   ` Yann E. MORIN
2022-08-15 16:37     ` Arnout Vandecappelle
2022-08-18 21:09   ` Yann E. MORIN
2022-08-15 11:17 ` [Buildroot] [PATCH next v5 3/3] support/testing/tests/fs/test_cpio.py: new runtime test Arnout Vandecappelle (Essensium/Mind)
2022-08-18 21:10   ` Yann E. MORIN
2022-08-15 12:36 ` [Buildroot] [PATCH next v5 1/3] package/dracut: new host package Yann E. MORIN
2022-08-15 16:27   ` Arnout Vandecappelle via buildroot
2022-08-18 21:09 ` Yann E. MORIN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.