diff mbox series

[next,v5,2/3] fs/cpio: new option to use dracut tool

Message ID 20220815111710.1459820-2-arnout@mind.be
State Accepted
Headers show
Series [next,v5,1/3] package/dracut: new host package | expand

Commit Message

Arnout Vandecappelle Aug. 15, 2022, 11:17 a.m. UTC
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

Comments

Yann E. MORIN Aug. 15, 2022, 1:05 p.m. UTC | #1
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.
Arnout Vandecappelle Aug. 15, 2022, 4:37 p.m. UTC | #2
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.
>
Yann E. MORIN Aug. 18, 2022, 9:09 p.m. UTC | #3
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
diff mbox series

Patch

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 \
+"
+