I am maintaining a buildroot linux build system for one of our embedded devices. Most of the time we boot from SD card, which works fine. But sometime over the past few years the boot-from-NAND process has gotten borked. With systems I build today, the failure occurs when the boot process runs the /init script.
The /init script looks like this:
#!/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 $*
And this is the output:
mount: you must be root
/init: line 15: can't open /dev/console: Permission denied
Kernel panic - not syncing: Attempted to kill init!
Backtrace:
[<c00181cc>] (dump_backtrace+0x0/0x10c) from [<c0447090>] (dump_stack+0x18/0x1c)
r6:df02ba40 r5:c0555168 r4:c0684f88 r3:c0645194
[<c0447078>] (dump_stack+0x0/0x1c) from [<c044728c>] (panic+0x64/0x194)
[<c0447228>] (panic+0x0/0x194) from [<c0044120>] (do_exit+0x5c8/0x674)
r3:df02ba40 r2:df02df60 r1:00000000 r0:c0555168
r7:000000f8
[<c0043b58>] (do_exit+0x0/0x674) from [<c004442c>] (do_group_exit+0x44/0xa4)
r7:000000f8
[<c00443e8>] (do_group_exit+0x0/0xa4) from [<c00444a4>] (__wake_up_parent+0x0/0x28)
r4:000700de r3:00000002
[<c004448c>] (sys_exit_group+0x0/0x18) from [<c0014740>] (ret_fast_syscall+0x0/0x30)
Seeing the above, I added the following lines to the beginning of the /init script:
echo "id"
id
echo "whoami"
whoami
And now I get:
id
uid=0(root) gid=0(root) euid=1000(default)
whoami
default
mount: you must be root
/init: line 15: can't open /dev/console: Permission denied
Kernel panic - not syncing: Attempted to kill init!
Backtrace:
[<c00181cc>] (dump_backtrace+0x0/0x10c) from [<c0447090>] (dump_stack+0x18/0x1c)
r6:df02ba40 r5:c0555168 r4:c0684f88 r3:c0645194
[<c0447078>] (dump_stack+0x0/0x1c) from [<c044728c>] (panic+0x64/0x194)
[<c0447228>] (panic+0x0/0x194) from [<c0044120>] (do_exit+0x5c8/0x674)
r3:df02ba40 r2:df02df60 r1:00000000 r0:c0555168
r7:000000f8
[<c0043b58>] (do_exit+0x0/0x674) from [<c004442c>] (do_group_exit+0x44/0xa4)
r7:000000f8
[<c00443e8>] (do_group_exit+0x0/0xa4) from [<c00444a4>] (__wake_up_parent+0x0/0x28)
r4:000700de r3:00000002
[<c004448c>] (sys_exit_group+0x0/0x18) from [<c0014740>] (ret_fast_syscall+0x0/0x30)
I was able to poke the debug lines into the beginning of the /init script on an old working build, and got the following output:
id
uid=0(root) gid=0(root)
whoami
root
mount: mounting devtmpfs on /dev failed: Device or resource busy
Followed by a successful boot.
I'm assuming the problem is that the /init script is now being executed as the default non-root user instead of as root. But I don't know why that's happening nor how to fix it. The NAND boot is mounting an UBI filesystem as root /.