In this recipe we will learn about initscripts. Initscripts is a collection of scripts that make sure your computer starts up fine. It also provides the necessary functions and tools to manage services on your system. Initscripts' services are often referred to as daemons (https://wiki.archlinux.org/index.php/Daemon). These days, booting using initscripts can still be used in conjunction with systemd, but over time the use of initscripts will be discouraged and phased out. Systemd is a daemon that controls the startup of your system and also manages the services running on them. The initscripts are written in Bash, so they are easy to read and modify when needed. Extended information about the boot process of Arch Linux can be found at https://wiki.archlinux.org/index.php/Arch_Boot_Process.
The following list describes the main tasks that we will perform in this recipe:
3. This is the multiuser runlevel without starting X.rc.conf file within the DAEMONS array.The following step changes the runlevel:
telinit runlevel to change the runlevel, where runlevel is a number from 0 to 6.Let's list the steps required to set the default runlevel:
/etc/inittab.id:3:initdefault:. Here you will already see that the default selected runlevel is 3.telinit q.
/etc/rc.d/somedaemon start
Let's list the steps required to automatically start a service (daemon):
The telinit command will change the runlevel and depending on what number you switch to, some running applications and daemons might get stopped or just get started.
The default selected runlevel set in the inittab file determines what scripts will be used during the startup of your PC. This is also the reason why you always need to check if the configuration is correct by running telinit q, because if the inittab file is corrupted somehow your system will become unbootable.
The Bash script sitting in the /etc/rc.d/ folder will be executable. It will by default also provide three actions: start, stop, and restart.
During startup, the initscripts will read the DAEMONS array defined in the rc.conf file, and in the order they are defined all the daemons will be started during boot.
Now let's talk about some general information that is relevant to this recipe.
The runlevels are just numbers, but for us humans it is easier to remember sentences. So we do some matching of an action versus the runlevel number.
The following list defines each runlevel number:
0: Poweroff1: Single-user mode (rescue mode)2 and 4: These are user defined, but as on any other system they are the same as 3 by default3: Multi-user mode; users can log in via a terminal or network5: Multi-user graphical mode; this is runlevel 3 + X (some display manager)6: Rebootemergency: Emergency shell (you will encounter this during boot failures)The modification of the /etc/inittab file can lead to an unbootable system. So there are other ways to configure the default runlevel.
We can set the default runlevel we want in the kernel command line configured in our boot loader configuration file. This will allow us to safely switch runlevels.
Lets perform the following step to set the default runlevel via the boot loader (Syslinux in this example):
/boot/syslinux/syslinux.cfg.APPEND initrd=/initramfs-linux.img root=/dev/sda2rooftfstype=ext4 ro 5
We have set the default runlevel to 5 (graphical mode).
Arch Linux provides a helper application that makes it easy to start multiple daemons in one command.
The scripts that facilitate the starting of the daemons usually provide three actions by default:
start: Starts the daemonstop: Stops the daemonrestart: Restarts the daemonAnother common action is reload, which facilitates the running daemon to actually reload its configuration without really stopping.
Arch Linux provides a helper that can start and stop multiple services in one command. The helper comes with a nice man page, which you can read by issuing man rc.d.
rc.d action daemon1 daemon2 ...
The actions you can provide to rc.d are the same that you can pass to the scripts directly. So if a script provides the reload action, rc.d can use it.
Now, the default way of starting the daemons is sequential. The first has to be started correctly before the next can be started. We can improve our boot time by configuring the DAEMONS array a little differently.
If we want some service to be started in parallel with the one's following it, you can add @ in front of the entry in the DAEMONS array:
DAEMONS=(syslog-ng network @crond)We can also leave a service in the DAEMONS array but still disable it from automatically being started. For this we need to add ! in front of the service:
DAEMONS=(syslog-ng !network crond)