► http://localhost/localdomain/— Your Fedora system contains man and info pages on just about everything covered here. Use man -k
to search on a keyword.
CHAPTER 11
Automating Tasks
In this chapter, you will learn about the three ways to automate tasks on your system: making them services that run as your system starts, making them services you start and stop by hand, and scheduling them to run at specific times.
After you turn on the power switch, the boot process begins with the computer executing code stored in a chip called the BIOS; this process occurs no matter what operating system you have installed. The Linux boot process begins when the code known as the boot loader starts loading the Linux kernel and ends only when the login prompt appears.
As a system administrator, you will use the skills you learn in this chapter to control your system's services and manage runlevels on your computer. Understanding the management of the system services and states is essential to understanding how Linux works (especially in a multi-user environment) and will help untangle the mysteries of a few of your Fedora system's configuration files. Furthermore, a good knowledge of the cron
daemon that handles task scheduling is essential for administrators at all skill levels.
In this chapter, you'll take your first steps in shell scripting, but if you want to take it further, Chapter 33, "Writing and Executing a Shell Script," is dedicated exclusively to programming shell scripts. These are preset lists of commands that you want to execute all at once, so putting them in a shell script means you can just type the name of the script and all the commands run in sequence. For now, though, we're more interested in having things done automatically for us without much user intervention.
Running Services at Bootup
Although most people consider a computer to be either on or off, in Fedora there are a number of states in between. Known as runlevels , they control what system services are started at bootup. These services are simply applications running in the background that provide some needed function to your system, such as getting information from your mouse and sending it to the display; or a service could monitor the partitions to see whether they have enough free space left on them. Services are typically loaded and run (also referred to as being started ) during the boot process, in the same way as Microsoft Windows services are.
You can manage nearly every aspect of your computer and how it behaves after booting via configuring and ordering boot scripts, as well as by using various system administration utilities included with Fedora. In this chapter, you learn how to work with these boot scripts and system administration utilities. This chapter also offers advice for trouble shooting and fixing problems that might arise with software configuration or the introduction or removal of various types of hardware from your system.
Beginning the Boot Loading Process
Although the actual boot loading mechanism for Linux varies on different hardware plat forms (such as the SPARC, Alpha, or PowerPC systems), Intel-based PCs running Fedora most often use the same mechanism throughout product lines. This process is accomplished through a Basic Input Output System, or BIOS. The BIOS is an application stored in a chip on the motherboard that initializes the hardware on the motherboard (and often the hardware that's attached to the motherboard). The BIOS gets the system ready to load and run the software that we recognize as the operating system.
As a last step, the BIOS code looks for a special program known as the boot loader or boot code . The instructions in this little bit of code tell the BIOS where the Linux kernel is located, how it should be loaded into memory, and how it should be started.
If all goes well, the BIOS looks for a bootable volume such as a floppy disk, CD-ROM, hard drive, RAM disk, or other media. The bootable volume contains a special hexadecimal value written to the volume by the boot loader application (likely either GRUB or LILO, although LILO is not provided with Fedora) when the boot loader code was first installed in the system's drives. The BIOS searches volumes in the order established by the BIOS settings (for example, the floppy first, followed by a CD-ROM, and then a hard drive) and then boots from the first bootable volume it finds. Modern BIOSs allow considerable flexibility in choosing the device used for booting the system.
NOTE
If the BIOS detects a hardware problem, the boot process fails and the BIOS generates a few beeps from the system speaker. These "beep codes" indicate the nature of the problem the BIOS has encountered. The codes vary among manufacturers, and the diagnosis of problems occurring during this phase of the boot process is beyond the scope of this book and does not involve Linux. If you encounter a problem, you should consult the motherboard manual or contact the motherboard's manufacturer.
Next, the BIOS looks on the bootable volume for boot code in the partition boot sector also known as the Master Boot Record ( MBR ) of the first hard disk. The MBR contains the boot loader code and the partition table — think of it as an index for a book, plus a few comments on how to start reading the book. (We cover the MBR in more detail in Chapter 35, "Managing the File System.") If the BIOS finds a boot loader, it loads the boot loader code into memory. At that point, the BIOS's job is completed, and it passes control of the system to the boot loader.
The boot loader locates the Linux kernel on the disk and loads it into memory. After that task is completed, the boot loader passes control of the system to the Linux kernel. You can see how one process builds on another in an approach that enables many different operating systems to work with the same hardware.
Fedora can use a variety of boot loaders, including GRUB (the default for Fedora), LILO (a long-time standard but not available with Fedora), BootMagic (a commercial program), and others.
NOTE
Linux is very flexible and can be booted from multiple images on a CD-ROM, over a network using PXE (pronounced "pixie") or NetBoot, or on a headless server with the console display sent over a serial or network connection. Work is even underway to create a special Linux BIOS at http://www.linuxbios.org/ that expedites the boot process because Linux does not need many of the services offered by the typical BIOS.
This kind of flexibility enables Linux to be used in a variety of ways, such as remote servers or diskless workstations, which are not generally seen in personal home use.
In a general sense, the kernel manages the system resources. As the user, you do not often interact with the kernel, but instead just the applications that you are using. Unix refers to each application as a process, and the kernel assigns each process a number called a process ID (PID) . First, the Linux kernel loads and runs a process named init
, which is also known as the "father of all processes" because it starts every subsequent process. The init
process looks for a list of instructions in a file named /etc/rc.d/rc.sysinit
. That script issues a number of commands that are run only once—each time the system is turned on.
NOTE
Details about the sequence of events that occur when the Linux kernel is loaded can be found in the file /usr/src/iinux-2.6/init/main.c
if you installed the Linux kernel documentation.
This next step of the boot process begins with a message that the Linux kernel is loading, and a series of messages is printed to the screen, giving you the status of each command in rc.sysinit
script language. A failure should display an error message. The - quiet
option may be passed to the kernel at boot time to suppress many of these messages.
Читать дальше