个人工具

Quick HOWTO : Ch07 : The Linux Boot Process/zh

来自Ubuntu中文

Newrain讨论 | 贡献2007年9月18日 (二) 18:13的版本 获取一个GUI控制界面

跳转至: 导航, 搜索


简介

了解Linux如何启动很有用,之后您就可以改变登录界面的类型,或者自由选择启动时加载哪些程序。欢迎阅读下面的细节。

Linux启动顺序

您或许还记得,当初安装Linux时,安装程序显示了一份硬盘分区的列表,包含各个分区的大小,您的文件系统将安装在这些分区上。

当为各个分区分配磁盘空间时,每个分区的第一个数据单元,或称之为“扇区”,总是预留给启动代码。整块硬盘的第一个扇区也用于同样的目的,该扇区被称作主引导记录(MBR)。

当由硬盘启动PC时,BIOS被加载,之后运行MBR中的启动引导代码。MBR需要知道哪个分区的引导扇区中包含了操作系统的启动引导代码,之后MBR会试着启动其中的一个。

Fedora Linux发行版使用了非常复杂的GRUB启动引导程序,该程序无法放入MBR的512字节中。GRUB启动引导程序仅搜寻特定的启动分区,找到后加载第二阶段的启动引导程序。GRUB从包含各类操作系统和操作系统的启动参数的配置文件/boot/grub/grub.conf 中读取启动配置数据。当GRUB启动引导程序完成后,第二阶段的启动引导程序在屏幕上显示有Fedora标记的所有你选择的操作系统核心配置。 注意: 在一些操作系统中,如Debian / Ubuntu,配置文件 /boot/grub/grub.conf 可能会被下面的文件取代 /boot/grub/menu.lst.

图7-1显示了能够同时启动Fedora Linux和Windows 2000系统的一个典型grub.conf文件。配置文件的结构将在第33章讨论, "Modifying the Kernel to Improve Performance".


图 7-1 grub.conf 文件示例

default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Fedora Core (2.6.8-1.521)
        root (hd0,0)
        kernel /vmlinuz-2.6.8-1.521 ro root=LABEL=/
        initrd /initrd-2.6.8-1.521.img
title Windows 2000
      rootnoverify (hd0,1)
      chainloader +1


当Linux开始启动内核时,首先运行/sbin/init脚本程序进行一些系统检查,如文件系统完整性的确认和操作系统正常运作的重要程序的启动。 Linux开始检测/etc/initab文件,并决定Linux的全部运行模式和运行级别。有效的运行级别列表见表7-1。

表 7-1 Linux 运行级别 (“()”中中文为译者添加)

Mode Directory Run Level Description
0 /etc/rc.d/rc0.d Halt (关机)
1 /etc/rc.d/rc1.d Single-user mode (单用户模式)
2 /etc/rc.d/rc2.d Not used (user-definable) (未使用,用户自定义)
3 /etc/rc.d/rc3.d Full multi-user mode (no GUI interface) (多用户模式,无图形界面)
4 /etc/rc.d/rc4.d Not used (user-definable) (未使用,用户定义)
5 /etc/rc.d/rc5.d Full multiuser mode (with GUI interface) (多用户模式,图形界面)
6 /etc/rc.d/rc6.d Reboot (重启)

init程序依据选定的运行级别执行在子目录 /etc/rc.d 下的脚本程序.。运行级别0-6分别对应子目录中的 /etc/rc.d/rc0.d -/etc/rc.d/rc6.d

以下是/etc/rc.d/rc3.d目录下的脚本文件列表


[root@bigboy tmp]# ls /etc/rc.d/rc3.d
...    ...    K75netfs      K96pcmcia    ...    ...
...    ...    K86nfslock    S05kudzu     ...    ...
...    ...    K87portmap    S09wlan      ...    ...
...    ...    K91isdn       S10network   ...    ...
...    ...    K92iptables   S12syslog    ...    ...
...    ...    K95firstboot  S17keytable  ...    ...
[root@bigboy tmp]#

如上,你会发现,这些目录中的每个文件名要么是以“S”开头,以表明这些脚本是在系统启动的时候运行,或以“K”开头,表示这类脚本在系统正在关闭的时候被调用。如果一个脚本不在此目录,那么此脚本不会被运行。

