1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

Chapter 33. LPI Exam 201 Review Questions and Exercises

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (10.57 MB, 1,207 trang )

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks

33.1. Linux Kernel (Topic 2.201)

33.1.1. Review Questions


You find that the make modules command fails repeatedly when trying to compile a new kernel. What can you do to solve this



You need to know the CPU type on a system before updating the kernel. Which of the files in the /proc directory can tell you

what CPU you are using?


You want to learn more about the PCI-based hardware in a typical Intel-based computer so that you can update the kernel.

What command can you use?


The older computer you are using does not support the make bzImage command. What commands can you execute if you

want to create a smaller kernel?


You have just compiled a new kernel, but it will not boot. You intend on booting a kernel on the second partition of

the first hard drive. Currently, the GRUB configuration file reads as follows:

title Test Kernel (2.6.0)

root (hd0,2)

kernel /boot/bzImage-2.6.1 ro root=LABEL=/

initrd /boot/initrd-2.6.1.img

What change needs to be made?


When building and installing modules during the process of creating a new kernel, when do you need to be root?

33.1.2. Answers


Use the make mrproper command, then make clean. If these two commands do not solve the problem, you are using the

wrong configuration file for your CPU type. Go to the /usr/src/linux/configs/kernelname directory and copy the correct file.




/bin/lspci -vv.


Any of the following: make zImage, make zdisk, or make zlilo.


Change root (hd0,2) to read root (hd0,1). GRUB uses a zero-based counting system, so the second partition of the system is

indicated by a 1, not a 2.


Only when installing the modules.

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks

33.1.3. Exercise

Following is an exercise for creating a custom 2.6 kernel. It contains many separate steps.


Make sure that you know your hardware. Use the lspci command with the -vv option to determine the type of hardware that

you have. Then view the output of the /proc/cpuinfo command to find the type of CPU your system is using.


Verify that you have all of the software components installed that will help you build and install a kernel. Components vary

between the 2.4 series and 2.6 series of kernels. Components and utilities include:











Gnu C

Gnu make





Once you have verified you have these components and utilities, you can obtain the source files from http:www.kernel.org or

from your system's distribution repositories. For example, you can obtain the kernel files on a Red Hat or Fedora system

using RPM. Novell SUSE systems provide Yast (or RPM, if you wish), and you can use apt or Synaptic for Debian-based


At this stage, you can also patch the kernel, if you wish. Once you have finished patching, you can configure the kernel.

During this stage of the process, you have to determine whether you want a static kernel or a modular kernel. Most systems

default to modular kernels.


Once you have made this decision, find the Makefile and edit it to contain unique information for your kernel. Change the

EXTRAVERSION = -1 portion of the Makefile to a unique value.


Then back up the hidden .config file that is in the../linux file of your source tree. Do this by copying the.config file to another

location. Then type make mrproper to begin with a fresh installation.


Now you are ready to use the make command to create a 2.6 kernel. You have a choice between themake config, make

oldconfig, make menuconfig, and make xconfig commands. The make config command does not provide a menu. Rather, it

runs a program that asks you a long series of questions that you have to answer. make oldconfig reads the existing file and

makes the changes you have indicated. Use make oldconfig only if you have made minor changes. Themake menuconfig

command presents an ncurses-based menu that is considerably more user-friendly than the list of questions presented by the

make config command. Finally, the make xconfig command is the most user-friendly, but may not be available on your system.


Choose the options that are best for your system. You will see that the choices are grouped into several sections (e.g.,

General Setup, Loadable Module Support, Device Drivers). Go through each option and choose the features you want. When

you are finished configuring your options, save them and exit the program.


You are now ready to build the kernel. Type the following:

make bzImage

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks


If you have chosen to build a modular kernel (the most common choice), you must then build the modules:

make modules

10. Now, become root and install the modules:

su root

make modules_install

11. Exit root.

12. Now you need to create an initial ramdisk image, so that the system can boot the hard drive and begin initialization. If, for

example, you are creating a kernel named 2.6.10-5-686, issue the following command to create the accompanying ramdisk


mkinitrd /boot/2.6.10-5-686

13. Now copy the new kernel and system.map file you have created to the /boot directory. Following is an example:

$ cp arch/i686/boot/bzImage /boot/bzImageYOUR_KERNEL_VERSION

$ cp System.map /boot/System.map-YOUR_KERNEL_VERSION

$ ln -s /boot/System.map-YOUR_KERNEL_VERSION /boot/System.map

Notice how the final command creates a symbolic link from your new system.map file to the /boot/System.map file.

14. After you are finished, edit your boot loader. If you are using GRUB, edit the /boot/grub/menu.lst file or possibly the

/etc/grub.conf file, which is usually a symbolic link to the/boot/grub/menu.lst file. If, for example, you have created a new

