|
linux 系统排错
(6)Debug Exercise I
In this exercise, you'll be working without an /etc/fstab configuration file. To prepare, rename this file to something that you can remember and restore as required, such as /etc/bak.fstab. You'll also need a rescue disk. If your computer can boot directly from your CD drive, the first Red Hat Installation CD can serve this purpose. Otherwise, you'll also need a boot disk that also allows you access to the actual Red Hat Linux installation files, locally or over a network. And you'll need to know the root password for this system.
The objective is to learn how /etc/fstab works, as well as the key configuration parameters associated with an /etc/fstab configuration line for your root (/) directory.
1.Start Red Hat Linux. Rename your /etc/fstab configuration file. One possible name is /etc/bak.fstab.
2.Make sure you have a boot disk that can serve as a rescue disk. If you know that your computer can boot directly from your Red Hat Linux installation CD, you're set. Otherwise, create a boot disk from the appropriate image file (boot.img, bootnet.img, or pcmcia.img).
3.Use the reboot command to restart Linux.
4.When you see your boot loader, probably GRUB, select your current version of Red Hat Linux.
5.Watch the messages as they scroll across the screen. You'll probably see a message similar to:
WARNING: couldn't open /etc/fstab: No such file or directory
6.You'll probably be taken to the single-user mode maintenance login prompt. Enter your root password at this prompt.
7.Find your currently configured partitions with the fdisk -l command. Make a note of each partition device that is formatted to a Linux filesystem.
8.Check the labels associated with each Linux-formatted partition. For example, if one of the partitions is /dev/hda1, run the e2label /dev/hda1 command. Make a note of the label that you see, such as /boot or /.
9.Try restoring your /etc/fstab file from your backup. It probably won't work.
10.Reboot your computer with a Red Hat Linux installation CD or boot disk. Type linux rescue at the boot prompt.
11.Follow the first basic steps toward installation.
12.Direct the installation program toward the source for the Red Hat Linux installation files, as required.
13.When you get to the Rescue menu, select Continue and press ENTER.
14.Since Linux still can't find your /etc/fstab file, you'll see an error message that suggests that you don't have any Linux partitions. Select OK and press ENTER to continue.
15.You are now in rescue mode. Run the df command. You probably won't see any of your normal filesystems mounted anywhere.
16.Try running the man fstab command. You probably won't be able to see the man page for the /etc/fstab configuration file.
17.Create the /mnt/sysimage directory as required with the mkdir command.
18.Back in step 8, you found the partition device associated with your root directory. Mount it on the /mnt/sysimage directory.
19.Restore the basic workings of your directory structure with the chroot /mnt/sysimage command.
20.Now try to rebuild /etc/fstab. Run the man fstab command. It should work now. Try to remember the settings for each of the columns in /etc/fstab. Using the fstab man page, and the information you gathered with the e2label command, try to rebuild a simple /etc/fstab file. Remember, avoid tabs and keep all configuration settings from wrapping to the next line. Create an /etc/fstab file with at least the settings for your root (/) directory.
21.Remove the installation floppy and/or CD from their drives.
22.Reboot your computer. If it works, congratulations. If it doesn't work, try editing /etc/fstab again.
23.When you've had enough, restore your original /etc/fstab file from your backup. Reboot your computer to make sure everything is all right.
24.Remember, you don't need to memorize all of the settings for /etc/fstab. However, you should recognize what works and what does not work in an /etc/fstab configuration file.
(6)Debug Exercise II
In this exercise, you'll be working without an /etc/inittab configuration file. To prepare, rename this file to something that you can remember and restore as required, such as /etc/bak.inittab.
The objective is to learn the effect of a corrupt or missing /etc/inittab file.
1.Start Red Hat Linux. Rename your /etc/inittab configuration file. One possible name is /etc/bak.inittab.
2.Use the reboot command to restart Linux.
3.Observe the messages as Linux tries to reboot. By default, the reboot command moves to runlevel 6.
4.If you see a message such as No inittab file found, Linux probably hangs. At this point, you'll need to restart your computer through the physical reset button or on-off switch. Since you no longer have an /etc/inittab file, Linux can't find the processes to stop at runlevel 6.
5.When you see your boot loader, probably GRUB, select your current version of Red Hat Linux.
6.Watch the messages as they scroll across the screen. You'll probably see a message similar to:
INIT: No inittab file found
Enter runlevel:
7.No matter what runlevel you enter, Linux ends up hanging. It's looking to /etc/inittab to find the scripts associated with the runlevel that you select. Since it can't find /etc/inittab, it stops with a no more processes left in this runlevel message.
8.At this point, you'll need to reboot your computer again. But you can now restart your computer with a boot disk as in the last exercise, or try starting in single-user mode.
9.When you see your boot loader, probably GRUB, you'll want to add a message to the kernel command line. In GRUB, enter p and type in your password if required. Then enter the a command to modify the kernel command line. You should see something like the following:
grub append> ro root=LABEL=/
10.Type the word single at the end of this command line and press ENTER. Even though the /etc/inittab file is missing, Linux should boot you into single-user mode.
11.Now try restoring your /etc/inittab file from the backup that you made. What happens?
12.Remount your root directory (/) in read/write mode. For example, if your root directory is normally located on /dev/hda2, run the following command:
mount -o remount,rw /dev/hda2
13.Try restoring your /etc/inittab file from the backup again. You should now be successful.
14.Try the reboot command again. Linux can now find /etc/inittab and should reboot fairly normally.
(6)Debug Exercise III
In this exercise, you'll be working with a modified /boot/grub/grub.conf configuration file. To prepare, copy and back up this file to something that you can remember and restore as required, such as /boot/grub/bak.grub.conf. If a relatively new administrator does not understand the meanings of root in the grub.conf configuration file, he may actually try to set root in the kernel configuration line to the partition associated with the /boot directory.
The objective is to learn the effect of a corrupt /boot/grub/grub.conf file.
1.Start Red Hat Linux. Back up your /boot/grub/grub.conf configuration file. One possible name is /boot/grub/bak.grub.conf.
2.Edit the currently existing /boot/grub/grub.conf configuration file. Change the entry in the kernel command line for root to a different directory. If you normally have a separately mounted /boot directory, use the associated partition device such as /dev/hda1.
3.Save your modified /boot/grub/grub.conf configuration file.
4.Use the reboot command to restart Linux.
5.Examine the boot messages as they scroll across your screen. If the kernel message points to the wrong partition, you'll get a message such as the following:
Kernel panic: No init found. Try passing init= option to kernel.
6.When you see your boot loader, probably GRUB, you'll want to add a message to the kernel command line. In GRUB, enter p and type in your password if required. Then enter the a command to modify the kernel command line. You should see something like the following:
grub append> ro root=/dev/hda1
7.Type the word single at the end of this command line and press ENTER. See what happens.
8.You probably still have a kernel panic. Try to pass an init= option to the kernel. After resetting your computer, wait for the GRUB menu. Add init=/bin/sh to the end of the kernel command line. Try booting again.
9.Back in the GRUB menu, edit the kernel command line again. Try editing the command to point root to different partitions and see what happens. Repeat as often as desired.
10.Finally, back in the GRUB menu, point root to the correct partition.
11.Try restoring your /boot/grub/grub.conf file from the backup.
12.Try the reboot command again. Linux can now find your root partition and should reboot normally.
(6)Debug Exercise IV
In this exercise, you'll be practicing with Telnet. The service can be on or off by default. It may be blocked by a firewall. Service may be denied through the /etc/xinetd.d/telnet configuration file or through /etc/hosts.deny. Ideally, you'll be able to check your work through another computer on a LAN.
1.Start Red Hat Linux. Check for the installation of the telnet package with the rpm -q telnet command. Install the telnet RPM if required.
2.Check your configuration for a firewall with the /sbin/service iptables status command.
3.If there are iptables rules active on your system, you may want to back them up with the /sbin/iptables-save > filename command.
4.If you have iptables rules, flush them with the /sbin/iptables -F command.
5.Check your /etc/hosts.allow and /etc/hosts.deny files. If there are rules related to in.telnetd or ALL services in either file, comment them out.
6.Check the default status of Telnet with the /sbin/chkconfig --list telnet command. The response should be off or on. Use chkconfig to turn Telnet on if required.
7.Check the /etc/xinetd.d/telnet configuration file. If there are only_from or no_access directives in this file, comment them out.
8.Now you should be able to connect to Telnet. Try it from the local computer with the telnet localhost command. You should be able to log in with a local user name and password. Log out of Telnet.
9.Repeat the telnet access request from a remote computer. Use the name or the IP address of the Telnet server. Log out of Telnet.
10.On the Telnet server, add the following line to the /etc/xinetd.d/telnet configuration file:
no_access = 127.0.0.1
11.From the computer with the Telnet server, try the telnet localhost command. What happens? Is a successful login through Telnet unexpected?
12.Run the /sbin/service xinetd reload command. Repeat step 11. What happens now? If possible, try to use the telnet command to connect to the Telnet server from a different computer on your LAN. Can you connect?
13.Restore the original /etc/xinetd.d/telnet configuration file and run /sbin/service xinetd reload command again.
14.Open the /etc/hosts.deny file in a text editor. Add the following line:
in.telnetd : ALL
15.Repeat step 11. What happens now? Try this again from another computer on your LAN.
16.Restore the original /etc/hosts.deny file.
17.Now try to set up a firewall to block yourself from accessing Telnet on the local computer.
18.Add the following iptables chain to your firewall (the TCP/IP port for Telnet is 23. You can look up the port you need in /etc/services):
/sbin/iptables -A INPUT -s 127.0.0.1 -p tcp --dport 23 -j DROP
19.Verify that your computer accepted this new rule with the iptables -L command. You should see that packets destined for Telnet are to be dropped.
20.Repeat step 11. What happens now? Try to log in via Telnet again from another computer on your LAN.
21.Note how the response is different when you block access through a firewall and through a file such as /etc/hosts.deny.
22.Restore your original firewall. Flush the rule that you created with the /sbin/iptables -F command. Then restore the old rules if required with the /sbin/iptables-restore < filename command.
转贴自linuxsir。org,想考rhce的兄弟可以看一下,保证收益非浅 |
|