大多数linux软件包将它们的启动脚本放在/etc/init.d目录下,并且在/etc/rc.d目录中创建相应的子目录以保存启动脚本的符号连接。如此使得文件管理更为容易。比如说,你只需删除文件的符号连接,而无需删除真实文件,这样以后你还可以使用它。

跟在K或者S后的数字按升序排列也就是这些脚本运行的次序。如,kudzu(后05)将比wlan(后09)先运行。

幸运的是,你不必需要一个总的脚本,或者符号连接来保证所有脚本运行正常。因为Fedora中有一个名为chkconfig的组件,Debian/Ubuntu使用update-rc.d命令来帮你做所有的事情。我们等会在详细讲它。

设置默认的启动级别

系统默认启动级别在文件/etc/inittab,变量initdefault中设置。当被设置为3时,系统以文本模式启动;当被设置为5时,系统将会以图形界面模式启动。这里是此文件的一部分(删除你不需要的initdefault行):


# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
# 
id:3:initdefault:                         # Console Text Mode
id:5:initdefault:                         # Console GUI Mode

注意:

  • 大多数用户以如windows的图形界面启动(runlevel 5)
  • 大多数techies倾向于基于文本的命令行模式启动(runlevel 3)
  • 在3到5之间改动默认启动值(or vice-versa),对下次重启有影响。查看下列章节:如何设置始终图形界面登录直到下次重启。
  • 当然,不要设置默认启动值为6,否则你会不断重启;设置默认启动值0会导致永远开不了机。

获取一个GUI控制界面

手工方法: 每次需要运行X终端GUI应用程序时,通过在VGA控制台模式下运行startx命令启动X终端。记住登出后你将再次返回到基于文本的控制台.

[root@bigboy tmp]# startx

自动方法:可以让Linux在每次登录时自动载入X终端GUI界面,除非用init命令重新启动系统。 需要编辑/etc/inittab文件的初始默认变量,在先前的文章中提到这些变量将使系统重新启动后仍保持这些功能。

[root@bigboy tmp]# init 5

当你的机器中CPU容量或内存变量低的时候或者你需要最大化利用你的资源,大部分时候你需要在runlevel3文本模式下运行系统,必要时通过startx命令启动GUI。

机器可以作为个人工作站或服务器来使用,这对相关非技术员工而言,可能需要花费更多的时间来操作机器。机器通过init 5命令一直运行在runlevel 5。记住,修改/etc/initab文件使得即使重新启动系统也能够一直运行在runlevel 5。

Get a Basic Text Terminal Without Exiting the GUI

There are a number of ways for you to get a command prompt when running a Linux GUI. This can be important if you need quick access to commands or you are not familiar with the GUI menu option layout.

Using a GUI Terminal Window

You can open a GUI-based window with a command prompt inside by doing the following:

  • Click on the Fedora logo button in the bottom left hand corner of the screen.
  • Click on Systems Tools and then Terminal

Using Virtual Consoles

By default, Linux runs six virtual console or TTY sessions running on the VGA console. These are defined by the mingetty statements in the /etc/inittab file. The X terminal GUI console creates its own virtual console using the first available TTY that is not controlled by mingetty. This makes the GUI run as number 7:

  • You can step through each virtual console session by using the Ctl-Alt-F1 through F6 key sequence. You'll get a new login prompt for each attempt.
  • You can get the GUI login with the sequence Ctl-Alt-F7 only in run level 5, or if the GUI is running after launching startx.

System Shutdown and Rebooting

It is usually not a good idea to immediately power off your system when you are finished using it. This can cause files that are being updated to become corrupted, or worse, you could corrupt the filesystem directory structure. Linux has a number of ways to gracefully shut down and reboot your system which will be outlined in this section.


Halt/Shut Down The System

The init command will allow you to change the current runlevel, and for a shutdown, that value is 0. Here is an example:

[root@bigboy tmp]# init 0

Fedora also has a shutdown command which can also be used to the same effect. It often prompts you as to whether you are sure you want to execute the command, which can be avoided with the -y switch. The -h switch forces the system to halt, and the first argument tells it how long to wait before starting the procedure, in this case 0 minutes. You can also specify shutting down at a specific time of the day; please refer to the man pages for details. Another advantage of the shutdown command is that it warns people that the shutdown is going to occur.

