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).
4 Not used/custom
5 Default GUI logon
6 Reboot the system

You can check the runlevel you are on by typing runlevel on a Terminal.

Init scripts

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 /etc/rc?.d/ (? is the runlevel). MX Linux default runlevel is 5, so init will execute scripts inside /etc/rc5.d/. Default runlevel is specified on /etc/inittab:


Inside each rc?.d folder, there are symbolic links to files inside /etc/init.d/.

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.

GRUB menu

  • From the desktop: press Ctrl + Alt + F1 to get out of X. Log in as root and run telinit 3.

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.: /etc/rc5.d/).

$ 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