[Buildroot] [PATCH 3/3] fs/dracut: new fs type

Thierry Bultel thierry.bultel at linatsea.fr
Wed Dec 15 18:00:21 UTC 2021


Adds an option to build an initramfs image,
using the dracut host tool.

Signed-off-by: Thierry Bultel <thierry.bultel at linatsea.fr>
---
 fs/Config.in        |  1 +
 fs/dracut/Config.in | 13 +++++++++++
 fs/dracut/dracut.mk | 55 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
 create mode 100644 fs/dracut/Config.in
 create mode 100644 fs/dracut/dracut.mk

diff --git a/fs/Config.in b/fs/Config.in
index eee5e26bb2..3938f3b9a7 100644
--- a/fs/Config.in
+++ b/fs/Config.in
@@ -5,6 +5,7 @@ source "fs/btrfs/Config.in"
 source "fs/cloop/Config.in"
 source "fs/cpio/Config.in"
 source "fs/cramfs/Config.in"
+source "fs/dracut/Config.in"
 source "fs/erofs/Config.in"
 source "fs/ext2/Config.in"
 source "fs/f2fs/Config.in"
diff --git a/fs/dracut/Config.in b/fs/dracut/Config.in
new file mode 100644
index 0000000000..ee4220def8
--- /dev/null
+++ b/fs/dracut/Config.in
@@ -0,0 +1,13 @@
+config BR2_TARGET_ROOTFS_DRACUT
+	bool "Invoke dracut to make an initramfs"
+	default n
+	select BR2_PACKAGE_HOST_DRACUT
+	select BR2_PACKAGE_HOST_UBOOT_TOOLS
+	help
+	  Builds an additional initramfs using dracut. This can be useful to create a recovery system, for instance.
+	
+if BR2_TARGET_ROOTFS_DRACUT
+config BR2_TARGET_ROOTFS_DRACUT_CONF_FILE
+	string "configuration file"
+endif
+
diff --git a/fs/dracut/dracut.mk b/fs/dracut/dracut.mk
new file mode 100644
index 0000000000..9c91150e82
--- /dev/null
+++ b/fs/dracut/dracut.mk
@@ -0,0 +1,55 @@
+################################################################################
+#
+# dracut to archive target filesystem
+#
+################################################################################
+
+ROOTFS_DRACUT_DEPENDENCIES = host-dracut host-uboot-tools
+
+ifeq ($(BR2_ROOTFS_DEVICE_CREATION_STATIC),y)
+
+define ROOTFS_DRACUT_ADD_INIT
+	if [ ! -e $(TARGET_DIR)/init ]; then \
+		ln -sf sbin/init $(TARGET_DIR)/init; \
+	fi
+endef
+
+else
+
+# devtmpfs does not get automounted when initramfs is used.
+# Add a pre-init script to mount it before running init
+# We must have /dev/console very early, even before /init runs,
+# for stdin/stdout/stderr
+define ROOTFS_DRACUT_ADD_INIT
+	if [ ! -e $(TARGET_DIR)/init ]; then \
+		$(INSTALL) -m 0755 fs/cpio/init $(TARGET_DIR)/init; \
+	fi
+	mkdir -p $(TARGET_DIR)/dev
+	mknod -m 0622 $(TARGET_DIR)/dev/console c 5 1
+endef
+
+endif # BR2_ROOTFS_DEVICE_CREATION_STATIC
+
+ROOTFS_DRACUT_PRE_GEN_HOOKS += ROOTFS_DRACUT_ADD_INIT
+
+define ROOTFS_DRACUT_CMD
+
+	mkdir -p $(@D)/tmp
+	rm -rf $(@D)/tmp/*
+
+	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 \
+	--kver $(BR2_LINUX_KERNEL_VERSION).0 \
+	-c $(BR2_TARGET_ROOTFS_DRACUT_CONF_FILE) \
+	--tmpdir $(@D)/tmp \
+	-M \
+	--force \
+	--keep \
+	$@
+
+endef
+
+$(eval $(rootfs))
-- 
2.25.1




More information about the buildroot mailing list