Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

init: handle bootloader identifier in kernel parameters

BootLoaders (Grub, LILO, etc) may pass an identifier such as "BOOT_IMAGE=
/boot/vmlinuz-x.y.z" to kernel parameters. But these identifiers are not
recognized by the kernel itself so will be passed to userspace. However
user space init program also don't recognize it.

KEXEC/KDUMP (kexec-tools) may also pass an identifier such as "kexec" on
some architectures.

We cannot change BootLoader's behavior, because this behavior exists for
many years, and there are already user space programs search BOOT_IMAGE=
in /proc/cmdline to obtain the kernel image locations:

https://github.com/linuxdeepin/deepin-ab-recovery/blob/master/util.go
(search getBootOptions)
https://github.com/linuxdeepin/deepin-ab-recovery/blob/master/main.go
(search getKernelReleaseWithBootOption) So the the best way is handle
(ignore) it by the kernel itself, which can avoid such boot warnings (if
we use something like init=/bin/bash, bootloader identifier can even cause
a crash):

Kernel command line: BOOT_IMAGE=(hd0,1)/vmlinuz-6.x root=/dev/sda3 ro console=tty
Unknown kernel command line parameters "BOOT_IMAGE=(hd0,1)/vmlinuz-6.x", will be passed to user space.

[chenhuacai@loongson.cn: use strstarts()]
Link: https://lkml.kernel.org/r/20250815090120.1569947-1-chenhuacai@loongson.cn
Link: https://lkml.kernel.org/r/20250721101343.3283480-1-chenhuacai@loongson.cn
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Huacai Chen and committed by
Andrew Morton
e416f0ed ca78a04c

+12
+12
init/main.c
··· 544 544 const char *unused, void *arg) 545 545 { 546 546 size_t len = strlen(param); 547 + /* 548 + * Well-known bootloader identifiers: 549 + * 1. LILO/Grub pass "BOOT_IMAGE=..."; 550 + * 2. kexec/kdump (kexec-tools) pass "kexec". 551 + */ 552 + const char *bootloader[] = { "BOOT_IMAGE=", "kexec", NULL }; 547 553 548 554 /* Handle params aliased to sysctls */ 549 555 if (sysctl_is_alias(param)) 550 556 return 0; 551 557 552 558 repair_env_string(param, val); 559 + 560 + /* Handle bootloader identifier */ 561 + for (int i = 0; bootloader[i]; i++) { 562 + if (strstarts(param, bootloader[i])) 563 + return 0; 564 + } 553 565 554 566 /* Handle obsolete-style parameters */ 555 567 if (obsolete_checksetup(param))