Skip to contentSkip to conversation

initramfs/init: make sure that 0, 1, 2 fds are available

PATCH New Thomas Petazzoni 2 participants 2 messages Aug 4, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initramfs/init: make sure that 0, 1, 2 fds are available

As the kernel doesn't automatically mount devtmpfs when an initramfs is used, commit 424888e47431db738f5f9b3c6392435bfce7a842 has introduced a small wrapper script that mounts devtmpfs before starting the real init.

Unfortunately, the problem is that in this case, the init process runs without any 0, 1 and 2 file descriptors, so none of the messages/errors printed by the various initialization scripts can be seen. This is due to the fact the init process relies on 0, 1 and 2 being opened by the kernel before init is started. However, as /dev/console isn't present on the filesystem at the time the kernel tries to open the console to create the 0, 1 and 2 file descriptors, the kernel fails on this and prints the famous "Warning: unable to open an initial console".

The proposed workaround is to actually open 0, 1 and 2 to /dev/console in the wrapper script, right after mounting the devtmpfs filesystem, and before starting the real init. The "Warning" from the kernel is still shown, but at least the messages from the init scripts are visible.

---
 fs/initramfs/init |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/initramfs/init +3 -0
index 751cb27..a275482 100755
@@ -1,4 +1,7 @@
 #!/bin/sh
 # devtmpfs does not get automounted for initramfs
 /bin/mount -t devtmpfs devtmpfs /dev
+exec 0</dev/console
+exec 1>/dev/console
+exec 2>/dev/console
 exec /sbin/init $*
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/1 initramfs/init: make sure that 0, 1, 2 fds are available

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas Petazzoni <[email protected]> writes:

Thomas> As the kernel doesn't automatically mount devtmpfs when an initramfs Thomas> is used, commit 424888e47431db738f5f9b3c6392435bfce7a842 has Thomas> introduced a small wrapper script that mounts devtmpfs before starting Thomas> the real init.

Thomas> Unfortunately, the problem is that in this case, the init process runs Thomas> without any 0, 1 and 2 file descriptors, so none of the Thomas> messages/errors printed by the various initialization scripts can be Thomas> seen. This is due to the fact the init process relies on 0, 1 and 2 Thomas> being opened by the kernel before init is started. However, as Thomas> /dev/console isn't present on the filesystem at the time the kernel Thomas> tries to open the console to create the 0, 1 and 2 file descriptors, Thomas> the kernel fails on this and prints the famous "Warning: unable to Thomas> open an initial console".

Thomas> The proposed workaround is to actually open 0, 1 and 2 to /dev/console Thomas> in the wrapper script, right after mounting the devtmpfs filesystem, Thomas> and before starting the real init. The "Warning" from the kernel is Thomas> still shown, but at least the messages from the init scripts are Thomas> visible.

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard