- 论坛徽章:
- 0
|
感觉到有点累了,做些试验来调剂一下
RHCE的有关启动的排错题目分析
我学Linux的一个简单目标是要考过RHCE,所以我也花了些时间在RHCE的排错题的解决之上。以下只是将网络上我所见之排错题目罗列与此,用实验的方法验证并分析解决之,这次是有关启动的部分。
先是几个是摘自RHCE Study Guide Exam RH302 3rd,有点旧,不过题目蛮好的。
题目一
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.
场景:
/etc/fstab丢失。
分析:
注意每个问题的出错信息,这是我们遇到问题第一能够得到的最好的线索。好比此题的: WARNING: couldn't open /etc/fstab: No such file or directory
已经很清楚的提示了/etc/fstab不存在。那么我们所要做的是要确定/etc/fstab是否存在,如果不存在就要想办法重建它。
在这个练习之中是使用rescue的环境来修复fstab,这正是之前我们练习过的方法。
解决方法:
(假定我们的Linux所在的分区都是普通的硬盘分区,如果是lvm,请参考之前的有关rescue环境的部分)
基本步骤如下:
1、 fdisk –l察看分区表,并记下
2、 使用e2label命令找到/和/boot等分区
3、 如果rescue已经为我们mount了分区,到第5步
4、 如果rescue没有找到分区,或者我们使用了skip直接到了shell状态,创建/mnt/sysimage目录后,自行mount根分区,如果设备文件不存在,使用makedevs自行创建
5、 chroot到/mnt/sysimage,这样我们可以得到很多命令,比如man之类
6、 根据fstab格式用vi自行创建fstab,最好要有/,/boot,/proc,swap,/dev/pts
7、 存盘,后sync后退回rescue环境
8、 exit退出重启动
其他方法1:
1. 启动后系统提示输入root密码可以进入shell,我们看到提示是(Repair filesystem)
2. 重新mount /成read write
$mount –o remount,rw /dev/hdaX / #这里的hdaX是你的/分区
3. 同上自己创建/etc/fstab (fdisk -l,e2label)
其他方法2:
1. Bootloader传递启动参数init=/bin/bash,进入shell模式
2. 重新mount /成read write
$mount –o remount,rw /dev/hdaX / #这里的hdaX是你的/分区
3. 同上自己创建/etc/fstab
fstab本身不属于任何rpm包,即使是不同的机器因为分区的不同也许也不尽相同。无论用何种方法都要求对/etc/fstab有相当了解,当然我们也可以使用man fstab来现场察看fstab的格式。
后两种方法启动并未完成,一般来说bootloader的kernel的一般都是用ro参数的,所以记得要重新mount至rw状态
题目二
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.
场景:
/etc/inittab丢失。
分析:
这个练习我之前也做过,会提示没有找到inittab,无论输入什么run-level都会死机的。
解决方法:
还记得关于rpm命令的-qf参数么,可以查找文件所属的rpm包,当然-Vf可以知道文件发生的变化。
1. 如果有cd可以进入single模式,如果没有cd就是用rescue进入askmethod的网络方式,安装源会在/mnt/source之中
2. 尝试自行创建inittab,inittab比fstab要复杂的多,一般很少会自行创建它
3. 使用rpm –qf /etc/inittab查处所属的rpm包,是initscripts
4. 使用rpm命令重新安装initscripts,记得要使--force参数,如果是resce环境要chroot或者使--root参数指定root为/mnt/sysimage
/etc/inittab比较复杂,安装之后基本也是适用default的值,可以使用重新安装rpm包的方法重新安装,如果要修改,可以重新安装后再修改。 |
-
01.GIF
(35.25 KB, 下载次数: 31)
a01
|