diff mbox series

[v2,2/3] package/dracut: new host package

Message ID 20211219073119.1087539-2-thierry.bultel@linatsea.fr
State Superseded
Headers show
Series [v2,1/3] package/cross-ldd: new package | expand

Commit Message

Thierry Bultel Dec. 19, 2021, 7:31 a.m. UTC
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
---
 package/Config.in.host           |  1 +
 package/dracut/Config.in.host    | 10 ++++++++++
 package/dracut/dracut.mk         | 28 ++++++++++++++++++++++++++++
 package/dracut/dracut_wrapper.sh | 14 ++++++++++++++
 4 files changed, 53 insertions(+)
 create mode 100644 package/dracut/Config.in.host
 create mode 100644 package/dracut/dracut.mk
 create mode 100644 package/dracut/dracut_wrapper.sh
diff mbox series

Patch

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/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..ada9e1d691
--- /dev/null
+++ b/package/dracut/dracut.mk
@@ -0,0 +1,28 @@ 
+################################################################################
+#
+# 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
+
+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..388086762c
--- /dev/null
+++ b/package/dracut/dracut_wrapper.sh
@@ -0,0 +1,14 @@ 
+#!/bin/bash
+
+set -e
+
+if [ -z "$*" ]; then
+    echo "No argument supplied"
+    exit
+fi
+
+DRACUT_LDD=${TARGET_CROSS}ldd \
+DRACUT_INSTALL="${HOST_DIR}/lib/dracut/dracut-install" \
+dracutbasedir=${HOST_DIR}/usr/lib/dracut \
+dracutsysrootdir=${TARGET_DIR} \
+${HOST_DIR}/bin/dracut "$@"