Certification Objective 3.05-Runlevels

Linux services are organized by runlevel. Some runlevels can reboot and halt Linux. Other runlevels can boot Linux with or without networking. The default runlevel for RHEL 5 boots Linux into the GUI.

Runlevels are controlled by scripts, organized in runlevel-based directories. While the default runlevel is defined in /etc/inittab, you can override the default during the boot process from the GRUB menu.

Functionality of Each Runlevel

RHEL has six basic runlevels, as defined in /etc/inittab. Each runlevel is associated with a level of functionality. For example, in single-user mode, also known as runlevel 1, only one user is allowed to connect to that Linux system. X11 mode, also known as runlevel 5, starts Linux into a GUI login screen. The Red Hat definitions for System V init runlevels are shown in Table 3-2.

Table 3-2: Red Hat Runlevels






Single-user mode, for maintenance (backups/restores) and repairs


Multiuser, with some network services


Multiuser, with networking




X11, defaults to a GUI login screen; logins bring the user to a GUI desktop, with networking


Reboot (never set initdefault in /etc/inittab to this value)

Making each runlevel work is the province of a substantial number of scripts. Each script can start or stop fundamental Linux processes such as printing (cupsd), scheduling (crond), Apache (httpd), Samba (smbd), and more. The starting and stopping of the right scripts becomes part of the boot process.

It should go without saying that if you set your initdefault to 0, your system will shut down when Linux tries to boot. Likewise, if you set the initdefault to 6, Linux will enter a continuous reboot cycle.

The default runlevel when you boot RHEL 5 is 5, GUI with networking. If you don't install the GUI on RHEL 5, the default is 3. If you have problems with one runlevel, consider booting into another. For example, if the GUI isn't working, consider booting into runlevel 1, 2, or 3. It allows you to boot into Linux, examine appropriate logs, and address related problems.

Different runlevels can be customized. For example, if you boot into runlevel 1 and have an appropriate network connection, all you need to do is run a command such as dhclient eth0 to activate that network connection.

image from book
Exam Watch

To practice for the Troubleshooting and System Maintenance part of each exam, it can be useful to back up and then modify critical configuration files such as /etc/inittab. But remember to do this on a test computer; if you can't solve the problem, you may lose the data on that computer. Before you proceed, learn the rescue mode techniques described in Chapter 16.

image from book

Runlevel Scripts

There are a series of scripts associated with each runlevel. For example, the default runlevel is 5, and the scripts associated with this runlevel can be found in the /etc/rc.d/rc5.d directory.

Naturally, the scripts associated with other runlevels can be found in other /etc/rc.d directories:

 rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d 

If the default runlevel is 5, init will look in /etc/rc.d/rc5.d and run each "kill" and "start" script it finds in that directory. A kill script is any file or symbolically linked file with a name that begins with a K. Likewise, start scripts start with S. If you run an ls -l command in this directory, you'll see only symbolic links to the actual scripts in /etc/rc.d/init.d. Observe current examples of kill and start scripts at runlevel 5 in Figure 3-4.

image from book
Figure 3-4: Sample kill and start scripts in runlevel 5

On the Job 

init scripts in the /etc/rc.d directories are hard linked to /etc. In other words, you'll see the same script files in the /etc/rc.d/rc5.d and /etc/rc5.d directories. You can confirm this by running the ls -i command on both directories, which displays the same inodes for each matching script file. For brevity, I normally refer to the shorter directory name in this book.

What's going on here? The init process knows to go to the directory associated with a particular runlevel. Once there, init runs the scripts in that directory that start with a K and then the scripts starting with an S. The K scripts stop processes that aren't supposed to operate in that runlevel. The S scripts start the processes associated with that runlevel. Within each category, scripts are run in numeric order; for example, K01yum is run before K35dhcpd, which is run before S10network.

Red Hat configures six different runlevels: 0, 1, 2, 3, 5, and 6. (Runlevel 4 is unused.) Hard links allow the configuration of the same scripts in the /etc/rc.d/init.d and /etc/init.d directories. For example, if you modify /etc/init.d/smb, the changes are automatically shown in /etc/rc.d/init.d/smb.

You can run a start script yourself, with some key switches. For example, you can run the smbd (Samba) and sshd (secure shell daemon) scripts with the following options:

 # /etc/init.d/smb Usage: /etc/init.d/smb {start|stop|restart|reload|status|condrestart} # service smb    # service is a shortcut to the management scripts Usage: /etc/init.d/smb {start|stop|restart|reload|status|condrestart} # service sshd Usage: /etc/init.d/sshd {start|stop|restart|reload|condrestart|status} # 

The /etc/init.d/smb restart command stops and starts Samba. See from the code how you can substitute the service command for /etc/init.d. It's one more timesaver that you can use on the Red Hat exams.

This is used by the scripts at each runlevel. In other words, if a K script exists for the smbd daemon, init runs /etc/init.d/smb stop. And naturally, an S script for the ssh daemon runs /etc/init.d/sshd start.

