[PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible

Lillian Berry posted 1 patch 3 months ago
init/main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible
Posted by Lillian Berry 3 months ago
Avoid silently ignoring the initramfs when the file specified in rdinit
is not usable. This prints an error that clearly explains the issue
(file was not found, vs initramfs was not found).

Signed-off-by: Lillian Berry <lillian@star-ark.net>
---
 init/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index 225a58279acd..e47984871775 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1592,7 +1592,11 @@ static noinline void __init kernel_init_freeable(void)
 	 * check if there is an early userspace init.  If yes, let it do all
 	 * the work
 	 */
-	if (init_eaccess(ramdisk_execute_command) != 0) {
+	int ramdisk_command_access;
+	ramdisk_command_access = init_eaccess(ramdisk_execute_command);
+	if (ramdisk_command_access != 0) {
+		pr_warn("check access for rdinit=%s failed: %i, ignoring\n",
+			ramdisk_execute_command, ramdisk_command_access);
 		ramdisk_execute_command = NULL;
 		prepare_namespace();
 	}
-- 
2.48.1
Re: [PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible
Posted by Ahmad Fatoum 3 hours ago
Hello Lillian,

On 7/7/25 11:14 AM, Lillian Berry wrote:
> Avoid silently ignoring the initramfs when the file specified in rdinit
> is not usable. This prints an error that clearly explains the issue
> (file was not found, vs initramfs was not found).

I have a system that works just fine without an initramfs, but now the
kernel warns me about it:

[    2.805602] check access for rdinit=/init failed: -2, ignoring

I suppose that's unintended and the code here should actually check that
there is an initrd at all before checking for the rdinit?

Thanks,
Ahmad

> 
> Signed-off-by: Lillian Berry <lillian@star-ark.net>
> ---
>  init/main.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/init/main.c b/init/main.c
> index 225a58279acd..e47984871775 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1592,7 +1592,11 @@ static noinline void __init kernel_init_freeable(void)
>  	 * check if there is an early userspace init.  If yes, let it do all
>  	 * the work
>  	 */
> -	if (init_eaccess(ramdisk_execute_command) != 0) {
> +	int ramdisk_command_access;
> +	ramdisk_command_access = init_eaccess(ramdisk_execute_command);
> +	if (ramdisk_command_access != 0) {
> +		pr_warn("check access for rdinit=%s failed: %i, ignoring\n",
> +			ramdisk_execute_command, ramdisk_command_access);
>  		ramdisk_execute_command = NULL;
>  		prepare_namespace();
>  	}

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |