Create and control start up scripts in BusyBox

55,433

Solution 1

For buildroot all your scripts must be placed in $path_to_buildroot/output/target/etc/init.d before build image. In my case this directory contains rcS and few scripts named S[0-99]script_name. So you can create your own start\stop script.

rcS:

#!/bin/sh

# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/S??* ;do

     # Ignore dangling symlinks (if any).
     [ ! -f "$i" ] && continue

     case "$i" in
    *.sh)
        # Source shell script for speed.
        (
        trap - INT QUIT TSTP
        set start
        . $i
        )
        ;;
    *)
        # No sh extension, so fork subprocess.
        $i start
        ;;
    esac
done

and for example S40network:

#!/bin/sh
#
# Start the network....
#

case "$1" in
  start)
    echo "Starting network..."
    /sbin/ifup -a
    ;;
  stop)
    echo -n "Stopping network..."
    /sbin/ifdown -a
    ;;
  restart|reload)
    "$0" stop
    "$0" start
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?

Solution 2

It's bad idea to change your fs in "target" folder. This is because changes in output/target/ do not survive the make clean command.

In buildroot manual decribed how to do it correctly

You should create dir somewhere which partly overlay file system. For example you can create dir "your-overlay" in buildroot dir where you create this struct

your-overlay/etc/init.d/<any_file>

Then you should set path to this overlay in defconfig

System configuration > Root filesystem overlay directories

(or, find BR2_ROOTFS_OVERLAY)

Also, the recommended path for this overlay is board/<company>/<boardname>/rootfs-overlay

Share:
55,433

Related videos on Youtube

vish.raval
Author by

vish.raval

*** Main Functions *** C and C++ int main(void); int main(); int main(int argc, char **argv); int main(int argc, char *argv[]); int main(int argc, char **argv, char **envp); JAVA public static void main(String[] args) public static void main(String... args) public static void main(String args[]) PYTHON def main(): # the main code goes here if __name__ == "__main__": main() PIKE int main(int argc, array(string) argv) SCALA def main(args:Array[String]) RUBY self # =&gt; main self.class # =&gt; Object self.class.ancestors # =&gt; [Object, Kernel]

Updated on September 18, 2022

Comments

  • vish.raval
    vish.raval over 1 year

    I have compiled a custom linux kernel in BusyBox. BusyBox init does not support runlevels. When the kernel boots up in BusyBox, it first executes init which looks for the specified runlevel in /etc/inittab. BusyBox init works just fine without /etc/inittab. When no inittab is found it has the following behavior:

    ::sysinit:/etc/init.d/rcS
    

    This part is very clear to me, but I would like to know how to manage daemons that start up networking, create serial ports, or start java processes. I have looked in the scripts that reside in /etc/init.d/ but I don't understand how to manage them. I am looking for a good tutorial or solution to control these services myself without an automated tool like buildroot. I want to understand how these scripts work and how to create devices in /dev/ (right now I only have console and ttyAM0).

  • Ciro Santilli Путлер Капут 六四事
    Ciro Santilli Путлер Капут 六四事 over 6 years
    Sample setup when using Buildroot as a submodule: github.com/cirosantilli/linux-kernel-module-cheat/blob/…
  • Tim
    Tim almost 6 years
    OP is using only BusyBox and indicates he wants to achieve his goal without buildroot. I don't see this answer relevant to the question. It's more a comment to the accepted answer.
  • Tim
    Tim almost 6 years
    S[0-99]script_name filename syntax will run S10* before S2* and break the script.
  • thom_nic
    thom_nic almost 6 years
    @Tim not necessarily "break the script", just zero-pad. Sure S20* runs after S10*, if you want something to come before S10 you need to call it S01*, S02*, etc. NBD.