Busybox init does not start /etc/init.d/rcS

12,521

Solution 1

  1. /bin/init needs to be on your filesystem.
  2. /bin/sh needs to be on your filesystem.
  3. /etc/init.d/rcS needs to be executable and have #!/bin/sh as its first line.

Solution 2

Init

Are you sure you where invoking Busybox init? What was the kernel command line? If no init= option was supplied to the the kernel, the kernel will look for an executable at /init.

For instance, if your busybox binary resides in /bin/busybox, you need to create the following symlink :

ln -s /bin/busybox /init

If you want your init to reside in /sbin, to comply with the inittab, also create a symlink there. Note that the kernel will not respect init= setting if you don't mount root and your busybox only runs in an initramfs.

ln -s /bin/busybox /sbin/init

Inittab

Also, you could try not using an inittab. The things you try to run from inittab, might very well fit in rcS and any descendant scripts. From the same source you found your example inittab:

# Note: BusyBox init works just fine without an inittab. If no inittab is
# found, it has the following default behavior:
#         ::sysinit:/etc/init.d/rcS
#         ::askfirst:/bin/sh
#         ::ctrlaltdel:/sbin/reboot
#         ::shutdown:/sbin/swapoff -a
#         ::shutdown:/bin/umount -a -r
#         ::restart:/sbin/init
#         tty2::askfirst:/bin/sh
#         tty3::askfirst:/bin/sh
#         tty4::askfirst:/bin/sh

rcS

Make sure /etc/init.d/rcS is executable:

chmod +x chroot chroot /bin/busybox

And try with:

#!/bin/busybox sh
echo "Hello world!"

Please note that this sentence can get buried between kernel log messages, so you might want to pass the quiet kernel command line option to see if it appears.

Busybox symlinks

Are the symlinks installed into the file system or not? If not it is not a disaster. Make sure that /etc/init.d/rcS starts with:

#!/bin/busybox sh
mkdir -pv /sbin
/bin/busybox --install -s

Solution 3

In addition to the scripts themselves being executable and having a correct shebang line, the kernel also needs to be compiled with the CONFIG_BINFMT_SCRIPT option enabled.

CONFIG_BINFMT_SCRIPT:

Say Y here if you want to execute interpreted scripts starting with
#! followed by the path to an interpreter.

You can build this support as a module; however, until that module
gets loaded, you cannot run scripts.  Thus, if you want to load this
module from an initramfs, the portion of the initramfs before loading
this module must consist of compiled binaries only.

Most systems will not boot if you say M or N here.  If unsure, say Y.

Without this option, you may receive the error message can't run '/etc/init.d/rcS': Exec format error.

Share:
12,521
selfbg
Author by

selfbg

Updated on August 03, 2022

Comments

  • selfbg
    selfbg almost 2 years

    I'm trying to build embedded system using buildroot. Everything seems to work. All modules are starting, the system is stable. The problem is that /etc/init.d/rcS does not start during initialization of the system. If I run it manually everything is OK. I have it in my inittab file.

    # /etc/inittab
    #
    # Copyright (C) 2001 Erik Andersen <[email protected]>
    #
    # Note: BusyBox init doesn't support runlevels.  The runlevels field is
    # completely ignored by BusyBox init. If you want runlevels, use
    # sysvinit.
    #
    # Format for each entry: <id>:<runlevels>:<action>:<process>
    #
    # id        == tty to run on, or empty for /dev/console
    # runlevels == ignored
    # action    == one of sysinit, respawn, askfirst, wait, and once
    # process   == program to run
    
    # Startup the system
    null::sysinit:/bin/mount -t proc proc /proc
    null::sysinit:/bin/mount -o remount,rw /
    null::sysinit:/bin/mkdir -p /dev/pts
    null::sysinit:/bin/mkdir -p /dev/shm
    null::sysinit:/bin/mount -a
    null::sysinit:/bin/hostname -F /etc/hostname
    # now run any rc scripts
    ::sysinit:/etc/init.d/rcS
    
    # Put a getty on the serial port
    ttyFIQ0::respawn:/sbin/getty -L -n ttyFIQ0 115200 vt100 # GENERIC_SERIAL
    
    # Stuff to do for the 3-finger salute
    ::ctrlaltdel:/sbin/reboot
    
    # Stuff to do before rebooting
    null::shutdown:/etc/init.d/rcK
    null::shutdown:/bin/umount -a -r
    null::shutdown:/sbin/swapoff -a
    

    Any idea what could be wrong?