Unix System V Boot Sequence
From Admin-SIG
During the evolution of the original Unix , there was a split into two major branches of development. One is refered to as System V, and one as BSD. They have somewhat different approaches to running startup scripts at boot. Many Linux distributions, including Debian, which is the one I am most familiar with, use the System V approach.
Before running startup scripts, the bootstrap process of getting a kernel loaded takes place. I’m not going to go into that. After the kernel is loaded, the first process started is usually the init program. This is true on the Debian laptop I am writing this article on. The init process has a process ID of 1. It is the First Process. A good way to see this is to run pstree on your Unix system. This what it looks like on my desktop.
init-+-atd
|-4*[aterm---bash---ssh]
|-bash---startx---xinit-+-WindowMaker-+-WindowMaker---WindowMaker---+
| | `-ssh-agent
| `-XFree86
|-bdflush
|-cron
|-cupsd
|-evolution-alarm---evolution-alarm---2*[evolution-alarm]
|-evolution-data----evolution-data----2*[evolution-data-]
|-famd
|-2*[gconfd-2]
|-5*[getty]
|-inetd
|-keventd
|-khubd
|-2*[kjournald]
|-klogd
|-ksoftirqd_CPU0
|-kswapd
|-kupdated
|-l2tpd
|-lockd
|-netserver
|-portmap
|-rpc.statd
|-rpciod
|-sshd
|-syslogd
|-xfs
|-xmms---xmms---2*[xmms]
`-xprint-+-xprint---Xprt
`-xprint
The configuration file for init is /etc/inittab. This file controls what processes init will spawn. Some processes are spawned from /etc/inittab itself, but most are not. Instead, inittab indicates which Unix run level to bring the system to be in. This is indicated in a line like this in inittab:
id:2:initdefault:
That is from my system. The default for Debian systems is level 2, which is indicated in the second field of the line above.
Init then executes the scripts in /etc/rcS.d. These scripts are there to take care of basic functions like mounting file systems and loading modules. After that, it starts all scripts that start with an “S” in /etc/rcrunlevel.d, where “runlevel” is the default run level, in this case, 2. So all the scripts that start with an “S” in /etc/rc2.d. What you will find if you look in /etc/rc2.d, is that the scripts also have a number following the “S". This controls the order the scripts are executed in. For example, S20inetd is executed before S21nfs-common.
Remember: The instructions below show that it is simple to add and subtract from your system's boot process. That means that you are free to make your boot much more useful, and you are also free to break it ;-)
Here is the payoff for all this esoteric knowledge. Change directory to /etc/rc2.d and do an “ls -l.” You will find that these are all symbolic links to scripts in /etc/init.d. When I wanted a script to be run at boot, I placed it in /etc/init.d. Then all I had to do was create a symbolic link in the appropriate rcS.d directory. That was it.
1. Write the script. 2. Put the script in /etc/init.d. 3. Create symbolic link in rcS.d.
Those are the only steps for inserting a script into the startup sequence.
Debian also gives you some tools to help with this process. In /etc/init.d you will find the file “skeleton.” It is a template for startup files to give them uniformity and help you give them the functionality of options such as “start,” “stop,” “reload,” etc., that startup scripts often have. My laptop script really didn’t need those features, so I didn’t us the skeleton template, but I have in the past and it is useful.
Also, Debian gives you the utility “update-rc.d.” When you run this command you give it arguments that tell it to create the symlinks for a script in /etc/init.d, and what run levels to create them in for you. You do not need it, but it is nice for the lazy.
That’s it. That’s how you can modify the boot process of your Linux, or System V, system by writing a script and inserting it into the boot sequence.

