All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Bultel <thierry.bultel@linatsea.fr>
To: buildroot@buildroot.org
Cc: Thierry Bultel <thierry.bultel@linatsea.fr>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [Buildroot] [PATCH v3 2/3] package/dracut: new host package
Date: Thu, 23 Dec 2021 12:13:47 +0100	[thread overview]
Message-ID: <20211223111348.3532601-2-thierry.bultel@linatsea.fr> (raw)
In-Reply-To: <20211223111348.3532601-1-thierry.bultel@linatsea.fr>

dracut is the tool used by desktop distributions to
build initrds. In the embedded world, it can be
very usefull, 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,
the idea is to use dracut to 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.

Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
---
Changes v1 -> v2 (all suggested by Arnoult)
  - added a wrapper script
Changes v2 -> v2
  - added modules for:
     - supporting busybox system init type
     - fixing a missing symlink for uClibc

Signed-off-by: Thierry Bultel <thierry.bultel@linatsea.fr>
---
 package/Config.in.host                        |  1 +
 .../05busybox-buildroot/module-setup.sh       | 69 +++++++++++++++++++
 package/dracut/06uclibc/module-setup.sh       | 20 ++++++
 package/dracut/Config.in.host                 | 10 +++
 package/dracut/dracut.mk                      | 45 ++++++++++++
 package/dracut/dracut_wrapper.sh              | 15 ++++
 6 files changed, 160 insertions(+)
 create mode 100755 package/dracut/05busybox-buildroot/module-setup.sh
 create mode 100644 package/dracut/06uclibc/module-setup.sh
 create mode 100644 package/dracut/Config.in.host
 create mode 100644 package/dracut/dracut.mk
 create mode 100644 package/dracut/dracut_wrapper.sh

diff --git a/package/Config.in.host b/package/Config.in.host
index 6e5a5c5fc5..72531374f4 100644
--- a/package/Config.in.host
+++ b/package/Config.in.host
@@ -14,6 +14,7 @@ menu "Host utilities"
 	source "package/cramfs/Config.in.host"
 	source "package/cryptsetup/Config.in.host"
 	source "package/dbus-python/Config.in.host"
+	source "package/dracut/Config.in.host"
 	source "package/dfu-util/Config.in.host"
 	source "package/dos2unix/Config.in.host"
 	source "package/dosfstools/Config.in.host"