[root@bigboy tmp]# shutdown -hy 0

Broadcast message from root (pts/0) (Sat Nov  6 13:15:27 2004):

The system is going down for system halt NOW!
[root@bigboy tmp]#

Reboot The System

You can also use the init command to reboot the system immediately by entering runlevel 6.

[root@bigboy tmp]# init 6

The "reboot" command has the same effect, but it also sends a warning message to all users.

[root@bigboy tmp]# reboot

Broadcast message from root (pts/0) (Sat Nov  6 12:39:31 2004):

The system is going down for reboot NOW!
[root@bigboy tmp]#

More graceful reboots can be done with the shutdown command using the -r switch and specifying a delay, which in this case is 10 minutes.

[root@bigboy root]# shutdown -ry 10

Broadcast message from root (pts/0) (Sat Nov  6 13:26:39 2004):

The system is going DOWN for reboot in 10 minutes!

Broadcast message from root (pts/0) (Sat Nov  6 13:27:39 2004):

The system is going DOWN for reboot in 9 minutes!
...
...
...
Broadcast message from root (pts/0) (Sat Nov  6 13:36:39 2004):

The system is going down for reboot NOW!

Entering Single-user Mode

Some activities require you to force the system to log off all users, third-party applications and networking so that only the systems administrator has access to the system from the VGA console. A typical scenario is the addition of a new hard disk, as mentioned in Chapter 27, "Expanding Disk Capacity", or the troubleshooting of a failed boot process.

Another reason is the recovery of your root password.

Switching to Single-user Mode

When the system is running normally, this can be done by using the init command to enter runlevel 1. It is best to do this from the console, because if you do it from a remote terminal session you'll be logged out.

[root@bigboy root]# init 1
...
...
bash-2.05b#

Unfortunately, this gives no prior warning to users, and the shutdown command doesn't have a single-user mode option. This can be overcome by running the shutdown command with a delay in minutes as the only argument.

[root@bigboy tmp]# shutdown 1

Broadcast message from root (pts/0) (Sat Nov  6 13:44:59 2004):

The system is going DOWN to maintenance mode in 1 minute!

Broadcast message from root (pts/0) (Sat Nov  6 13:45:59 2004):

The system is going down to maintenance mode NOW!

...
...
bash-2.05b#

Entering Single-user Mode At The Grub Splash Screen

You can enter single user mode directly after turning on the power to your system. The steps to do this are listed below.

1. Power on your system. Wait for the "Grub loading" message to appear and, depending on your Linux distribution, get ready to hit either any key or the ESC key to enter the grub boot menu.

Grub loading, please wait ...
Press ESC to enter the menu

or

Grub loading, please wait ...
Press any key to enter the menu

2. You will then get grub's main menu which will display a list of available kernels. Use the arrow keys to scroll to your desired version of the kernel and then press e for "edit".

Fedora Core (2.6.18-1.2239.fc5smp)
Fedora Core (2.6.18-1.2200.fc5smp)

3. The kernel's boot menu will appear. Use the arrow keys to scroll to the "kernel" line and then press e for "edit".

root (hd0,0)
kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/
initrd /initrd-2.6.18-1.2239.fc5smp.img

4. A grub edit prompt will appear. Use the arrow keys to move to the end of the line and add the word "single" to the end, separated by a space. Change

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/

to

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ single

5. Press enter to save your changes, and then b for "boot". 6. The system will continue to boot, but will go straight to the root # prompt without first asking for a username and password.

Reverting To Your Default runlevel From Single User Mode

The exit command forces the system to exit runlevel 1 and revert to the default runlevel for the system. You can also use the init command (for example init 3 and init 5) to alter this default behavior:

bash-2.05b# exit
INIT: Entering runlevel: 3
...
...
...
Fedora Core release 2 (Tettnang)
Kernel 2.6.8-1.521 on an i686
bigboy login:

Root Password Recovery

Sometimes you might forget the root password, or the previous systems administrator may move on to a new job without giving it to you. To do this, follow these steps:

  1. Go to the VGA console and press Ctrl-Alt-Del. The system will then shut down in an orderly fashion.
  2. Reboot the system and enter single-user mode.
  3. Once at the command prompt, change your password. Single user mode assumes the person at the console is the systems administrator root, so you don't have to specify a root username.
  4. Return to your default runlevel by using the exit command.

