[1/1] fs/cpio: make initramfs init script survive 'console=' kernel argument
diff mbox series

Message ID 80e3e080-0af3-99de-ff8f-9de5e3dca8a6@exertus.fi
State New
Headers show
Series
  • [1/1] fs/cpio: make initramfs init script survive 'console=' kernel argument
Related show

Commit Message

Timo Ketola Sept. 23, 2019, 10:58 a.m. UTC
When booting with 'console=<empty>' in the kernel command line (as e.g.
U-Boot does with silent flags in effect), opening /dev/console fails.
That is fatal in the /init script and kernel will panic. It is also
needless, because the kernel tries to open it anyway (well, as long as
we have console node in initramfs /dev; cpio.mk creates that alright).

Signed-off-by: Timo Ketola <timo.ketola@exertus.fi>
---
 fs/cpio/init | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Peter Korsgaard Sept. 23, 2019, 1:10 p.m. UTC | #1
>>>>> "Timo" == Timo Ketola <Timo.Ketola@exertus.fi> writes:

 > When booting with 'console=<empty>' in the kernel command line (as e.g.
 > U-Boot does with silent flags in effect), opening /dev/console fails.
 > That is fatal in the /init script and kernel will panic. It is also
 > needless, because the kernel tries to open it anyway (well, as long as
 > we have console node in initramfs /dev; cpio.mk creates that alright).

Also when devtmpfs is used? We manually mount devtmpfs in the initramfs,
so the kernel presumably cannot have opened /dev/console before
executing /init, and we do not add a static device node for
/dev/console.


 > Signed-off-by: Timo Ketola <timo.ketola@exertus.fi>
 > ---
 >  fs/cpio/init | 4 +---
 >  1 file changed, 1 insertion(+), 3 deletions(-)

 > diff --git a/fs/cpio/init b/fs/cpio/init
 > index dbe09ac..72b2401 100755
 > --- a/fs/cpio/init
 > +++ b/fs/cpio/init
 > @@ -1,7 +1,5 @@
 >  #!/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 "$@"
 > -- 
 > 2.7.4
 > _______________________________________________
 > buildroot mailing list
 > buildroot@busybox.net
 > http://lists.busybox.net/mailman/listinfo/buildroot
Timo Ketola Sept. 23, 2019, 4:55 p.m. UTC | #2
On 23.9.2019 16.10, Peter Korsgaard wrote:
>>>>>> "Timo" == Timo Ketola <Timo.Ketola@exertus.fi> writes:
> 
>  > When booting with 'console=<empty>' in the kernel command line (as e.g.
>  > U-Boot does with silent flags in effect), opening /dev/console fails.
>  > That is fatal in the /init script and kernel will panic. It is also
>  > needless, because the kernel tries to open it anyway (well, as long as
>  > we have console node in initramfs /dev; cpio.mk creates that alright).
> 
> Also when devtmpfs is used? We manually mount devtmpfs in the initramfs,
> so the kernel presumably cannot have opened /dev/console before
> executing /init, and we do not add a static device node for
> /dev/console.

But I thought BR does just that here:

https://git.busybox.net/buildroot/tree/fs/cpio/cpio.mk

line 24, 25
Peter Korsgaard Sept. 23, 2019, 5:07 p.m. UTC | #3
>>>>> "Timo" == Timo Ketola <timo@exertus.fi> writes:

 > On 23.9.2019 16.10, Peter Korsgaard wrote:
 >>>>>>> "Timo" == Timo Ketola <Timo.Ketola@exertus.fi> writes:
 >> 
 >> > When booting with 'console=<empty>' in the kernel command line (as e.g.
 >> > U-Boot does with silent flags in effect), opening /dev/console fails.
 >> > That is fatal in the /init script and kernel will panic. It is also
 >> > needless, because the kernel tries to open it anyway (well, as long as
 >> > we have console node in initramfs /dev; cpio.mk creates that alright).
 >> 
 >> Also when devtmpfs is used? We manually mount devtmpfs in the initramfs,
 >> so the kernel presumably cannot have opened /dev/console before
 >> executing /init, and we do not add a static device node for
 >> /dev/console.

 > But I thought BR does just that here:

 > https://git.busybox.net/buildroot/tree/fs/cpio/cpio.mk

 > line 24, 25

Heh, indeed - I forgot about that logic. Then I guess it is good, unless
something else in the boot sequence doesn't like a missing
stdin/stdout/stderr.
Timo Ketola Sept. 23, 2019, 7:31 p.m. UTC | #4
Peter,

On 23.9.2019 20.07, Peter Korsgaard wrote:
>>>>>> "Timo" == Timo Ketola <timo@exertus.fi> writes:
>  > But I thought BR does just that here:
> 
>  > https://git.busybox.net/buildroot/tree/fs/cpio/cpio.mk
> 
>  > line 24, 25
> 
> Heh, indeed - I forgot about that logic. Then I guess it is good, unless
> something else in the boot sequence doesn't like a missing
> stdin/stdout/stderr.

I think BusyBox's init takes care about that. See my conversation with
Arnout:

http://lists.busybox.net/pipermail/buildroot/2019-September/259889.html

And thanks for looking at this.

--

Timo
Timo Ketola Sept. 24, 2019, 5:24 a.m. UTC | #5
Hi there,

I tested this as per Arnout's suggestion by booting with 'console=' /
'console=ttymxc0,115200' and with / without initramfs. The result
depends only on console setting:

# cat /proc/cmdline; ls -l /proc/1/fd
console=
total 0
lrwx------    1 root     root            64 Sep 24 05:01 0 -> /dev/null
lrwx------    1 root     root            64 Sep 24 05:01 1 -> /dev/null
lrwx------    1 root     root            64 Sep 24 05:01 2 -> /dev/null

# cat /proc/cmdline; ls -l /proc/1/fd
console=ttymxc0,115200
total 0
lrwx------    1 root     root            64 Sep 24 05:20 0 -> /dev/console
lrwx------    1 root     root            64 Sep 24 05:20 1 -> /dev/console
lrwx------    1 root     root            64 Sep 24 05:20 2 -> /dev/console

--

Timo

Patch
diff mbox series

diff --git a/fs/cpio/init b/fs/cpio/init
index dbe09ac..72b2401 100755
--- a/fs/cpio/init
+++ b/fs/cpio/init
@@ -1,7 +1,5 @@ 
 #!/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 "$@"