Running a shell, or even a shell script, at boot time is fine for simple cases, but really you need something more flexible. Normally, Unix systems run a program called init
that starts up and monitors other programs. Over the years, there have been many init
programs, some of which I will describe in Chapter 9, Starting up - the init Program. For now, I will briefly introduce the init
from BusyBox.
init
begins by reading the configuration file, /etc/inittab
. Here is a simple example which is adequate for our needs:
::sysinit:/etc/init.d/rcS ::askfirst:-/bin/ash
The first line runs a shell script, rcS
, when init
is started. The second line prints the message Please press Enter to activate this console to the console, and starts a shell when you press Enter. The leading -
before /bin/ash
means that it will be a login shell, which sources /etc/profile
and $HOME/.profile
before giving the shell prompt. One of the advantages of launching the shell like this is that job control is enabled. The most immediate effect is that you can use Ctrl + C to terminate the current program. Maybe you didn't notice it before but, wait until you run the ping
program and find you can't stop it!
BusyBox init
provides a default inittab
if none is present in the root filesystem. It is a little more extensive than the preceding one.
The script /etc/init.d/rcS
is the place to put initialization commands that need to be performed at boot, for example, mounting the proc
and sysfs
filesystems:
#!/bin/sh mount -t proc proc /proc mount -t sysfs sysfs /sys
Make sure that you make rcS
executable, like this:
$ cd ~/rootfs $ chmod +x etc/init.d/rcS
You can try it out on QEMU by changing the -append
parameter, like this:
-append "console=ttyAMA0 rdinit=/sbin/init"
To achieve the same on the BeagelBone Black, you need to change the bootargs
variable in U-Boot as shown:
setenv bootargs console=ttyO0,115200 rdinit=/sbin/init