Starting and Stopping Daemons

A simple definition of a daemon is a programs that runs unattended even when nobody is logged into your system. Common examples of daemons are the syslog daemon which receives system error messages and writes them to a log file; the apache or httpd daemon that serves web pages to Internet web browsers and the sendmail daemon that places email it receives into your inbox.

The startup scripts I have been mentioning in the /etc/init.d directory govern the activation of daemons that were installed with some of your Linux packages. The commands to start and stop them are universal.

Starting a Daemon

If a startup script exists in the /etc/init.d directory, then its daemon can be started by specifying its filename followed by the keyword "start" as seen here:

root@u-bigboy:~# /etc/init.d/apache start
 * Starting apache 1.3 web server...
   ...done.
root@u-bigboy:~#

Stopping a Daemon

Daemons can be stopped by specifying its script filename followed by the keyword "stop":

root@u-bigboy:~# /etc/init.d/apache stop
 * Stopping apache 1.3 web server...
   ...done.
root@u-bigboy:~#

Restarting a Daemon

Daemons usually only read their configuration files when they are started, therefore if you edit the file, you have to restart the daemon for the new settings to become active. This can be done with the keyword "restart":

root@u-bigboy:~# /etc/init.d/apache restart
 * Restarting apache 1.3 web server...
   ...done.
root@u-bigboy:~#

Don’t worry about configuring your daemons. Later we'll be covering some commonly used daemons and will discuss them with ample examples.

The service command

Some operating systems such as Fedora and Redhat also come with the shortcut service command which allows you to control daemons with the "start", "stop" and "restart" keywords, but with less typing. Here are some quick, intuitive examples of doing this:

[root@bigboy ~]# service httpd start
[root@bigboy ~]# service httpd stop
[root@bigboy ~]# service httpd restart

The service command also has the "status" keyword which will provide a brief report on what the daemon is doing.

[root@bigboy ~]# service httpd status
httpd (pid 6135 6133 6132 6131 6130 6129 6128 6127 1561) is running...
[root@bigboy ~]#

Using chkconfig to Start Daemons at Each runlevel

As stated earlier, the chkconfig command can be used to adjust which applications start at each runlevel. You can use this command with the --list switch to get a full listing of packages listed in /etc/init.d and the runlevels at which they will be on or off:

[root@bigboy tmp]# chkconfig --list
keytable 0:off 1:on  2:on  3:on 4:on  5:on 6:off
atd      0:off 1:off 2:off 3:on 4:on  5:on 6:off
syslog   0:off 1:off 2:on  3:on 4:on  5:on 6:off
gpm      0:off 1:off 2:on  3:on 4:on  5:on 6:off
kudzu    0:off 1:off 2:off 3:on 4:on  5:on 6:off
wlan     0:off 1:off 2:on  3:on 4:on  5:on 6:off
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
netfs    0:off 1:off 2:off 3:on 4:on  5:on 6:off
network  0:off 1:off 2:on  3:on 4:on  5:on 6:off
random   0:off 1:off 2:on  3:on 4:on  5:on 6:off
...
...

chkconfig Examples

You can use chkconfig to change runlevels for particular packages. Here we see sendmail will start with a regular startup at runlevel 3 or 5. Let's change it so that sendmail doesn't startup at boot.

Use Chkconfig to Get a Listing of sendmail's Current Startup Options

The chkconfig command can be used with grep to determine the run levels in which sendmail will run. Here we see it will run at levels 3 and 5.

[root@bigboy tmp]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@bigboy tmp]#

Switch Off sendmail Starting Up in Levels 3 and 5

The chkconfig command with the --level switch indicates that some action needs to be done at the runlevels entered as its values. The first argument in the command is the package you want to affect and the second defines whether you want it on or off. In this case we want sendmail not to be started when entering runlevels 3 and 5:

[root@bigboy tmp]# chkconfig --level 35 sendmail off
[root@bigboy tmp]#

By not specifying the runlevels with the --level switch, chckconfig will make the changes for runlevels 3 and 5 automatically:

