From: Timo Ketola Date: Mon, 23 Sep 2019 10:58:45 +0000 (+0000) Subject: fs/cpio: make initramfs init script survive 'console=' kernel argument X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=98a6f1fc02e41ac30db24ac2b7262033faabacde;p=buildroot.git fs/cpio: make initramfs init script survive 'console=' kernel argument When booting with 'console=' in the kernel command line (as e.g. U-Boot does with silent flags in effect), opening /dev/console fails. As per POSIX [0], when iany redirection fails, the shell running exec shal exit in error. So, when 'console=' is specified. /dev/console can't be opened, and the redirection fails, and /init is killed. That behaviour was fixed on the kernel side with commit 2bd3a997befc2 (Open /dev/console from rootfs), present since 2.6.34, released in May 2010, so any [dr]ecent kernel will have that fix. Furthermore, busybox will fix things up anyway (in bb_sanitize_stdio()), falling back to opening /dev/null if no console is availble. systemd does a similar thing (in make_console_stdio()), and sysvinit again has a similar approach (in console_init()). The archealogy search turned up those relevant commits: 2011-08-04 10a130f91e initramfs/init: make sure that 0, 1, 2 fds are available introduces the three exec redirections in initramfs 2011-09-06 3fac21ef8d cpio: fix boot with dynamic /dev introduces the three exec redirections in cpio 2011-09-06 13a3afc536 fs/initramfs: refactor with fs/cpio dropped the initramfs tweaks to reuse the cpio ones 2012-11-04 e1ebae700a fs/common: Create initial console device introduces the /dev/console char,5,1 pseudo device creation in cpio 2018-03-31 dec061adce fs/cpio: don't extend packages' permissions table switched from the permission-table to a manual mknod to create /dev/console The redirections were added before we could guarantee there was a /dev/console in the rootfs. We're now guaranteed to have /dev/console in an initramfs, and any recent kernel will automatically open /dev/console before spawning /init. The three redirections are useless now, and cause harm under certain conditions. Drop them. [0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_20_01 Signed-off-by: Timo Ketola Cc: Peter Korsgaard [yann.morin.1998@free.fr: - extend commit log with the analysis done with Peter ] Signed-off-by: Yann E. MORIN --- diff --git a/fs/cpio/init b/fs/cpio/init index dbe09ac68e..b0af18b67a 100755 --- a/fs/cpio/init +++ b/fs/cpio/init @@ -1,7 +1,4 @@ #!/bin/sh # devtmpfs does not get automounted for initramfs /bin/mount -t devtmpfs devtmpfs /dev -exec 0/dev/console -exec 2>/dev/console exec /sbin/init "$@"