How to use SysVinit: the alternative to Systemd
Some operating systems come with SysVinit as the service manager, instead of Systemd. Here I will teach you how to run scripts at boot using this tool.
I am going to use MX Linux, a Debian based distro with sysVinit installed.
Table of Contents
A runlevel is one of the modes that a UNIX-based system can run. Each runlevel has certain number of services to be running, so the user can control the bahaviour of the system by adding or removing services on each runlevel, or changing the default runlevel. Most systems have seven runlevels.
|MX Linux Runlevel||Comment|
|0||Halt the system.|
|1||Single-user mode: provides a root console without logon. Useful if you lose your root password.|
|2||Multiuser with no network.|
|3||Console logon, no X (i.e. no GUI).|
|5||Default GUI logon|
|6||Reboot the system|
You can check the runlevel you are on by typing
runlevel on a Terminal.
init is the parent process of all system processes (its Process ID is 1). When system boots,
init process is started and executes all startup scripts inside
? is the runlevel). MX Linux default runlevel is 5, so
init will execute scripts inside
/etc/rc5.d/. Default runlevel is specified on
rc?.d folder, there are symbolic links to files inside
Changing a runlevel
You can change the runlevel at boot time of when the system is running. For example, if you want to change to a console runlevel (no GUI):
- From the GRUB menu: type
e(for ‘edit’) when your operating system is selected, go to the end of the line that starts with
linux /boot/vmlinux-5..., add a space and type the runlevel number (e.g.:
3). Finally, press F10 to boot.
- From the desktop: press Ctrl + Alt + F1 to get out of X. Log in as root and run
Writing rc.d scripts
As I said before, init scripts are inside
/etc/init.d/. You create a symbolic link to those files on the runlevel folder you want to run the script (e.g.:
$ ls -l /etc/rc5.d/ total 0 lrwxrwxrwx 1 root root 14 Mar 3 18:31 K01nmbd -> ../init.d/nmbd lrwxrwxrwx 1 root root 14 Mar 3 18:31 K01smbd -> ../init.d/smbd