System V Startup Scripts

Changing the default run level

On startup, the system enters one of five possible run levels. The default run level is specified in /etc/inittab with the following entry early in the file:

# The default runlevel.
id:2:initdefault:

After installation this is usually set to startup in level 2. Level 1 is 'single-user' mode and does not allow remote login. It is useful to be able to still remotely login, but have a minimal number of services running. E.g. This would allow un-mounting of /var which would otherwise be in use. To achieve this, we need to change the default run level to 3.

# The default runlevel.
id:3:initdefault:

The entries in run levels 2 and 3 should be identical after install, but it is worth checking they're the same.

We can then switch to run level 3 with:

# telinit 3

Rename the links in run level 2, leaving only those necessary to run SSH. E.g. the following entries for run level 2 leaves SSH running and allows un-mounting of /var:

  /etc/rc2.d:
  used 7 available 121612
  drwxr-xr-x  2 root root 1024 2007-08-06 16:06 .
  drwxr-xr-x 90 root root 5120 2007-08-06 16:09 ..
  lrwxrwxrwx  1 root root   17 2007-03-21 13:14 K09apache2 -> ../init.d/apache2
  lrwxrwxrwx  1 root root   19 2007-04-25 17:29 K10tomcat5.5 -> ../init.d/tomcat5.5
  lrwxrwxrwx  1 root root   14 2007-03-21 12:22 K11cron -> ../init.d/cron
  lrwxrwxrwx  1 root root   26 2007-04-27 11:19 K20clamav-freshclam -> ../init.d/clamav-freshclam
  lrwxrwxrwx  1 root root   15 2007-03-21 12:22 K20exim4 -> ../init.d/exim4
  lrwxrwxrwx  1 root root   16 2007-04-24 10:29 K20kannel -> ../init.d/kannel
  lrwxrwxrwx  1 root root   13 2007-03-21 13:14 K20lpd -> ../init.d/lpd
  lrwxrwxrwx  1 root root   23 2007-03-21 13:14 K20openbsd-inetd -> ../init.d/openbsd-inetd
  lrwxrwxrwx  1 root root   15 2007-03-26 15:01 K20rsync -> ../init.d/rsync
  lrwxrwxrwx  1 root root   15 2007-04-23 17:39 K21mysql -> ../init.d/mysql
  lrwxrwxrwx  1 root root   19 2007-04-23 17:39 K22mysql-ndb -> ../init.d/mysql-ndb
  lrwxrwxrwx  1 root root   23 2007-04-23 17:39 K23mysql-ndb-mgm -> ../init.d/mysql-ndb-mgm
  lrwxrwxrwx  1 root root   13 2007-05-24 10:15 K23ntp -> ../init.d/ntp
  lrwxrwxrwx  1 root root   15 2007-03-21 12:23 K25mdadm -> ../init.d/mdadm
  lrwxrwxrwx  1 root root   20 2007-03-21 13:14 K79nfs-common -> ../init.d/nfs-common
  lrwxrwxrwx  1 root root   13 2007-03-21 12:22 K89atd -> ../init.d/atd
  lrwxrwxrwx  1 root root   15 2007-03-21 12:22 K89klogd -> ../init.d/klogd
  lrwxrwxrwx  1 root root   18 2007-03-21 12:22 K90sysklogd -> ../init.d/sysklogd
  -rw-r--r--  1 root root  556 2007-01-30 22:27 README
  lrwxrwxrwx  1 root root   17 2007-03-21 13:14 S18portmap -> ../init.d/portmap
  lrwxrwxrwx  1 root root   17 2007-03-21 12:22 S20makedev -> ../init.d/makedev
  lrwxrwxrwx  1 root root   13 2007-03-21 13:16 S20ssh -> ../init.d/ssh
  lrwxrwxrwx  1 root root   18 2007-05-24 09:33 S99rc.local -> ../init.d/rc.local
  lrwxrwxrwx  1 root root   19 2007-03-21 12:22 S99rmnologin -> ../init.d/rmnologin
  lrwxrwxrwx  1 root root   23 2007-03-21 12:22 S99stop-bootlogd -> ../init.d/stop-bootlogd

You will probably need to ssh as root to be able to unmount /home etc.

You can then switch to run level 2 with:

# telinit 2

After a while, the unwanted services should have stopped. You can check /var/log/syslog or check the output of 'ps' to see what is left running.

-- Frank Dean - 06 Aug 2007