[root@bigboy tmp]# chkconfig sendmail off

Because the intention is to permanently shutdown sendmail permanently, we might also have to stop it from running now.

[root@bigboy tmp]# service sendmail stop
Shutting down sendmail: [  OK  ]
Shutting down sm-client: [  OK  ]
[root@bigboy tmp]#

Double-check that sendmail Will Not Start Up

We can then use chkconfig to double-check our work.

[root@bigboy tmp]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@bigboy tmp]#

Turn On sendmail Again

To reactivate sendmail, we can use chkconfig once more, but with the on argument. Start sendmail again to get it running immediately, not just after the next reboot.

[root@bigboy tmp]# chkconfig sendmail on
[root@bigboy tmp]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@bigboy tmp]# service sendmail start
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
[root@bigboy tmp]#

Using chkconfig to Improve Security

A default Fedora installation automatically starts a number of daemons that you may not necessarily need for a Web server. This usually results in your system listening on a variety of unexpected TCP/IP ports that could be used as doors into your system by hackers.

The screen output of the netstat -an command below shows a typical case. Some ports are relatively easy to recognize. TCP ports 25 and 22 are for mail and SSH, respectively, but some others are less obvious. Should you use the chkconfig command and the scripts in the /etc/init.d directory to shut these down permanently?

[root@bigboy tmp]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address
State
tcp    0    0 0.0.0.0:32768    0.0.0.0:*     LISTEN
tcp    0    0 127.0.0.1:32769  0.0.0.0:*     LISTEN
tcp    0    0 0.0.0.0:111      0.0.0.0:*     LISTEN
tcp    0    0 127.0.0.1:631    0.0.0.0:*     LISTEN
tcp    0    0 127.0.0.1:25     0.0.0.0:*     LISTEN
tcp    0    0 :::22            :::*          LISTEN
udp    0    0 0.0.0.0:32768    0.0.0.0:*
udp    0    0 0.0.0.0:930      0.0.0.0:*
udp    0    0 0.0.0.0:68       0.0.0.0:*
udp    0    0 0.0.0.0:111      0.0.0.0:*
udp    0    0 0.0.0.0:631      0.0.0.0:*
...
...
[root@bigboy tmp]#

For example, how do you know which startup script is responsible for TCP port 111? The answer is to use the lsof command which lists all open, or actively used, files and can be given additional options to extend its scope to include the TCP/IP protocol stack.

In the next examples we see that TCP ports 111 and 32769, and UDP port 123 are being used by the portmap, xinetd and ntp daemons respectively. The portmap daemon is required for the operation of NFS and NIS, topics that are covered in Chapters 29, "Remote Disk Access with NFS", and 30, "Configuring NIS". portmap also has many known security flaws that makes it advisable to be run on a secured network. If you don't need any of these three applications, it's best to shut down portmap permanently. NTP, which is covered in Chapter 24, "The NTP Server", is required for synchronizing your time with a reliable time source, and may be necessary. A number of network applications are reliant on xinetd, as explained in Chapter 16, "Telnet, TFTP, and xinetd", and it might be required for their operation:

