Re: [Buildroot] [PATCH 3/3] fs/dracut: new fs type
From: Arnout Vandecappelle <hidden>
Date: 2021-12-16 20:49:54
On 15/12/2021 19:00, Thierry Bultel wrote:
quoted hunk ↗ jump to hunk
Adds an option to build an initramfs image, using the dracut host tool. Signed-off-by: Thierry Bultel <redacted> --- 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.mkdiff --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
Don't add "default n", it's the default :-)
+ 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"
Is there a possibility for a default configuration file?
quoted hunk ↗ jump to hunk
+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
The above is the same logic as in cpio.mk. It would be better if we could refactor that to a common place.
+ +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 \
It would be nice if all of the above could be patches into host-dracut, so when called from a post-image script, it's not needed to pass all of that in. You should also check then if it gets properly updated by support/misc/relocate-sdk.sh (I think yes).
+ dracutsysrootdir=$(TARGET_DIR) \ + $(HOST_DIR)/bin/dracut \ + --kver $(BR2_LINUX_KERNEL_VERSION).0 \
This should be indented with a second tab. Also, you can't use BR2_LINUX_KERNEL_VERSION because that's only available if BR2_LINUX_KERNEL=y. So either you have to depend on that, or you need to add an option to Config.in to be able to set it. Also, you should probably use LINUX_VERSION_PROBED instead (at least if you need an actual kernel version, and not some commit hash or something). Also, what is the .0 appended to it?
+ -c $(BR2_TARGET_ROOTFS_DRACUT_CONF_FILE) \
We normally have a check in the makefile to exit immediately if the option is not set. See for example in linux-backports. Note that it needs to be in a BR_BUILDING condition. Regards, Arnout
+ --tmpdir $(@D)/tmp \ + -M \ + --force \ + --keep \ + $@ + +endef + +$(eval $(rootfs))
_______________________________________________ buildroot mailing list buildroot@buildroot.org https://lists.buildroot.org/mailman/listinfo/buildroot