[PATCH 2/2] init: ensure that /dev/null is (nearly) always available in initramfs

Askar Safin
2026-02-19T21:04:43Z

Binaries linked with bionic libc require /dev/null to be present,
otherwise they will crash before entering "main", as explained
in https://landley.net/toybox/faq.html#cross3 .

So we should put /dev/null to initramfs, but this is impossible
if we create initramfs using "cpio" and we are running as normal
user.

This problem can be solved by using gen_init_cpio.

But let's make sure instead that /dev/null is always available as
a quality-of-implementation feature. This will reduce number
of failure modes and will make it easier for developers to
get early boot right. (Early boot issues are very hard to debug.)

Signed-off-by: Askar Safin <safinaskar@gmail.com>
---
init/do_mounts.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index f911280a348e..3e71049b3dcf 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -525,5 +525,8 @@ void __init create_basic_rootfs(void)
WARN_ON_ONCE(init_mkdir("/dev", 0755) != 0);
WARN_ON_ONCE(init_mknod("/dev/console", S_IFCHR | 0600,
new_encode_dev(MKDEV(5, 1))) != 0);
+ WARN_ON_ONCE(init_mknod("/dev/null", S_IFCHR,
+ new_encode_dev(MKDEV(1, 3))) != 0);
+ WARN_ON_ONCE(init_chmod("/dev/null", 0666) != 0);
WARN_ON_ONCE(init_mkdir("/root", 0700) != 0);
}
--
2.47.3