Examine the scripts at each runlevel, as defined in the /etc/rcx directory, where x is the runlevel. Make a note of the differences. The default difference between runlevels 3 and 5 is subtle. However, runlevel 2 includes fewer network-related scripts than 3; runlevel 1 starts only a couple of services. In contrast, runlevels 0 and 6 start the killall script and execute the halt or reboot services.

image from book
Exam Watch

Make sure you go through the /etc/rc.d hierarchy as well as the /etc/inittab and /etc/rc.d/rc.sysinit files (as specified in /etc/inittab), and understand what's happening along the way. This is the key to understanding what's happening during the boot process.

image from book

Booting into the Runlevel of Your Choice

You should know how to boot into different runlevels during the boot process. As defined in the Red Hat Exam Prep guide, this is explicitly described as an RHCT (and therefore also an RHCE) requirement:

Boot systems into different runlevels for troubleshooting and maintenance.

In other words, you need to know how to boot into a different runlevel from the main GRUB menu. If you do nothing during the boot process, GRUB automatically boots the default operating system and kernel. If you want to see and possibly select from available kernels (and even operating systems), press any key before the following message expires (normally in 5 seconds)

 Press any key to enter the menu 

You'll then see a menu similar to Figure 3-5, from where you can modify how GRUB boots into Linux.

image from book
Figure 3-5: The GRUB boot loader

If you have problems booting into the GUI, first try to boot into runlevel 3, which boots into Linux with all services except the GUI. You can then use the techniques described in Chapter 14 to examine typical problems that can prevent the GUI from starting.

Exercise 3-3: Booting into a Different Runlevel

image from book

One key skill is understanding how to boot into a different runlevel. This exercise assumes you've configured RHEL 5 per the defaults, which sets the default runlevel as 5. Check your /etc/inittab file. If your system reflects the defaults, it should read as follows:


Change this directive if needed and reboot your system. Now you can start the exercise.

  1. When you see the following message, make sure to press any key to access the GRUB menu:

     Press any key to enter the menu 

  2. If the menu is password protected, you'll have to press p before entering the GRUB password. Then you can press a to access the kernel command line.

  3. At the end of the kernel command line, type a space followed by the runlevel of your choice. First, enter 3, and press b to boot this kernel.

  4. Watch the boot messages. What kind of login screen do you see?

  5. Log into this system. You can use any existing user account.

  6. Run the reboot command to restart this system.

  7. Repeat steps 1 through 3, but boot this system into runlevel 1.

  8. Watch the boot messages. What kind of login screen do you see? Do you have to log in at all?

  9. Repeat steps 1 through 3, but boot this system into runlevel s.

  10. Watch the boot messages. What kind of login screen do you see? Do you have to log in at all?

  11. Run the reboot command to restart this system.

  12. Repeat steps 1 through 3, but boot this system into runlevel emergency.

  13. Watch the boot messages. What kind of login screen do you see? What password do you need?

  14. Repeat steps 1 through 3, but boot this system into runlevel init=/bin/sh.

  15. Watch the boot messages. What kind of login screen do you see?

  16. Run the halt command to stop this system.

image from book

More serious problems can be addressed by booting into other runlevels. The standard is to boot into "single-user mode," also known as runlevel 1. Check the scripts in the /etc/rc1.d directory. Note that these scripts typically start only a couple of services.

There are three command alternatives to runlevel 1: s, init=bin/sh, and emergency. To boot Linux at these levels, reboot your system. When you see the GRUB configuration menu described earlier in this chapter, enter the GRUB password if required, and then press a to modify the kernel arguments.

Except for a normal boot of Linux, single-user mode is the most commonly used option. This is the system maintenance mode for experienced Linux administrators. It allows you to perform clean backups and restores to any partitions as needed from local hardware. It also allows you to run administration commands, recover or repair password and shadow password files, run filesystem checks, and so forth.

From single-user mode, type exit and your system will go into multiuser mode. If you have made changes or repairs to any partitions, you should reboot the computer with the reboot command. If you've made changes during your exam, you'll want to test those changes with a reboot.

RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302)
Linux Patch Management: Keeping Linux Systems Up To Date
ISBN: 0132366754
EAN: 2147483647
Year: 2004
Pages: 227
Authors: Michael Jang

Similar book on Amazon
Linux Quick Fix Notebook
Linux Quick Fix Notebook
Self-Service Linux: Mastering the Art of Problem Determination
Self-Service Linux: Mastering the Art of Problem Determination
RHCSA/RHCE Red Hat Linux Certification Study Guide (Exams EX200 & EX300), 6th Edition (Certification Press)
RHCSA/RHCE Red Hat Linux Certification Study Guide (Exams EX200 & EX300), 6th Edition (Certification Press)
Security Strategies in Linux Platforms and Applications (Information Systems Security & Assurance)
Security Strategies in Linux Platforms and Applications (Information Systems Security & Assurance)

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net