The nicest thing about Linux from a maintenance perspective is that everything is a file. Of course, it can be perplexing at times to know which file something lives in. But as a rule, Linux recovery amounts to using basic filesystem utilities like
rm, and a text editor like vi. Of course, to automate these activities, tools like grep, awk, and bash are helpful; or at a higher level, perl or python. This tutorial does not address basic file manipulation.
Assuming you know how to manipulate and edit files, the only "gotcha" perhaps remaining for a broken system is not being able to use the filesystems at all.
Your best friend in repairing a broken filesystem is
fsck. The next tutorial (on topic 203) has more information, so we will just introduce the tool here.
The tool called
fsck is actually just a front-end for a number of more narrow
fsck.* tools --
fsck.reiser. You may specify the type explicitly using the
-t option, but
fsck will make an effort to figure it out on its own. Read the manpage for
fsck.* for more details. The main thing you want to know is that the
-a option will try to fix everything it can automatically.
You can check an unmounted filesystem by mentioning its raw device. For example, use
fsck /dev/hda8 to check a partition not in use. You can also check a rooted filesystem such as
fsck /home, but generally do that only if the filesystem is already mounted as read-only, not as read-write.
A flexible feature of Linux systems is the fine-tuned control you have over mounting and unmounting filesystems. Unlike under Windows and some other operating systems, partitions are not automatically assigned locations by the Linux kernel, but are instead attached to the single
/ root hierarchy by the
mount command. Moreover, different filesystem types (on different drives, even) may be mounted within the same hierarchy. You can unmount a particular partition with the
umount command, specifying either the mount point (such as /home) or the raw device (such as /dev/hda7).
For recovery purposes, the ability to control mount points lets you do forensic analysis on partitions -- using fsck or other tools -- without risk of further damage to a damaged filesystem. You may also custom mount a filesystem using various options; the most important of these is mounting read-only using either of the synonyms
As a quick example, you might want to substitute one user directory location for another, either because of damage to one or simply to expand disk space or move to a faster disk. You might perform this switch using something like:
# umount /home # old /dev/hda7 home dir
# mount -t xfs /dev/sda1 /home # new SCSI disk using XFS
# mount -t ext3 /dev/sda2 /tmp # also put the /tmp on SCSI
For recovery, system upgrades, and special purposes, it is useful to be able to mount and unmount filesystems at will. But for day-to-day operation, you generally want a pretty fixed set of mounts to happen at every system boot. You control the mounts that happen at bootup by putting configuration lines in the file /etc/fstab. A typical configuration might look something like this:
Listing 4. Sample configuration in /etc/fstab
/dev/hda7 / ext3 defaults 1 1 none /dev/pts devpts mode=0620 0 0 /dev/hda9 /home ext3 defaults 1 2 none /mnt/cdrom supermount dev=/dev/hdc,fs=auto,ro,--,iocharset=iso8859-1,codepage=850,umask=0 0 0 none /mnt/floppy supermount dev=/dev/fd0,fs=auto,--,iocharset=iso8859-1,sync,codepage=850,umask=0 0 0 none /proc proc defaults 0 0 /dev/hda8 swap swap defaults 0 0
Find more details in the next tutorial (on topic 203).