Regardless of what distribution you install, when you run a Linux installer you tend to pick one, or other, of the "standard" installations. This generally means that when you boot up for the first time, you'll end up with stuff running that you didn't want. There are a couple of good reasons why you wouldn't want this to happen: first, anything that's running unnecessarily takes memory and processor cycles; second, and more importantly, a lot of Linux packages are network-related and to have them sitting listening for incoming connections may give you a security hole.

What's running?
The first place to look to see what's running is the boot-up screen. As Linux starts, you see a bunch of text floating up the screen, most of which comprises lines that say: "Starting XXX". So have a scan and see if there's anything that strikes you as unwanted (if you're not using database services, for instance, you might spot that "Starting MySQL" is telling you that there's a database system running that you don't want).

Where to look
When it starts up, Linux looks at its startup directories to see what services to fire up. All Unix family operating systems have the concept of a "runlevel", which is the state to which the system boots. The two most common runlevels are 3 (standard multi-user mode with a command line prompt on the console screen) and 5 (multi-user mode with a graphical X-Windows user interface). You can see which runlevel your system is operating in by looking in /etc/inittab; you'll see an "initdefault" line that looks something like:

id:5:initdefault

… which in this case tells us that the system will run at level 5 – multi-user with X-Windows.

Linux's startup files live in a set of directories under /etc/rc.d. The actual startup scripts themselves live in /etc/rc.d/init.d, and the directories that relate to the various runlevels have symbolic links (like Windows shortcuts) to these main scripts.

Each runlevel has a directory within /etc/rc.d – these are called rc1.d, rc2.d, and so on – the number relates to the runlevel. So for runlevel 5, we care about the contents of /etc/rc.d/rc5.d.

Within each directory are a set of "stop" links (labelled Kxxxxx) and a set of "start" links (Sxxxxx). When Linux moves to a given runlevel, it starts all the services that start with an S, and stops those that start with a K (if they're running). So if you have an item "S80sendmail" in /etc/rc.d/rc5.d, this means that it'll start the Sendmail email transport service when Linux boots.

Services are started and stopped in ascending lexicographic order of their link name in the startup directory. So S80sendmail would be started before S80spamassassin, because this is the order they'd appear in an alphabetic list. If you compare the runlevel 5 directory with, say, the runlevel 1 (single user with little running) you'll see that the "K" entries in the level 1 directory are ordered, to a large extent, in reverse order from the "S" entries in level 5. This makes sense – if you start X after Y because X can't run unless Y's already going, it makes sense to stop X before you stop Y when the time comes to turn things off.

If you want to disable something in your current runlevel, you'll need to change its "S" script to a "K" script. The trick here is to figure out what you need to change the ordering to – for instance, Sendmail starts up as S80sendmail, but stops as S30sendmail. The trick is to look in the runlevel 0 (halt) directory, as this shuts down pretty well everything, for a "K" script from which you can crib the appropriate number. So let's assume we want to stop the CUPS (printing) service from running. Its startup script in /etc/rc.d/rc5.d is called S90cups, so let's do a quick scan for items in /etc/rc.d/rc0.d that are called K??cups:

[[email protected] rc5.d]# ls /etc/rc.d/rc0.d/K*cups /etc/rc.d/rc0.d/K10cups

This gives us the clue that we should use 10 as our ordering. The trick now is to realise that the start and stop entries in the runlevel startup directories are just links to the real scripts, which live in /etc/rc.d/init.d, and that the script deals with both startup and shutdown items. So all we need to do to disable our service is to rename the "S" script in /etc/rc.d/rc5.d to the right "K" filename:

[[email protected] rc5.d]# mv S90cups K10cups

One other quick hint: the name of the startup item often makes it hard to guess what the script does. If this is the case, find the script with the appropriate name in /etc/init.d, because there are usually loads of comments at the top of each script describing what the package does.

Pretty GUI
Under most Linuxes, you don't have to muck about with these files – assuming you're running the GUI runlevel (5) you'll get a pretty application that lets you just tick the things you want to start. In Red Hat 9, you'd go to System Settings->Server Settings->Services to run this tool. The GUI tool is quite nice, because as well as letting you easily tell it which services you do and don't want, it has a nice description for each item so you don't have to guess what it's for from its (usually cryptic) name. The GUI-based system doesn't do anything that you wouldn't be able to do by hand (it just manipulates links in the same way as we've discussed) but it does make life easier.