kernel named 2.6.10-5-686, create the following entry for GRUB:


New, kernel 2.6.10-5-686




/boot/vmlinuz-2.6.10-5-686 root=/dev/hda2 ro quiet splash





You do not have to run any command to enable this file; GRUB will read the menu.lst or grub.conf file automatically at boot

time. If you experience any problems, you can edit the configuration file on the fly at boot time, as described later in this


Alternatively, if you are using LILO to use the same kernel, alter your /etc/lilo.conf file as follows:














This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks.

append=" ide1=autotune ide0=autotune"






Then run the lilo command to update the boot sequence.

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks

33.2. System Startup (Topic 2.202)

33.2.1. Review Questions


Why are the files under the /etc/init.d directory executable?


Some systems, such as Red Hat, do not place startup scripts in the /etc/init.d directory. Where do Red Hat and others put

these scripts?


What is the result of the following entry in the /etc/inittab file?

ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now


You find scripts named K11anacron and S15bind9 in the /etc/rc2.d directory. Which script will run first when the system starts



You wish to run the fsck command on a partition named/dev/hda1. What command should you run first?


What is the result of the following command?

fsck -a /dev/hda3

33.2.2. Answers


Because these files are run by the init program and are used to start system daemons


In the /etc/rc.d/init.d directory


It traps the hardware-based command that normally shuts the system down, and runs the Linux shutdown command. As a

result, system shutdown is more orderly and causes fewer problems.


K11anacron, because K scripts are run first. ThenS scripts are run. Alphabetical order is followed. SoK11anacron would run

before K11bind, for example.


umount /dev/hda1


The command runs fsck on an IDE device and automatically repairs any problems found.

33.2.3. Exercises


Review the contents of the /etc/inittab file. Consider adding the following line that adds a newgetty command (standard

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks

text-based login) for runlevels 2, 3, 4, and 5 on tty12:

12:2345:respawn:/sbin/getty 38400 tty12


Review the contents of the scripts at your particular runlevel. In some systems (Red Hat and Fedora), you can find these

scripts in the subdirectories of the /etc/rc.d directory. In other systems, you will find the files in the/etc/rcN.d directory, where N

is the number of the runlevel. For example, an Ubuntu system is Debian based and defaults to runlevel 2. Therefore, the

scripts that run at the default runlevel are in the /etc/rc2.d directory. Review the scripts in this directory to see what is run.

Notice that there are K scripts and S scripts. The K scripts are run before theS scripts. Scripts are run first in numerical, then in

alphabetical, order. Determine the order in which scripts are run.


Practice using the following commands as root:

init 0

init 6

init 2

init 5

Write down the results of each command for your particular system or systems.


Review the contents of the /etc/mkinitrd/mkinitrd.conf file. Note the default settings for the initrd image that would be created.

They are usually 022. The DELAY option is usually set to 0 by default. You would increase this value if you wished to give the

system a chance to rest before running initialization scripts.


As root, type init 1. Notice what you have to do to enter maintenance mode. After you type theroot password, you will see that

you can edit files, make necessary changes, and run programs such as fsck (as long as you have unmounted the partition).

You are now the root user.


If you are using GRUB, reboot your system and then select the default boot option when the GRUB menu screen appears.

Press e. You will see that you can now edit the boot parameters for this particular session. Press the Escape key to go back

to the main menu.


If you are using GRUB, reboot your system again. Once you see the GRUB menu screen, press c. You will be sent to a

GRUB prompt, where you can create your own boot sequence. Press the Escape key to return to the menu and boot your



If you are using GRUB, execute the following commands to store Stage 1 and Stage 2 on a floppy disk:


:Insert a floppy disk.

b. Change to the GRUB directory:

cd /boot/grub/


Copy the Stage 1 files and Stage 2 files to the floppy disk using the dd command:

dd if=stage1 of=/dev/fd0 bs=512 count=1

dd if=stage2 of=/dev/fd0 bs=512 seek=1

These commands create a valid boot floppy disk for your drive.


If you do not have a floppy disk drive and want to create a GRUB boot CD, you need to use the file named stage2_eltorito.

This is a special Stage 2 file required by CD-ROM drives. You do not need to use the Stage 1 or Stage 2 files. The

stage2_eltorito file is often located in the /usr/lib/grub/i386-pc/ or /lib/grub/i386-pc directory. The steps you take to create a

bootable CD-ROM follow.


Create a directory structure to store the ISO image you are going to create. This structure must be stored onto the

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks.

CD-ROM as /boot/grub:

mkdir -p iso/boot/grub

b. Copy the /usr/lib/grub/i386-pc/stage2_eltorito file to the directory you have just created:

cp /usr/lib/grub/i386-pc/stage2_eltorito ~/iso/boot/grub/


