How To Customize Your Startup Routine In Debian

Every modern operating system has some sort of startup routine. Even DOS had the old AUTOEXEC.BAT and CONFIG.SYS. The startup system defines what is launched on system startup, under what conditions, and in what order. DOS did things the simple way, having a file that was read on every boot that would run commands in whatever order they’re placed in the file. It is indeed simple, but like much of DOS, not nearly powerful or flexible enough to cut it these days.

Nearly all Linux variants use a startup routing modeled after the one found in UNIX System V. Ubuntu uses a system called Upstart which is meant to be backward-compatible with the normal SysV Init. These all run based on the concept of runlevels. A runlevel is simply a set of instructions for bootup/shutdown. If your Linux is set to use, for example, runlevel 5 by default, then every time you boot up you’re going to run all the startup scripts for runlevel 5. The following example shows how the runlevels are set up on a standard Debian installation.

  • 0 – Halt
  • 1 – Single User
  • 2 – Full Multi-User
  • 3 – Full Multi-User
  • 4 – Full Multi-User
  • 5 – Full Multi-User
  • 6 – Reboot

These can be customized by the makers of each distro, so some may default to different runlevels than others. Debian typically defaults to runlevel 2.

To find out your default runlevel, open a console and enter:

cat /etc/inittab | grep initdefault

Or just open /etc/inittab in your text editor of choice and look toward the top for the “initdefault” line.

Now that we know which runlevel our system is using, we can begin trimming out the unneeded parts. Each runlevel has a directory on the system with all the startup scripts. Right now, we’re only worried about the scripts for runlevel 2. Open your file manager or command prompt to /etc/rc2.d. In that directory are all the links to your startup programs for that runlevel.

Example of contents of /etc/rc2.d

You’ll see that each starts with a letter (S or K) followed by a two digit number (00-99). Those scripts that begin with S are started when that runlevel is entered, those beginning with K are killed when the runlevel is entered. The numbers represent the order to run those scripts. For example, S05Foo would start before S80Bar.

There’s a pretty good chance you won’t recognize some of the items listed in that directory. Some of them are pretty clear like “network-manager” while others are more cryptic. If you’re not sure what you can safely remove, look for a man page on that item. For example, if you’re not sure what “acpid” is, enter

man acpid

into your terminal. If man has no entry, there’s always Google.

Now, to begin removing unneeded items. You COULD simply delete the scripts in the rc2.d directory (they’re actually just links to the real scripts) but I wouldn’t recommend that method. It would work in that it would prevent the script from being run on startup, but it could leave open “K” scripts in other runlevels, and it makes it more difficult to restore that item should you need it later. As usual, Debian has a better way.

The command update-rc.d can be used to cleanly add and remove startup items from your runlevel. I have no bluetooth capability on this computer, so I’m going to remove the bluetooth startup item.

update-rc.d -f bluetooth remove

The same method can be used for each item in your default runlevel that you want to remove. If in doubt, leave it there.

If you find yourself wanting to restore that startup item later, the same tool can be used to add services to runlevels. If I later add bluetooth capability to this computer, I can restore that service with

update-rc.d bluetooth defaults

Once you’ve removed all the unnecessary items for your startup, you’ll find your machine boots much more quickly and takes up fewer system resources.

There are other methods from controlling your startup routine, some include graphical utilities to make it easier. If you use a graphical tool for managing your startup, leave a comment and tell me which one and what you like about it.