diff --git a/package/dracut/05busybox-buildroot/module-setup.sh b/package/dracut/05busybox-buildroot/module-setup.sh
new file mode 100755
index 0000000000..b227571db4
--- /dev/null
+++ b/package/dracut/05busybox-buildroot/module-setup.sh
@@ -0,0 +1,69 @@
+#!/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 -s lib $initdir/lib64
+		ln -s lib $initdir/usr/lib64
+	fi
+
+	if [ -e $dracutsysrootdir/lib32 ]; then
+		ln -s lib $initdir/lib32
+		ln -s lib $initdir/usr/lib32
+	fi
+	
+	install_busybox_links "/bin" "busybox"
+	install_busybox_links "/sbin" "../bin/busybox"
+	install_busybox_links "/usr/bin" "../../bin/busybox" 
+	install_busybox_links "/usr/sbin" "../../bin/busybox"
+	
+	inst_multiple \
+		/etc/inittab	\
+		/etc/init.d/rcS \
+		/etc/init.d/rcK \
+		/etc/issue	\
+		/etc/fstab	\
+		/etc/group	\
+		/etc/passwd	\
+		/etc/shadow	\
+		/etc/hostname
+	
+#	mkdir -p $initdir/etc/init.d
+#	cp -a $dracutsysrootdir/etc/init.d/* $initdir/etc/init.d
+	
+}
+
diff --git a/package/dracut/06uclibc/module-setup.sh b/package/dracut/06uclibc/module-setup.sh
new file mode 100644
index 0000000000..77e9bd864e
--- /dev/null
+++ b/package/dracut/06uclibc/module-setup.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+check() {
+	return 0
+}
+
+depends() {
+	return 0
+}
+
+
+
+install() {
+
+	# Despite of the fact that the listed dependency (reported by readelf -d)
+	# is purely ld-uClibc.so.1, the loader needs the ld-uClibc.so.0, too
+
+	ln -s ld-uClibc.so.1 $initdir/lib/ld-uClibc.so.0
+
+}
diff --git a/package/dracut/Config.in.host b/package/dracut/Config.in.host
new file mode 100644
index 0000000000..074d46f623
--- /dev/null
+++ b/package/dracut/Config.in.host
@@ -0,0 +1,10 @@
+config BR2_PACKAGE_HOST_DRACUT
+	bool
+	select BR2_PACKAGE_HOST_KMOD
+	select BR2_PACKAGE_HOST_CROSS_LDD
+	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/dracut.mk b/package/dracut/dracut.mk
new file mode 100644
index 0000000000..6c82b4ba75
--- /dev/null
+++ b/package/dracut/dracut.mk
@@ -0,0 +1,45 @@
+################################################################################
+#
+# 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-cross-ldd
+
+define HOST_DRACUT_POST_INSTALL_ENABLE_FAKEROOT
+	$(SED) '/unset LD_LIBRARY_PATH/d' $(HOST_DIR)/bin/dracut
+	$(SED) '/unset LD_PRELOAD/d' $(HOST_DIR)/bin/dracut
+endef
+
+define HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
+	$(INSTALL) -D -m 0755 package/dracut/dracut_wrapper.sh \
+		$(HOST_DIR)/usr/bin/dracut_wrapper.sh
+endef
+
+ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
+define HOST_DRACUT_POST_INSTALL_UCLIBC_MODULE
+	$(INSTALL) -D -m 0755 package/dracut/06uclibc/module-setup.sh \
+		$(HOST_DIR)/lib/dracut/modules.d/06uclibc/module-setup.sh
+endef
+HOST_DRACUT_POST_INSTALL_HOOKS+=HOST_DRACUT_POST_INSTALL_UCLIBC_MODULE
+endif
+
+ifeq ($(BR2_INIT_BUSYBOX),y)
+define HOST_DRACUT_POST_INSTALL_BUSYBOX_MODULE
+	$(INSTALL) -D -m 0755 package/dracut/05busybox-buildroot/module-setup.sh \
+		$(HOST_DIR)/lib/dracut/modules.d/05busybox-buildroot/module-setup.sh
+endef
+HOST_DRACUT_POST_INSTALL_HOOKS+=HOST_DRACUT_POST_INSTALL_BUSYBOX_MODULE
+
+endif
+
+HOST_DRACUT_POST_INSTALL_HOOKS+=HOST_DRACUT_POST_INSTALL_ENABLE_FAKEROOT
+HOST_DRACUT_POST_INSTALL_HOOKS+=HOST_DRACUT_POST_INSTALL_WRAPPER_SCRIPT
+
+$(eval $(host-autotools-package))
diff --git a/package/dracut/dracut_wrapper.sh b/package/dracut/dracut_wrapper.sh
new file mode 100644
index 0000000000..9d3db3b58e
--- /dev/null
+++ b/package/dracut/dracut_wrapper.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -e
+set -x
+
+if [ -z "$*" ]; then
+    echo "No argument supplied"
+    exit
+fi
+
+DRACUT_LDD=${TARGET_CROSS}ldd-cross \
+DRACUT_INSTALL="${HOST_DIR}/lib/dracut/dracut-install" \
+dracutbasedir=${HOST_DIR}/usr/lib/dracut \
+dracutsysrootdir=${TARGET_DIR} \
+${HOST_DIR}/bin/dracut "$@"
-- 
2.25.1

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

  reply	other threads:[~2021-12-23 11:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 11:13 [Buildroot] [PATCH v3 1/3] package/cross-ldd: new package Thierry Bultel
2021-12-23 11:13 ` Thierry Bultel [this message]
2022-01-05 23:16   ` [Buildroot] [PATCH v3 2/3] package/dracut: new host package Yann E. MORIN
2022-01-06 14:56     ` Thierry Bultel
2022-01-06 15:13       ` Thomas Petazzoni
2022-01-06 15:56         ` Thierry Bultel
2021-12-23 11:13 ` [Buildroot] [PATCH v3 3/3] fs/cpio: new option to use dracut tool Thierry Bultel
2022-01-06 10:31   ` Yann E. MORIN
2022-01-06 13:48     ` Thierry Bultel
2022-01-05 22:29 ` [Buildroot] [PATCH v3 1/3] package/cross-ldd: new package Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211223111348.3532601-2-thierry.bultel@linatsea.fr \
    --to=thierry.bultel@linatsea.fr \
    --cc=buildroot@buildroot.org \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.