Use the mkisofs command to create an ISO image:

mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table

-o grub.iso iso

This command tells mkisofs to create Rock Ridge protocol files and also specifies the path of the boot image used.

d. You can then use any application you wish to burn the ISO image (grub.iso) onto the CD-ROM.

10. If you are using LILO, add password protection to it using the instructions given in this book. Be sure to make a backup copy

of your original lilo.conf file before making any changes to it. Once you are finished making your changes, be sure to install

them as lilo.conf and then runlilo to make sure your changes are recognized.

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks

33.3. Filesystem (Topic 2.203)

33.3.1. Review Questions


What is the difference between the /etc/fstab and the /etc/mtab files?


What is the meaning of the sixth field in the /etc/fstab file?


Where would the following line appear, and what does it accomplish?

cdrom -fstype=iso9660,ro,sync,nodev,nosuid



What type of information is found in the /proc/mounts file?


For a device named /dev/sda1, you wish to learn the last mount time, the maximum count of boot times that have occurred

between checks by fsck, and the maximum mount counts. You know that some of the output may not be understood by the

dumpe2fs command. What dumpe2fs option would you use to get this command to report all findings?


What command flushes all data and writes it to disk?


How can you see that an attempted copy using the dd command failed?


You have tried to use the swapon command on a partition named/dev/hda3. This partition has the following entry in/etc/fstab:




defaults,noauto,errors=remount-ro 0

What information in this line can help you identify the most likely problem?

33.3.2. Answers


The /etc/fstab file shows the filesystems that will be mounted. The/etc/mtab file lists the filesystems that are mounted. In other

words, /etc/fstab controls the behavior of the system, whereas/etc/mtab reflects the results.


The sixth field of /etc/fstab determines the order that partitions (that is, filesystems) are checked when a system boots.


The entry is part of the autofs configuration file. The entry automatically mounts the /dev/cdrom drive as a read-only device

when a disk is inserted. SUID files are not mounted, and neither are device files. The filesystem type is iso9660, which is

standard for CD-ROM devices.


The filesystems that are currently mounted and active.


dumpe2fs -f /dev/sda1.

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register


it. Thanks




The failed dd command issues an error code greater than 0 to standard error. An error message such as "No space left on

device" may also be displayed.


The noauto option precludes the use of the /dev/hda3 device as a swap file.

33.3.3. Exercises


Use the cat command to view the contents of the /proc/mounts file. What do this file's contents have in common with the

contents of the /etc/mtab file?


Review the /etc/fstab file and take note of the syntax. Be able to identify the following:

The filesystem used

The mount point

The filesystem type

The options: be able to describe each one

The dump value

The pass number

Familiarize yourself with each of the fields and their possible values.


Use the less command to read the contents of the /etc/mtab file. Then use the badblocks command to look for problems on

one of the Linux filesystems. Make sure that you unmount the partition first. For example, if you wanted to read the /dev/hda3

partition, you would issue the following commands:

umount /dev/hda3

badblocks -o bad.txt /dev/hda3

The bad.txt file will contain a list of all bad blocks on the partition.


Try out the dd command to copy the contents of a partition into a single file. Make sure that you have a large amount of disk

space in the destination directory. Suppose you have a partition named /dev/hda3 that is 500 MB. You could write it to a

single image (using a different partition) as follows:

dd if=/dev/hda3 of=hda3.img

The following copies the contents of bootdisk.img to a floppy disk:

dd if=bootdisk.img of=/dev/fd0


It is also important to know the options to dd. For instance, you can increase the block size to make writing faster and more

efficient. Or you can specify the block size to copy only the data that you need. For example, to copy the boot sector from the

/dev/hda device, you could tell dd to perform this operation once on the first 512 bytes:

dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1

This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks.


You can then tell dd to write the second stage onto the same floppy. This time, you will use the seek option, which tells

dd to

skip over the first 512 bytes, as specified in the bs option, and continue writing on byte 513 of the floppy:

dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1

Continue experimenting with the dd command, but be careful: a simple mistake can destroy all data on your drive or partition.


On a system that has sufficient unused space, create a new 500-MB partition. Use the fsck command and create a type 82

partition. Next, use the mkswap command to make this space a swap file, for instance:

mkswap -c /dev/hdb2

Now use the swapon command to activate the partition so that it can be used as RAM:

swapon /dev/hdb2

Issue the swapoff command for the /dev/hdb2 partition. Use fdisk to re-create the partition. Then, use the mke2fs -j command

to create an ext3 partition on it. Copy data to this new partition. If you want to keep it, update the/etc/fstab file to automatically

mount it. If you wish, you can recreate the swap space and then update /etc/fstab to automatically mount it with the following








Xem Thêm
Tải bản đầy đủ (.pdf) (1,207 trang)