After mounting the root filesystem, the kernel starts one program in user space. This is init, and it gets process ID 1. The kernel does not start your web server or login screen itself. Init arranges all of that.
What init does
Init typically:
- mounts the remaining filesystems
- starts background services such as logging, networking and SSH
- provides login prompts or a graphical login
- adopts orphaned processes and collects them when they exit
- manages an orderly shutdown
An orphan is a process whose parent has exited. By default it is handed to PID 1, although a process can register itself as a "subreaper" and take that role for its own descendants.
If PID 1 exits, the kernel panics. If it cannot find any init to run at all, boot also ends in a panic.
Three init systems
- System V init runs shell scripts in a set order, grouped into runlevels.
- Upstart reacts to events. Ubuntu used it before moving to systemd, and it is now historical.
- systemd describes everything as units with dependencies, and starts many of them in parallel. It is the default on most major distributions.
Others exist. Alpine, for example, runs BusyBox init as PID 1 and uses OpenRC to manage services.
Which one are you running?
Ask for the name of process 1:
$ ps -p 1 -o comm=
systemdOn many systems the traditional path /sbin/init is a link to the real program:
$ ls -l /sbin/init
lrwxrwxrwx 1 root root 22 Aug 5 10:12 /sbin/init -> ../lib/systemd/systemdThe link target and date will differ on your machine. A name of init from ps does not tell you which system it is, so check the link or the documentation. Inside a container, PID 1 is often just the application or a shell.
Choosing a different init
The kernel parameter init= names the program to run instead of the default. Administrators sometimes use init=/bin/bash to repair a system. It gives a root shell with almost nothing set up, which is also why physical access and the bootloader need protecting.
Seeing the process tree
$ ps -e -o pid,ppid,comm | head -3
PID PPID COMMAND
1 0 systemd
2 0 kthreaddPPID is the parent's ID. A parent of 0 means the process was started by the kernel itself.
Try it
Find your PID 1, follow the /sbin/init link, and run ps -e -o pid,ppid,comm to pick out three processes whose parent is 1. For more practice with processes, use the processes lab.
Check your understanding
Boot Process: Init
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.