Stuff to read
Role of the kernel
Loading the initial ramdisk
After the kernel is loaded, it will begin to enumerate the devices and call appropriate device drives to initialize their internal structures. Usually an initial ramdisk will be loaded. In most Linux systems this is stored in /boot.
Running the initial ramdisk
Take a look at the initial ramdisk of your system to see what is inside it. Mostly it is programs, such as busybox to get the system started Take a look at the Wikipeida page to get a idea of how the initial ramdisk is used.
Take a look at the shell script init located in the initial ramdisk. This will be the first user space process. The kernel will run it as process number 1. When process number 1 exits, the kernel will reboot. Also, if a parent process terminates, its child processes are inherited by process number 1.
As its last action, the init on the ramdisk will call bin/run-init which runs /sbin/init with the proper security context.
Running the real init
At this point, it gets complicated. Because init runs in userspace, it can be replaced. Everyone is trying to improve init. Take a look the chaos in the world of init.
System V init
Take a look at a description of the System V init configure and some examples of /etc/inittab.
Look at the following to see how it all works today. Be sure to look at some of the files inside
Startup files should be LSB compliant so that they can be managed using update-rc.d.
The various configuration files start with the directory /etc/init. Upstart can be event driven. It is supposed to also handle dynamic events, such as the insertion of a USB drive.
However most major distributions are adopting systemd. Take a look at the directory /etc/systemd for how it is used on your systema and also read the freedesktop.org guide.
Working with three different init styles
There are three different ways to enable and disable services.
#! /bin/sh if [ -f /etc/init.d/apache2 ]; then /usr/sbin/update-rc.d apache2 disable fi if [ -f /etc/init/dovecot.conf ]; then echo manual > /etc/init/dovecot.override fi ## git-daemon enabled by link ## /etc/service/git-daemon --> /etc/sv/git-daemon if [ -L /etc/service/git-daemon ]; then /bin/rm /etc/service/git-daemon fi