Fixing Problems with the Root FilesystemHere is a simple example demonstrating a problem with the root filesystem. The cause is a typo in /etc/fstab. The fix is easy if we can figure out how to boot Linux. Attempting to boot Linux results in the following: Initializing USB keyboard: [ OK ] Booting from the mkbootdisk floppy gives the same result. The problem isn't with /bootit is with /. We need a way to get the system up to fix or restore /. There are three common ways to boot when the Linux boot fails:
Booting from a Second Hard DiskThe box we have been using in the examples is a dual-boot system with Red Hat on one disk and SUSE on the other. Repairing a damaged Red Hat root filesystem is easy in this configuration. We can just boot SUSE, mount the Red Hat root filesystem to some temporary mount point, and fix the problem. Booting from a Rescue CDA convenient method of repairing the root filesystem is to use a bootable Linux CD. We will use the Knoppix distribution (http://www.knoppix.net/), but there are many choices, and the most popular are listed at the end of this section. A rescue disk might have been provided with your Linux distribution CDs that can serve the same purpose. You will probably need to modify the BIOS settings to boot from the CD-ROM or DVD drive before the hard disks. After that is done, restart the computer with the Knoppix CD in the drive. After the Knoppix CD boots, log into KDE. There is no password. Open a terminal window and run df to see what is mounted. The following listing shows that no disk filesystems are mounted. knoppix@ttyp0[knoppix]$ su - root The hard disks are not mounted, but we can see that they are in /etc/fstab. It is easy enough to mount them, as you can see here: root@ttyp0[~]# cat /etc/fstab We can see in the following listing that a typo is keeping our Linux box from booting. The fstab has a typo: LBEL=/should be LABEL=/ instead. root@ttyp0[~]# cd /mnt/hda2 Now just fix fstab, unmount the repaired root filesystem, and reboot from the hard disk. The following shows the corrected fstab. root@ttyp0[hda2]# cat etc/fstab Note Many different "Linux on a CD" distributions are available. Here is a list of some of the most popular:
We don't endorse any particular rescue CD distribution, and we list several so that you can evaluate them and choose the best method for your situation. Reset Lost Root Password Using a Knoppix CDIf the root password is lost, there is no way to log in at multiuser mode. Red Hat doesn't require a password in single user mode, though, which makes it easy to reset the password. Just reboot to single user mode and run passwd. But what about distributions such as SUSE that require a password in single user mode? It is just a bit more complicated to resolve in this case. The solution is to boot from the Knoppix CD or whatever rescue disk you use. When the box is booted, mount the SUSE root filesystem to some temporary mount point such as /mnt/hdb3. If you are using Knoppix, be sure to change the mount option to defaults in /etc/fstab first, or else device file access won't work. When the filesystem is mounted, just run chroot /mnt/hdb3 and passwd as root to reset the SUSE password. The chroot command is used to start a new shell with an effective root directory of the root partition on the problem disk. In other words, after running chroot /mnt/hdb3, the command ls/ shows the files and directories from the /mnt/hdb3 directory. See the chroot(1) man page for further details. Reinstall GRUB Using Knoppix CDThe process to reinstall GRUB when booted from Knoppix is very similar to resetting the SUSE root password. We again use chroot. In this example, GRUB is written to the MBR of /dev/hda. First, we change fstab to mount the boot partition under /boot and change the options to defaults for both /dev/hda1 and /dev/hda2. /dev/hda1 is /boot, and /dev/hda2 is /. /dev/hda3 is swap, so we leave it alone. The next listing shows the original fstab that Knoppix gives us: knoppix@ttyp1[knoppix]$ su - root The following listing shows fstab after we change the /dev/hda1 and /dev/hda2 lines: root@ttyp1[~]# cat /etc/fstab Now we mount the disk filesystems so that we can reinstall GRUB: mount /dev/hda2 Next, we run chroot /mnt/hda2 to make /mnt/hda2 the effective / for the following GRUB work. The commands in the following listing are the same as the previous GRUB reinstallation example. grub> root (hd0,0) After this is done, we can just quit the GRUB shell and exit the chroot shell. We then unmount /dev/hda1 and /dev/hda2 and reboot. Booting from a Floppy Rescue DiskA 3.5-inch floppy disk doesn't have room for a full Linux system. However, you can make a bootable rescue disk that includes critical utilities needed to recover a system. We recommend using Knoppix, SystemRescueCd, or some other CD-based solution because they are full Linux distributions and have all the commands and utilities you are used to. If a CD-ROM is not available on the Linux server, then a rescue floppy is a good solution. Check tomsrtbt (http://www.toms.net/rb/) for a good floppy disk distribution. Tom Fawcett has an excellent article explaining how to build a rescue disk on the Linux Documentation Project Web site at http://www.tldp.org/HOWTO/Bootdisk-HOWTO/. Whatever method you decide to use, be sure to verify that it will boot all your Linux boxes before you need it to resolve a problem. |
Thursday, November 12, 2009
Fixing Problems with the Root Filesystem
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment