CHAPTER 3. Booting Linux
Exam objectives in this chapter
■ GRUB
■ Runlevels
■ Troubleshooting Boot Issues

Introduction

The Linux boot process starts when the system is powered up and the hardware is checked by the system BIOS and then determines what device (for example, floppy disk drive, hard disk drive, CD/DVD drive) will be used to boot the system. This first sector of the boot device contains the Linux bootloading program (for example, LILO, GRUB, NTLOADER), although we will describe the Grand Unified Bootloader (GRUB) program, which we will use throughout this book. The system BIOS loads GRUB into memory and executes the program and system control is now transferred to the bootloader. The various processes are described in the following sections.

Exam Warning
For the Linux+ exam, the Linux booting process is based on the Intel x86 CPU architecture. Linux also supports the booting of other CPU hardware architectures (for example, AMD, Alpha, ARM, IA-64, m68k, MIPS, PA-RISC, PowerPC, S/390, SPARC), but the boot processes are different.

GRUB

GRUB is used for starting modern Linux operating systems and is the first program on any storage device that the computer executes. The purpose of the boot-loader program is to perform a sequence of events on your computer to load the main operating system. In essence, the bootloader receives control from the system BIOS process, performs a sequence of events, and then transfers control to the operating system kernel.
Most modern bootloaders are dynamically configurable and can be executed during and after the system has been booted. The bootloader can load pre-defined configuration files during startup or can support boot-time changes (for example, selecting different kernels, virtual file systems) via a boot command line prompt. In addition, the bootloader application can make modifications to boot-time configuration files and test the files prior to using them after control has been transferred to the operating system kernel.

Installing GRUB and Booting Linux

Prior to the execution of GRUB, the system BIOS loads into memory the Master Boot Record (MBR) and executes it contents. The total size of the MBR is 512 bytes, which contains the bootloader program and disk partitioning information. The preinstallation form of the GRUB program is divided into two stages and the MBR loads GRUB stage 1. The stage 1 program uses the first 446 bytes with the remaining 64 bytes allocated to the partition table of the hard disk drives. The purpose of GRUB stage 1 is to find and load GRUB stage 2 (which may reside physically elsewhere on the hard disk). GRUB stage 1 must be flexible enough to access many different file system types. This flexibility is accomplished because GRUB stage 1 has loaded a large number of mass storage device drivers. Once loaded, GRUB stage 2 can perform the following three different functions:
■ load a predefined Linux kernel (for example, vmlinuz-version.gz).
■ allow selection of which operating system to boot on dual boot system.
■ entry of different boot parameters.
Once GRUB stage 2 has loaded the Linux kernel, it must also load a virtual file system and execute the Linux kernel.

Fast Facts
Linux is started using a bootloader, often using GRUB which can be summarized as follows.
■ Is loaded by the BIOS and resides in the MBR.
■ Can access many different filesystems (ext3, file allocation table (FAT), VFAT, and so forth).
■ Is dynamically configurable after you have installed Linux.
■ Main configuration file is /etc/grub.conf.
■ GRUB boot menu is /boot/grub/menu.1st.

GRUB Configuration Files and Commands

GRUB is a dynamically configurable bootloader application and allows for postinstallation changes to the system for ensuring a successful boot-up process, if device changes or Linux kernel modifications are required. The GRUB application allows for alterations to three important configuration files.
The first file, /etc/grub.conf, contains information about the disk partition used to find and load GRUB stage 2, as shown in Figure 3.1. This file instructs GRUB stage 1 where to look for the GRUB stage 2 image (/boot/grub/stage2) for loading.
B9781597494977000062/f03-01.jpg is missing
FIGURE 3.1.
/etc/grub.conf File
The second file, /boot/grub/menu.lst, is a file that functions as the GRUB Boot Menu. It contains content about the partitions and operating systems that can be booted, the loading of different kernels, the establishing of a different default kernel, and various other boot option modifications, as shown in Figure 3.2. The Troubleshooting Boot Issues section, presented later in this chapter, provides GRUB prompt procedures for entering commands that can be issued to dynamically modify the Linux kernel loading and runlevel processes.
B9781597494977000062/f03-02.jpg is missing
FIGURE 3.2.
/boot/grub/menu.lst File
The /boot/grub/menu.lst file options used for modifying and/or selecting a different kernel and various other functions are presented in Table 3.1.
Table 3.1. /boot/grub/menu.lst Options

/boot/grub/menu.lst OptionsPurpose
defaultThis option is used to instruct the system to use the designated Title entry to boot by default. Examples include:
■ default 0 – for the first menu
■ default 1 – for the second menu
■ default 2 – for the third menu
timeoutThis option is to instruct the system to immediately boot the default selection or wait a prescribed amount of time. Examples include:
■ timeout 5 – means wait 5 s before automatically booting the system.
■ timeout 10 – means wait 10 s before automatically booting the system.
■ timeout 0 – means boot the default selection immediately.
titleThis option indicates the setting displayed by the boot-menu title. Examples include:
■ title Linux
■ title Failsafe
■ title GNOME User Interface
rootThis option provides a device or partition name indicating the location of the kernel and initrd files. Examples include:
■ root (hd0,0) – this represents the first hard drive and the first partition.
■ root (hd0,1) – this represents the first hard drive and the second partition.
kernelThis option presents the location and name for the Linux kernel (for example, vmlinuz). This is the option used to select a different kernel to boot the system. It also specifies the default runlevel by placing the number at the end of the line. Examples include:
■ kernel/vmlinuz-version
■ kernel/boot/vmlinuz-version
initrdThis option provides the name and location of the virtual file system. This is the option used to select a different virtual file system. Examples include:
■ initrd/boot/initrd
■ initrd/initrd
root = /disk partitionThis option instructs the system where to mount the Linux root (/) directory. This is the option to use if a different device and/or partition is used for the root (/) directory. Examples include:
■ root = /dev/sda2
■ root = /dev/sdb1
showoptsThis option is used to display parameters listed after this option on the boot screen. Examples include:
■ showopts acpi = off ide = nodma
The final configuration file, /boot/grub/device.map, is a unique file whose purpose is to map the Linux device names to the GRUB/BIOS device naming conventions, shown below:
(fd0)/dev/fd0
(hd0)/dev/sda
GRUB is also an executable program (known as GRUB Shell) accessible from the root prompt and offers the following:
■ change the disk order
■ view other boot loaders
■ view hard disk partition details
■ modify partition settings
■ boot user-defined configuration files
■ password protect the system during the bootloading process
Using this command, you can install or test GRUB configuration settings before applying the modifications to the system during the next boot process. To implement changes made to the GRUB configuration device.map file, from the Linux prompt, execute the following command to reload device.map and execute commands listed in the grub.conf file.
grub –batch</etc/grub.conf

Did You Know?
GRUB is a bootloader for Linux and also an executable shell command to configure the bootloader from the root prompt. You can test new boot time configuration settings prior to applying them. This is useful if you need to modify the partition details or to boot new configuration files.
In rare occasions, you may be required to reinstall the GRUB preinstallation application to the hard disk on a running system. To accomplish this task, you can use the grub-install command, as shown in Figure 3.3. This command installs GRUB to either the MBR or another partition and checks for errors.
grub-install/dev/sda
B9781597494977000062/f03-03.jpg is missing
FIGURE 3.3.
Grub-install/dev/sda

Runlevels

This section introduces the functionality of the init program and the seven different runlevels.

The init Command

The init command is responsible for executing runlevels and is the last step in the boot process. It will be identified by the process id of 1. It is responsible for starting system process defined in the /etc/inittab file.

Runlevels

Runlevels are specialized scripts that define how a computer system starts or stops by executing various services or processes and the level of root administration and user access. The runlevel is changed by having a privileged user run teleinit or init, which sends appropriate signals to init.
Seven different runlevels exist, numbered from 0 through 6 although runlevel 4 is not often used.

Fast Facts
Knowledge of the runlevels and what each is designed to do is very important and the most important are described as follows:
■ 0 terminates all programs and shuts down the system.
■ 1 is for single-user mode; s or S can also be used.
■ 2 is for multiuser mode without network connectivity.
■ 3 is for multiuser mode with network connectivity and starts in command line mode.
■ 5 starts multiuser mode with network connectivity and starts the graphical user interface (GUI).
■ 6 reboots the system.
Most systems set their default runlevels to either 3 or 5.
To execute runlevels, two types of scripts are located in the /etc/init.d directory called through symbolic links. The first set of scripts, executed by the init command, is started during the system's boot process or whenever you initiate the shutdown process. These scripts are contained in the /etc/inittab file, as shown in Figure 3.4. The default runlevel setting is located in the file /etc/inittab. The default runlevel entry looks like the following in the file:
id:5:initdefault:
B9781597494977000062/f03-04.jpg is missing
FIGURE 3.4.
Linux Inittab Scripts File
For the file presented in Figure 3.4, the runlevel is configured to startup in multiuser mode and provide network connectivity and X Windows support for Windows Managers. The file also indicates what subdirectory to search for specific services or programs to execute. For the default runlevel, /etc/init.d/rc5.d is the directory containing default services and programs scripts. Each of the runlevel folders contain scripts that are executed when a runlevel is started and stopped. For files containing scripts used for starting a runlevel, these files begin with the capital letter “S.” For files containing scripts used for stopping a runlevel, the files begin with the capital letter “K.” The second sets of scripts are executed whenever the runlevels are changed from one runlevel to another runlevel. The /etc/init.d/rc file is called to ensure the scripts are executed in the proper sequence.

Troubleshooting Boot Issues

This section provides an overview of different options available to resolve Linux boot issues. dmesg is used to send kernel messages to a standard output (for example, console). The kernel can send messages to the computer monitor representing hardware devices detected and configured during startup. dmesg accomplishes this by being able to print or control the kernel ring buffer and can assist in troubleshooting or obtaining information about system hardware. The dmesg syntax is as follows:
dmesg [-c] [-n level] [-s bufsize]
■ “-c” clears the kernel ring buffer.
■ “-s bufsize” determines the buffer size to query from the kernel ring buffer. The default size is 16392.
■ “-n level” determines the type of messages sent to the computer monitor. When “-n 1” is used, only panic messages appear on the computer monitor. All other messages are prevented. The dmesg command will not print or clear the kernel ring buffer when the “-n” option is used.
Entering dmesg (or dmesg | more) without any parameters will display the entire list of kernel messages sent to the standard output.

Crunch Time
The use of dmesg when you are trying to resolve boot time issues is very useful and important to remember for the exam. The command will be able to show you the hardware devices the kernel detects and if it can configure them.
The next option, kernel options, allows you to enter information to be executed by the Linux kernel during the booting of the system. The kernel parameters can be added by editing /boot/grub/menu.lst or by entering information at the boot prompt. The /boot/grub/menu.lst provides the default kernel parameters, as shown earlier in Figure 3.2. In addition, failsafe kernel parameters can be predefined that will enable Linux to boot even under problematic circumstances. To dynamically modify the kernel during the boot process with GRUB, you can enter various kernel parameters such as the modification of the runlevel parameter.

Fast Facts
The use of a Rescue System is very useful as it loads a specialized kernel without a GUI from a variety of sources.
■ The original distribuition disk can be used, so you can then modify configuration files, check the file system for defects, verify and/or modify the bootloader configuration, resize the partition, and make a few other critical system modifications that may be necessary.
■ You can use a Live CD that allows you to perform a system rescue by booting the system and then mounting the disk partitions to fix or repair configuration or boot issues. These can be on CD, DVD, or even a USB memory stick.
Single-user mode is used to bypass the requirement to enter a root password (many Linux distributions now force the entering of a root password). Typically, this option is used to gain access to the root prompt to change a lost or forgotten password. When the Linux system is booted under runlevel 1 (single-user mode), you will directly get a root prompt and you can execute the passwd command to modify the root password. As you are logged in as root, you will not be prompted to enter the old password.

Summary of Exam Objectives

In this chapter, we discussed the Linux boot process and the information you will be required to know during the booting of a Linux system. GRUB is one of the default bootloading applications and loads the Linux kernel from the specified boot device. GRUB is used during the initial booting of the system and afterwards as an application to install or test GRUB configuration settings prior to applying the modifications to the system during the boot process. Three critical GRUB configuration files were presented: /etc/grub.conf, /boot/grub/menu.lst, and /boot/grub/device.map. The grub-install command is used to reinstall the GRUB preinstallation application to the hard disk on a running system. This command installs GRUB to either the MBR or a partition and checks for errors.
Runlevels use a collection of scripts that define how a computer system starts or stops by executing various services or processes and the level of root administration and user access. The runlevels are numbered from 0 through 6 with the default runlevel settings for the systems located in the /etc/inittab file.
The final section, Troubleshooting Boot Issues, introduced approaches to resolve boot problems. The dmesg command can assist in troubleshooting or obtaining information about system hardware and is used to send Linux kernel messages to a standard output by being able to print or control the kernel ring buffer.
The dynamic modification of the kernel option allows you to enter information to be executed by the Linux kernel during the booting of your system. The kernel parameters can be added by editing /boot/grub/menu.lst, entering information at the boot prompt or by dynamically modifying the kernel during the boot process with GRUB.
The System Rescue approach starts a specialized Linux kernel without a GUI. The Linux kernel loaded can be obtained from a bootable device (for example, LiveCD). Once the Linux kernel is loaded into RAM, you can modify configuration files, check the file system for defects, verify and/or modify the boot loader configuration, resize the partition, and a few other critical system modifications that may be necessary.
1. You are the IT system administrator for the Linux systems in your department. You need to make changes to the default runlevel setting. Which file contains the default runlevel setting?
A. /etc/inittab
B. /etc/grub.boot/inittab
C. /boot/grub/device.map
D. /etc/init.d
2. Your IT department has made several hardware device changes. These include changes like modifications to the hard disk drives. You need to make modifications to the GRUB bootloader. Which file should you edit to configure the GRUB stage 2 image?
A. /etc/menu.lst
B. /boot/grub/menu.lst
C. /etc/grub.conf
D. /boot/grub/grub.conf
3. You are the IT system administrator for the Linux systems in your department. You need to make changes to the GRUB device naming conventions. Which file contains the default runlevel setting?
A. /etc/device.map
B. /etc/grub.boot/device.map
C. /boot/grub/device.map
D. /etc/init.d
4. The Linux kernel is a critical component in the Linux boot process. Where does it reside on the system?
A. The /kernel directory
B. The /grub/boot/kernel directory
C. The /boot directory
D. The /boot/kernel directory
5. The Linux bootloader is a very critical component in the Linux boot process. Where does it reside on the system?
A. It resides in the Master Boot Record
B. It resides inside the Linux kernel
C. The /etc directory
D. Inside the system BIOS
Answers
1. Correct answer and explanation: A. Answer A is correct because the /etc/inittab contains the default runlevel setting. The default setting for run-level 5 looks like the following:
id:5:initdefault
Incorrect answers and explanations: B, C, and D. Answer B is incorrect because the directory path /etc/grub.boot does not exist. Answer C is incorrect because /boot/grub/device.map is used to map Linux device names to GRUB device naming conventions. Answer D is incorrect because /etc/init.d is the directory containing the runlevels scripts.
2. Correct answer and explanation: C. Answer C is correct because /etc/grub. conf contains directory information about the disk partition used to find and load GRUB stage2 image.
Incorrect answers and explanations: A, B, and D. Answer A is incorrect because the menu.lst does not reside in the /etc directory and the file is used to determine which operating system is load and booted based on menu item selected. Answer B is incorrect because the file is used to determine which operating system is loaded and booted based on the menu item selected. Answer D is incorrect because the grub.conf does not reside in the /boot/grub directory.
3. Correct answer and explanation: C. Answer C is correct because /boot/ grub/device.map is used to map Linux device names to GRUB device naming conventions.
For example:
(hd0)→/dev/sda
Incorrect answers and explanations: A, B, and D. Answer A is incorrect because the directory path /etc does not contain device.map. Answer B is incorrect because the directory /boot/grub.boot does not exist. Answer D is incorrect because /etc/init.d is the directory containing the runlevels scripts.
4. Correct answer and explanation: C. Answer C is correct because the Linux kernel is located in the /boot directory.
Incorrect answers and explanations: A, B, and D. Answers A, B, and D are incorrect because these directories do not exist.
5. Correct answer and explanation: A. Answer A is correct because the Linux Bootloader resides in the Master Boot Record (MBR). The MBR is the bootloading sector. The system BIOS reads the first sector of the boot device. This sector is 512-bytes in size. For a hard disk drive, this special sector is known as the MBR.
Incorrect answers and explanations: B, C, and D. Answer B is incorrect because the Linux bootloader is used to retrieve the Linux kernel. Answer C is incorrect because /etc is a folder mounted by the Linux kernel once it obtains control from the Linux bootloader. Answer D is incorrect because the system BIOS reads the first sector of the boot device. This sector contains the Linux boot loading program. The system BIOS loads the bootloader into memory and executes the program.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.35.72