Understanding the etcfstab File


Understanding the /etc/fstab File

You may be wondering whether there is a shortcut to all this mountinga way to program "recipes" for all the mountable devices on a systembecause chances are that all the flexibility offered by the mount tools will become less useful over the lifetime of a system. After you figure out the commands and esoteric device names needed to mount your second IDE hard drive, your NFS volume from across the network, your MS-DOS floppy, and your SCSI CD-ROM, do you really have to remember those commands every time you want to mount them? No, there is indeed a better way: the /etc/fstab file.

Let's take a look at the file now, using cat /etc/fstab:

# Device             Mountpoint      FStype  Options       Dump   Pass# /dev/ad0s1b          none            swap    sw            0      0 /dev/ad0s1a          /               ufs     rw            1      1 /dev/ad1s1f          /tmp            ufs     rw            2      2 /dev/ad0s1g          /var            ufs     rw            2      2 /dev/ad0s1e          /usr            ufs     rw            2      2 /dev/acd0            /cdrom          cd9660  ro,noauto     0      0 /dev/fd0             /floppy         msdos   rw,noauto     0      0 proc                 /proc           procfs  rw            0      0 /dev/ad1s1g          /home           ufs     rw            2      2


This file (which will vary according to your system's configuration) tells the system everything it needs to know about a given mount point: what device attaches to it, what filesystem type to expect, the mount options, and in what order it should perform filesystem checks when the system is booted. The fstab file is closely interrelated with the mount command. Used in conjunction, these two tools can make filesystem management a relative breeze.

The main function of the fstab file is to give the system a profile of mounted devices that can be activated automatically at boot time. With all your mount points specified in the fstab file, you can issue the command mount -a to mount them all (which is what happens during bootup). When the system goes through its filesystem checks during bootup, it runs fsck -p to "preen" the filesystems, making sure they are all marked "clean" (you'll learn more about the fsck actions in "Checking and Repairing Filesystems with fsck," later in this chapter). The system then runs mount -a -t nonfs to mount all filesystems listed in /etc/fstab except for NFS volumes.

Beyond this function, though, is an even more convenient effect of this setup. After a mount point is specified in /etc/fstab, you no longer need to remember the mount command necessary to bring it online; now, the only thing you have to know is the name of the mount point:

# mount /home


This command reads in all the necessary information about /home from the fstab file. It knows that the device you want is /dev/ad1s1g, that it's a UFS (well, FFS) filesystem, and that you want it mounted read/write. Similarly, to mount a CD-ROM, all you need to enter is the following:

# mount /cdrom


Now the process of mounting disks is starting to look almost user-friendly!

The noauto option on the /cdrom and /floppy entries tells mount that these filesystems should not be mounted at boot time. As with NFS resources, there is no guarantee that a CD-ROM or floppy disk will be available when the system boots, so the noauto option prevents mount from spending pointless time trying to mount a disk that isn't there. It doesn't prevent you from easily mounting it later, however. The preceding mount command is all you need.

You can specify any of the command-line mount options in the fourth column of the fstab file that are applicable to the filesystem in question. For instance, any options listed in man mount can be used, as well as anything in the filesystem's man mount_* page if it's a nonstandard filesystem type.

The fifth column in the /etc/fstab file contains the dump level numbers. These numbers are for the benefit of the dump command, which is a venerable UNIX backup utility that operates based on priority levels. You call for a backup at a specified dump level; the dump level number tells dump at what level to trigger a backup for each filesystem. For example, filesystems with a dump level number of 1 are backed up only when the dump level is 1 or lower (a dump level of 0 indicates a full backup of all filesystems). Note that specifying 0 in /etc/fstab omits that filesystem from ever being dumped.

The sixth, or rightmost, column in /etc/fstab is the Pass# field. The pass number is a flag for fsck; numbers above 0 indicate the order in which the filesystems should be checked. The root filesystem has a pass number of 1, meaning that it is checked first; mounts with a pass number of 2 are checked next, in as concurrent a manner as the hardware permits. A pass number of 0 means that the filesystem should not be checked; this is what you want for CD-ROMs, floppies, swap partitions, and other resources that can't become corrupted (or devices where it doesn't matter if they do become corrupted).

A fuller discussion of backup and restoration procedures can be found in Chapter 21, "FreeBSD Survival Guide," in which dump will be covered in more detail, along with other backup/mirroring methods such as CVSup.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net