[root@ bigboy tmp]# lsof -i tcp:111
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
portmap 1165  rpc    4u  IPv4   2979       TCP *:sunrpc (LISTEN)
[root@ bigboy tmp #
 
[root@bigboy tmp]# lsof -i tcp:32769
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
xinetd  1522 root    5u  IPv4   2764       TCP probe-001:32769 (LISTEN)
[root@bigboy tmp]#
 
[root@bigboy root]# lsof -i udp:123
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
ntpd    1321  ntp    4u  IPv4   3390       UDP *:ntp
...
...
[root@bigboy root]#

In some cases it's tricky to determine the application based on the results of the lsof command. In the example below, we've discovered that TCP port 32768 is being used by rpc.statd, but there is no rpc.statd file in the /etc/init.d directory. The simple solution is to use the grep command to search all the files for the string rpc.statd to determine which one is responsible for its operation. We soon discover that the nfslock daemon uses it. If you don't need nfslock, then shut it down permanently.

[root@bigboy tmp]# lsof -i tcp:32768
COMMAND    PID    USER   FD   TYPE DEVICE SIZE NODE NAME
rpc.statd 1178 rpcuser    6u  IPv4   2400       TCP *:32768 (LISTEN)
[root@bigboy tmp]# ls /etc/init.d/rpc.statd
ls: /etc/init.d/rpc.statd: No such file or directory
[root@bigboy tmp]# grep -i statd /etc/init.d/*
/etc/init.d/nfslock:[ -x /sbin/rpc.statd ] || exit 0
...
...
[root@bigboy tmp]#

As a rule of thumb, applications listening only on the loopback interface (IP address 127.0.0.1) are usually the least susceptible to network attack and probably don't need to be stopped for network security reasons. Those listening on all interfaces, depicted as IP address 0.0.0.0, are naturally more vulnerable and their continued operation should be dependent on your server's needs. I usually shutdown nfs, nfslock, netfs, portmap, and cups printing as standard practice on Internet servers. I keep sendmail running as it is always needed to send and receive mail (see Chapter 21, "Configuring Linux Mail Servers", for details). Your needs may be different.

Remember to thoroughly research your options thoroughly before choosing to shut down an application. Use the Linux man pages, reference books and the Internet for information. Unpredictable results are always undesirable.

Shutting down applications is only a part of server security. Firewalls, physical access restrictions, password policies, and patch updates need to be considered. Full coverage of server and network security is beyond the scope of this book, but you should always have a security reference guide on hand to guide your final decisions.

Final Tips on chkconfig

Remember the following:

  • In most cases, you want to modify runlevels 3 and 5 simultaneously and with the same values.
  • Don't add/remove anything to other runlevels unless you absolutely know what you are doing. Don't experiment, unless in a test environment.
  • chkconfig doesn't start the programs in the /etc/init.d directory, it just configures them to be started or ignored when the system boots up. The commands for starting and stopping the programs covered in this book are covered in each respective chapter.

Using sysv-rc-conf to Start Daemons at Each runlevel

With Debian / Ubuntu Linux, the update-rc.d command replaces chkconfig as the default package for modifying /etc/init.d script links. Unfortunately, the utility was written to facilitate link modification when packages are installed or removed, but is less friendly when you need to alter links for existing packages you want to keep.

Fortunately there is hope for the harried systems administrator in the form of the sysv-rc-conf package which uses an almost identical syntax to chkconfig, and has a GUI mode if you run it from the command line without any arguments. This section will show you some important tips in using sysv-rc-conf.

Installing sysv-rc-conf

The sysv-rc-conf package can be installed easily using apt-get. Here is an example.

root@u-bigboy:~# apt-get install sysv-rc-conf

Listing the runlevels for Daemons

This can be done with the --list option. In this example below we get a listing for only the apache daemon.

root@u-bigboy:~#  sysv-rc-conf  --list apache
apache       0:off      1:off   2:on    3:on    4:on    5:on    6:off
root@u-bigboy:~#

Here we get a listing for everything.

root@u-bigboy:~#  sysv-rc-conf  --list
acpi-support 0:off      1:off   2:on    3:on    4:on    5:on    6:off
acpid        0:off      1:off   2:on    3:on    4:on    5:on    6:off
alsa-utils   0:off      6:off
…
…
…
vbesave      2:on       3:on    4:on    5:on
x11-common   S:on
root@u-bigboy:~#

Setting the runlevels for Daemons

The sysv-rc-conf program has further similarities to the chkconfig syntax. Here we set the apache daemon to start automatically at levels 2 through 5.

root@u-bigboy:~# sysv-rc-conf  apache on

Similarly, we can set the apache daemon not to start at levels 2 through 5 with this command:

root@u-bigboy:~# sysv-rc-conf  apache off

Finally we can use set the apache daemon to start only at levels 3 and 5.

root@u-bigboy:~# sysv-rc-conf  --level 35 apache on

Conclusion

The topics discussed in this chapter might seem simple, but like syslog, which was covered in Chapter 5, "Troubleshooting Linux with syslog", they are an essential part of Linux administration that gets frequently overlooked especially when new software is installed.

Whenever possible, always try to reboot your system to make sure all the newly installed applications start up correctly. Sometimes they start but give errors listed only in the /var/log directory. Taking the time to configure and test your startup scripts could prevent you from being awakened in the middle of the night while you are on vacation! It is really important.