Move tool for generating initramfs cpio to scripts/
Subsystems (8)
Nicolas Schier
maintainerv3 cover Move tool for generating initramfs cpio to scripts/
initramfs cpio tools had been subject of several recent discussions on linux-kbuild. Let's get two minor steps forward by enabling a top-level target for building gen_init_cpio w/o the need of a valid kbuild configuration [1] and move the tools for generating the built-in initramfs from usr/ to scripts/ [2].
---
Changes in v3:
* Update various remaining usr/gen_init* references treewide (Nathan)
* Link to v2: https://patch.msgid.link/20260720-move-gen_init_cpio-to-scripts-v2-0-26b7e15c7133@kernel.org
Changes in v2:
* Build gen_init_cpio only if CONFIG_BLK_DEV_INITRD (Thomas)
* Keep underscore top-level target name (scripts_gen_init_cpio)
(Thomas)
* Link to v1: https://patch.msgid.link/20260309-move-gen_init_cpio-to-scripts-v1-0-0c5059b1ec5b@kernel.org
To: Nathan Chancellor <[email protected]>
To: Nicolas Schier <[email protected]>
To: Jonathan Corbet <[email protected]>
To: Shuah Khan <[email protected]>
To: Randy Dunlap <[email protected]>
To: Luis Augenstein <[email protected]>
To: Maximilian Huber <[email protected]>
To: Mike Rapoport <[email protected]>
To: Pasha Tatashin <[email protected]>
To: Pratyush Yadav <[email protected]>
To: Alexander Graf <[email protected]>
To: Willy Tarreau <[email protected]>
To: Thomas Weißschuh <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
Nicolas Schier (2):
kbuild: Mark usr_gen_init_cpio as no-dot-config-target
kbuild: Move gen_init_cpio and gen_initramfs.sh to scripts/
.../early-userspace/early_userspace_support.rst | 16 ++++++++--------
Documentation/filesystems/ramfs-rootfs-initramfs.rst | 10 +++++-----
MAINTAINERS | 1 +
Makefile | 9 +++++----
scripts/.gitignore | 1 +
scripts/Makefile | 3 +++
scripts/Makefile.package | 2 +-
{usr => scripts}/gen_init_cpio.c | 0
{usr => scripts}/gen_initramfs.sh | 2 +-
scripts/remove-stale-files | 2 ++
scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py | 2 +-
tools/testing/selftests/kho/vmtest.sh | 2 +-
tools/testing/selftests/nolibc/Makefile.nolibc | 2 +-
usr/.gitignore | 4 +++-
usr/Kconfig | 2 +-
usr/Makefile | 4 +---
16 files changed, 35 insertions(+), 27 deletions(-)---
base-commit: 93f51579e7df248780214094418f205253383cc5
change-id: 20260225-move-gen_init_cpio-to-scripts-9e89ef99e51a
Best regards,
Signature · 1 line
Nicolas
Nicolas Schier
maintainerPATCH v3 1/2 kbuild: Mark usr_gen_init_cpio as no-dot-config-target
Let usr/gen_init_cpio be built also if there is no kernel configuration.
Askar Safin reported that gen_init_cpio may be of use before any kernel configuration is available. Add usr_gen_init_cpio to list of targets that do not require a .config file.
--- Makefile | 1 + 1 file changed, 1 insertion(+)
Makefile +1 -0
@@ -298,6 +298,7 @@ no-dot-config-targets := $(clean-targets) \ %asm-generic kernelversion %src-pkg dt_binding_check \ dt_style_selftest \ outputmakefile rustavailable rustfmt rustfmtcheck \ + usr_gen_init_cpio \ run-command no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_name
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v3 1/2] kbuild: Mark usr_gen_init_cpio as no-dot-config-target
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines
Let
usr/gen_init_cpiobe built also if there is no kernel configuration.Askar Safin reported that
gen_init_cpiomay be of use before any kernel configuration is available. Addusr_gen_init_cpioto list of targets that do not require a .config file.Reported-by Askar Safin <[email protected]>Fixes f8e05c10631e ("kbuild: Add top-level target for building gen_init_cpio")Signed-off-by Nicolas Schier <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260925-move-gen_init_cpio-to-scripts-v3-1-99c493f76722@kernel.org?part=1
Nicolas Schier
maintainerPATCH v3 2/2 kbuild: Move gen_init_cpio and gen_initramfs.sh to scripts/
In reply to Nicolas Schiergen_init_cpio and gen_initramfs.sh are part of kbuild and required for all kernel builds w/ CONFIG_BLK_DEV_INITRD. Move both to scripts/ to be more clear about their importance.
---
Changes in v3:
* Update other references to usr/gen_init* (Nathan)
---
.../early-userspace/early_userspace_support.rst | 16 ++++++++--------
Documentation/filesystems/ramfs-rootfs-initramfs.rst | 10 +++++-----
MAINTAINERS | 1 +
Makefile | 10 +++++-----
scripts/.gitignore | 1 +
scripts/Makefile | 3 +++
scripts/Makefile.package | 2 +-
{usr => scripts}/gen_init_cpio.c | 0
{usr => scripts}/gen_initramfs.sh | 2 +-
scripts/remove-stale-files | 2 ++
scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py | 2 +-
tools/testing/selftests/kho/vmtest.sh | 2 +-
tools/testing/selftests/nolibc/Makefile.nolibc | 2 +-
usr/.gitignore | 4 +++-
usr/Kconfig | 2 +-
usr/Makefile | 4 +---
16 files changed, 35 insertions(+), 28 deletions(-)Documentation/driver-api/early-userspace/early_userspace_support.rst +8 -8
@@ -55,9 +55,9 @@ user root (0). INITRAMFS_ROOT_GID can be set to a group ID that needs to be mapped to group root (0). A source file must be directives in the format required by the -usr/gen_init_cpio utility (run 'usr/gen_init_cpio -h' to get the +scripts/gen_init_cpio utility (run 'scripts/gen_init_cpio -h' to get the file format). The directives in the file will be passed directly to -usr/gen_init_cpio. +scripts/gen_init_cpio. When a combination of directories and files are specified then the initramfs image will be an aggregate of all of them. In this way a user
@@ -69,17 +69,17 @@ early userspace image can be built by an unprivileged user. As a technical note, when directories and files are specified, the entire CONFIG_INITRAMFS_SOURCE is passed to -usr/gen_initramfs.sh. This means that CONFIG_INITRAMFS_SOURCE +scripts/gen_initramfs.sh. This means that CONFIG_INITRAMFS_SOURCE can really be interpreted as any legal argument to gen_initramfs.sh. If a directory is specified as an argument then the contents are scanned, uid/gid translation is performed, and -usr/gen_init_cpio file directives are output. If a file is -specified as an argument to usr/gen_initramfs.sh then the +scripts/gen_init_cpio file directives are output. If a file is +specified as an argument to scripts/gen_initramfs.sh then the contents of the file are simply copied to the output. All of the output directives from directory scanning and file contents copying are -processed by usr/gen_init_cpio. +processed by scripts/gen_init_cpio. -See also 'usr/gen_initramfs.sh -h'. +See also 'scripts/gen_initramfs.sh -h'. Where's this all leading? =========================
@@ -142,7 +142,7 @@ b) some device and filesystem drivers built as modules and stored in an c) using initramfs. The call to prepare_namespace() must be skipped. This means that a binary must do all the work. Said binary can be stored - into initramfs either via modifying usr/gen_init_cpio.c or via the new + into initramfs either via modifying scripts/gen_init_cpio.c or via the new initrd format, an cpio archive. It must be called "/init". This binary is responsible to do all the things prepare_namespace() would do.
Documentation/filesystems/ramfs-rootfs-initramfs.rst +5 -5
@@ -155,7 +155,7 @@ specification such as the following example:: dir /mnt 755 0 0 file /init initramfs/init.sh 755 0 0 -Run "usr/gen_init_cpio" (after the kernel build) to get a usage message +Run "scripts/gen_init_cpio" (after the kernel build) to get a usage message documenting the above file format. One advantage of the configuration file is that root access is not required to
@@ -167,9 +167,9 @@ Documentation/driver-api/early-userspace/early_userspace_support.rst for more de The kernel does not depend on external cpio tools. If you specify a directory instead of a configuration file, the kernel's build infrastructure creates a configuration file from that directory (usr/Makefile calls -usr/gen_initramfs.sh), and proceeds to package up that directory -using the config file (by feeding it to usr/gen_init_cpio, which is created -from usr/gen_init_cpio.c). The kernel's build-time cpio creation code is +scripts/gen_initramfs.sh), and proceeds to package up that directory +using the config file (by feeding it to scripts/gen_init_cpio, which is created +from scripts/gen_init_cpio.c). The kernel's build-time cpio creation code is entirely self-contained, and the kernel's boot-time extractor is also (obviously) self-contained.
@@ -313,7 +313,7 @@ the above threads) is: 2) The cpio archive format chosen by the kernel is simpler and cleaner (and thus easier to create and parse) than any of the (literally dozens of) various tar archive formats. The complete initramfs archive format is - explained in buffer-format.rst, created in usr/gen_init_cpio.c, and + explained in buffer-format.rst, created in scripts/gen_init_cpio.c, and extracted in init/initramfs.c. All three together come to less than 26k total of human-readable text.
MAINTAINERS +1 -0
@@ -14139,6 +14139,7 @@ F: scripts/basic/ F: scripts/clang-tools/ F: scripts/container F: scripts/dummy-tools/ +F: scripts/gen_init* F: scripts/include/ F: scripts/install.sh F: scripts/mk*
Makefile +5 -5
@@ -298,7 +298,7 @@ no-dot-config-targets := $(clean-targets) \ %asm-generic kernelversion %src-pkg dt_binding_check \ dt_style_selftest \ outputmakefile rustavailable rustfmt rustfmtcheck \ - usr_gen_init_cpio \ + scripts_gen_init_cpio \ run-command no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_name
@@ -1529,9 +1529,9 @@ ifdef CONFIG_HEADERS_INSTALL prepare: headers endif -PHONY += usr_gen_init_cpio -usr_gen_init_cpio: scripts_basic - $(Q)$(MAKE) $(build)=usr usr/gen_init_cpio +PHONY += scripts_gen_init_cpio +scripts_gen_init_cpio: scripts_basic + $(Q)$(MAKE) $(build)=scripts scripts/gen_init_cpio PHONY += scripts_unifdef scripts_unifdef: scripts_basic
@@ -1832,7 +1832,7 @@ distclean: mrproper # Packaging of the kernel to various formats # --------------------------------------------------------------------------- -modules-cpio-pkg: usr_gen_init_cpio +modules-cpio-pkg: scripts_gen_init_cpio %src-pkg: FORCE $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
scripts/.gitignore +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only /asn1_compiler +/gen_init_cpio /gen_packed_field_checks /generate_rust_target /insert-sys-cert
scripts/Makefile +3 -0
@@ -53,6 +53,9 @@ ifdef CONFIG_BUILDTIME_MCOUNT_SORT HOSTCFLAGS_sorttable.o += -DMCOUNT_SORT_ENABLED endif +hostprogs += gen_init_cpio +always-$(CONFIG_BLK_DEV_INITRD) += gen_init_cpio + # The following programs are only built on demand hostprogs += unifdef gen_packed_field_checks
scripts/Makefile.package +1 -1
@@ -198,7 +198,7 @@ tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@/$(INSTALL_MOD_PATH) modules_install quiet_cmd_cpio = CPIO $@ - cmd_cpio = $(CONFIG_SHELL) $(srctree)/usr/gen_initramfs.sh -o $@ $< + cmd_cpio = $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs.sh -o $@ $< modules-$(KERNELRELEASE)-$(ARCH).cpio: .tmp_modules_cpio $(call cmd,cpio)
scripts/gen_init_cpio.c renamed from usr/gen_init_cpio.c +0 -0
scripts/gen_initramfs.sh renamed from usr/gen_initramfs.sh +1 -1
@@ -247,4 +247,4 @@ done # If output_file is set we will generate cpio archive # we are careful to delete tmp files -usr/gen_init_cpio $output $timestamp $cpio_list +scripts/gen_init_cpio $output $timestamp $cpio_list
scripts/remove-stale-files +2 -0
@@ -26,3 +26,5 @@ rm -f scripts/selinux/genheaders/genheaders rm -f *.spec rm -f lib/test_fortify.log + +rm -f usr/gen_init_cpio
scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py +1 -1
@@ -338,7 +338,7 @@ class TestSavedCmdParser(unittest.TestCase): # gen_initramfs.sh command tests def test_gen_initramfs(self): - cmd = "sh ../usr/gen_initramfs.sh -o usr/initramfs_data.cpio -l usr/.initramfs_data.cpio.d ../usr/default_cpio_list" + cmd = "sh ../scripts/gen_initramfs.sh -o usr/initramfs_data.cpio -l usr/.initramfs_data.cpio.d ../usr/default_cpio_list" expected = "../usr/default_cpio_list" self._assert_parsing(cmd, expected)
tools/testing/selftests/kho/vmtest.sh +1 -1
@@ -100,7 +100,7 @@ file /init $tmp_dir/init 0755 0 0 file /kernel $kernel 0644 0 0 EOF - "$build_dir/usr/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd" + "$build_dir/scripts/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd" } function run_qemu() {
tools/testing/selftests/nolibc/Makefile.nolibc +1 -1
@@ -295,7 +295,7 @@ run-user: nolibc-test $(Q)$(REPORT) $(CURDIR)/run.out initramfs.cpio: kernel nolibc-test - $(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(objtree)/usr/gen_init_cpio - > initramfs.cpio + $(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(objtree)/scripts/gen_init_cpio - > initramfs.cpio initramfs: nolibc-test $(QUIET_MKDIR)mkdir -p initramfs
usr/.gitignore +3 -1
@@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -/gen_init_cpio /initramfs_data.cpio /initramfs_inc_data + +# Keep around until cleanup in scripts/remove-stale-files +/gen_init_cpio
usr/Kconfig +1 -1
@@ -13,7 +13,7 @@ config INITRAMFS_SOURCE to be used as an initramfs image. Directories should contain a filesystem layout to be included in the initramfs image. Files should contain entries according to the format described by the - "usr/gen_init_cpio" program in the kernel tree. + "scripts/gen_init_cpio" program in the kernel tree. When multiple directories and files are specified then the initramfs image will be the aggregate of all of them.
usr/Makefile +1 -3
@@ -16,8 +16,6 @@ obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o $(obj)/initramfs_data.o: $(obj)/initramfs_inc_data -hostprogs := gen_init_cpio - ramfs-input := $(CONFIG_INITRAMFS_SOURCE) cpio-data :=
@@ -72,7 +70,7 @@ quiet_cmd_initfs = GEN $@ # 2) There are changes in which files are included (added or deleted) # 3) If gen_init_cpio are newer than initramfs_data.cpio # 4) Arguments to gen_initramfs.sh changes -$(obj)/initramfs_data.cpio: $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE +$(obj)/initramfs_data.cpio: $(srctree)/scripts/gen_initramfs.sh scripts/gen_init_cpio $(deps_initramfs) FORCE $(call if_changed,initfs) endif
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v3 2/2] kbuild: Move gen_init_cpio and gen_initramfs.sh to scripts/
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] selftests/liveupdate: vmtest.sh mkinitrd fails due to missing gen_init_cpio - [Low] kbuild…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] selftests/liveupdate: vmtest.sh mkinitrd fails due to missing gen_init_cpio
- [Low] kbuild: stale comment in gen_initramfs.sh assumes old usr/ location --
commit 97c7fb8e47f1b247f157846cfecd29ff5f239ed1
Author: Nicolas Schier <[email protected]>
kbuild: Move gen_init_cpio and gen_initramfs.sh to scripts/
gen_init_cpio and gen_initramfs.sh are part of kbuild and required for all kernel builds w/ CONFIG_BLK_DEV_INITRD. Move both to scripts/ to be more clear about their importance.
tools/testing/selftests/kho/vmtest.sh file /init $tmp_dir/init 0755 0 0 · line 104
Quoted 11 lines
tools/testing/selftests/kho/vmtest.sh +1
-1@@ -100,7 +100,7 @@ file /init $tmp_dir/init 0755 0 0 file /kernel $kernel 0644 0 0 EOF - "$build_dir/usr/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd" + "$build_dir/scripts/gen_init_cpio" "$tmp_dir/cpio_list" > "$initrd" }
[Severity: Medium]
The path for the kho selftest was updated, but it looks like tools/testing/selftests/liveupdate/vmtest.sh also still calls the old path.
For example, in its mkinitrd():
# Generate inner_initrd.cpio
"$build_dir/usr/gen_init_cpio" "$workspace_dir/cpio_list_inner" > "$workspace_dir/inner_initrd.cpio"
and again later in the same function:
# Generate the final initrd "$build_dir/usr/gen_init_cpio" "$workspace_dir/cpio_list" > "$initrd"
Since this patch ensures the old artifact is removed via scripts/remove-stale-files, will the liveupdate selftest unconditionally fail because it cannot find gen_init_cpio?
Should liveupdate/vmtest.sh be updated to use scripts/gen_init_cpio as well?
scripts/gen_initramfs.sh done · line 250
Quoted 13 lines
scripts/gen_initramfs.sh renamed from usr/gen_initramfs.sh +1
-1@@ -247,4 +247,4 @@ done # If output_file is set we will generate cpio archive # we are careful to delete tmp files -usr/gen_init_cpio $output $timestamp $cpio_list +scripts/gen_init_cpio $output $timestamp $cpio_list
[Severity: Low]
Is the script header comment now out of date?
At the top of the renamed scripts/gen_initramfs.sh it still states:
# Generate a cpio packed initramfs. It uses gen_init_cpio to generate
# the cpio archive. # This script assumes that gen_init_cpio is located in usr/ directory
Should this comment be updated to reflect the new scripts/ location?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260925-move-gen_init_cpio-to-scripts-v3-1-99c493f76722@kernel.org?part=2
Mike Rapoport
maintainerHi Nicolas,
Quoted 24 lines · Nicolas Schier
initramfs cpio tools had been subject of several recent discussions on linux-kbuild. Let's get two minor steps forward by enabling a top-level target for building
gen_init_cpiow/o the need of a valid kbuild configuration [1] and move the tools for generating the built-in initramfs fromusr/toscripts/[2].---
Changes in v3:
* Update various remainingusr/gen_init*references treewide (Nathan)
* Link to v2: https://patch.msgid.link/20260720-move-gen_init_cpio-to-scripts-v2-0-26b7e15c7133@kernel.orgChanges in v2:
* Buildgen_init_cpioonly ifCONFIG_BLK_DEV_INITRD(Thomas)
* Keep underscore top-level target name (scripts_gen_init_cpio)
(Thomas)
* Link to v1: https://patch.msgid.link/20260309-move-gen_init_cpio-to-scripts-v1-0-0c5059b1ec5b@kernel.org---
Nicolas Schier (2):
kbuild: Markusr_gen_init_cpioas no-dot-config-target
kbuild: Movegen_init_cpioandgen_initramfs.shtoscripts/
Quoted 12 lines
.../early-userspace/early_userspace_support.rst | 16 ++++++++--------
Documentation/filesystems/ramfs-rootfs-initramfs.rst | 10 +++++-----
MAINTAINERS | 1 +
Makefile | 9 +++++----
scripts/.gitignore | 1 +
scripts/Makefile | 3 +++
scripts/Makefile.package | 2 +-
{usr => scripts}/gen_init_cpio.c | 0
{usr => scripts}/gen_initramfs.sh | 2 +-
scripts/remove-stale-files | 2 ++
scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py | 2 +-
tools/testing/selftests/kho/vmtest.sh | 2 +-There's also tools/testing/selftests/liveupdate/vmtest.sh I know of, didn't check for other users in tools/testing
Quoted 13 lines
tools/testing/selftests/nolibc/Makefile.nolibc | 2 +- usr/.gitignore | 4 +++- usr/Kconfig | 2 +- usr/Makefile | 4 +--- 16 files changed, 35 insertions(+), 27 deletions(-)---
base-commit:93f51579e7df248780214094418f205253383cc5
change-id: 20260225-move-gen_init_cpio-to-scripts-9e89ef99e51aBest regards,
Signature · 1 line
Nicolas
Signature · 2 lines
Sincerely yours, Mike.
Nicolas Schier
maintainerQuoted 40 lines · Mike Rapoport
Hi Nicolas,
Quoted 24 lines · Nicolas Schier
initramfs cpio tools had been subject of several recent discussions on linux-kbuild. Let's get two minor steps forward by enabling a top-level target for building
gen_init_cpiow/o the need of a valid kbuild configuration [1] and move the tools for generating the built-in initramfs fromusr/toscripts/[2].---
Changes in v3:
* Update various remainingusr/gen_init*references treewide (Nathan)
* Link to v2: https://patch.msgid.link/20260720-move-gen_init_cpio-to-scripts-v2-0-26b7e15c7133@kernel.orgChanges in v2:
* Buildgen_init_cpioonly ifCONFIG_BLK_DEV_INITRD(Thomas)
* Keep underscore top-level target name (scripts_gen_init_cpio)
(Thomas)
* Link to v1: https://patch.msgid.link/20260309-move-gen_init_cpio-to-scripts-v1-0-0c5059b1ec5b@kernel.org---
Nicolas Schier (2):
kbuild: Markusr_gen_init_cpioas no-dot-config-target
kbuild: Movegen_init_cpioandgen_initramfs.shtoscripts/Quoted 12 lines
.../early-userspace/early_userspace_support.rst | 16 ++++++++-------- Documentation/filesystems/ramfs-rootfs-initramfs.rst | 10 +++++----- MAINTAINERS | 1 + Makefile | 9 +++++---- scripts/.gitignore | 1 + scripts/Makefile | 3 +++ scripts/Makefile.package | 2 +- {usr => scripts}/gen_init_cpio.c | 0 {usr => scripts}/gen_initramfs.sh | 2 +- scripts/remove-stale-files | 2 ++ scripts/sbom/tests/cmd_graph/test_savedcmd_parser.py | 2 +- tools/testing/selftests/kho/vmtest.sh | 2 +-
Quoted 3 lines
There's also
tools/testing/selftests/liveupdate/vmtest.shI know of, didn't check for other users intools/testing
No idea how I missed that again; will be adjusted in v4. Thanks a lot!
Signature · 1 line
Nicolas