Customising the boot process involves understanding how startup script are called. The chapter also describes common problems that arise at different points during the booting process as well as some recovery techniques. Finally we focus our attention on the initial ram disk (or initial root device) initrd stage of the booting process. This will allow us to make decisions as to when new initial ram disks need to be made.
In order to prevent processes run by users from interfering with the kernel two distinct memory areas are defined. These are referred to as kernel space memory and user space memory. The init process is the first program to run in user-space.
init is therefore the parent of all processes.
The init program's configuration file is
/etc/inittab.
Runlevels determine which processes should run together.
All processes that can be started or stopped at a given runlevel are
controlled by a script (called an init script or an rc script) in
/etc/rc.d/init.d (or /etc/init.d
in some systems.
List of rc scripts on a typical system
anacron halt kudzu ntpd rusersd syslog ypxfrd apmd identd lpd portmap rwalld vncserver atd ipchains netfs radvd rwhod xfs autofs iptables network random sendmail xinetd crond kdcrotate nfs rawdevices single ypbind functions keytable nfslock rhnsd snmpd yppasswdd gpm killall nscd rstatd sshd ypserv
Selecting a process to run or be stopped in a given runlevel is done by
creating symbolic links in the
/etc/rc.d/rc
(or N.d//etc/rc on some
systems) directory, where N.d/N is a runlevel.
We want to run a script at a given run level. Our script will be called
printtotty10 and will simply print the
message given as an argument to /dev/tty10.
/bin/printtotty10
#!/bin/bash echo $1 > /dev/tty10
One way to have the script started at a specific run level
is to add a line in /etc/inittab like
pr10:3:once:/bin/printtotty10 Printtotty was started in inittab
This is not always the best way to do this. What if many scripts need
to be started? The inittab file would look messy.
We can write a custom rc-script. We follow the usage to call the script the same name as the actual tool we want to startup.
/etc/rc.d/init.d/printtotty10
#!/bin/sh
# chkconfig: 345 85 15
# description: This line has to be here for chkconfig to work ... \
#The script will display a message on /dev/tty10
#First source some predefined functions such as echo_success()
./etc/rc.d/init.d/functions
start() {
echo -n "Starting printtotty10"
/bin/printtotty10 "printtotty10 was started with an rc-script "
echo_success
echo
}
stop() {
echo -n "Stopping custom-rc"
/bin/printtotty10 "The custom script has stopped"
echo_success
echo
}
case "$1" in
start)
start;;
stop)
stop;;
esac
exit 0
The printtotty10 script can be
started at boot time by placing the command in
/etc/rc.d/rc.local. The rc.local
script is the last rc-script to be run.
![]() | Note |
|---|---|
When setting up a linux server as a router it is possible to switch on ip-forwarding at boot time by adding the following line to rc.local: echo 1 > /proc/sys/net/ipv4/ip_forward However it is better to use the sysctl mechanism to switch
ip-forwarding on every time the network interface is started.
This is done by adding the following line to
net.ipv4.ip_forward = 1 |