sections in this module City College of San Francisco - CS260A
Unix/Linux System Administration

Module: Filesystems I
module list

The File System Table /etc/fstab

The filesystem table /etc/fstab is a configuration file used by the system to control the mounting of filesystems. It contains entries for actual filesystems and for pseudo-filesystems. The latter may be 'dynamic' entries added by the system dynamically. The filesystem portion of the /etc/fstab consists of entries added to the fstab either at system installation, by the logical volume manager, or by hand by the system administrator to describe where filesystems are, their types, and how to mount and manage them. 

Not all mounted filesystems are described in /etc/fstab. Filesystems for removable devices that are automatically detected are mounted without being described in it.

The format of an entry in /etc/fstab is

device   mount-point    type   mount-options   dump-freq   passno

where the fields are separated by any amount of whitespace.

Examples:

UUID=45f0031f-ed8a-4f4b-8369-c87447ae0a0e /  ext4  defaults    1 1

This entry is for the root filesystem. Its passno is 1. The filesystem is mounted by its universally unique id (uuid).

LABEL=/boot        /boot       ext3    defaults        1 2
/dev/hda8          /usr        ext3    defaults        1 2

Each of these entries (one label, one device) is the simplest kind. These are examples of the most common type of entry. If you want to create a new entry, duplicate one of these as a starting point. Although true in this example, the label and the mount point are not necessarily the same. Note that the passno is 2, which indicates these filesystems must be checked second (after the root filesystem.)

LABEL=SWAP-hda9    swap        swap    defaults        0 0

This is the swap device. Its label is set at system installation. A discussion of swapping may be found in a later section.

A note is necessary here about the use of autoauto appears in two places: in field #3 (the type field) it means automatically determine filesystem type, if possible. A type of auto is often used for removable devices (if these are placed in the fstab, which is rare today), so that a PC-formatted (or Mac-formatted) removable can be used in addition to one that is linux-formatted. In field #4 (the mount-options field) it means automatically mount the filesystem in response to a mount -a command.  (mount -a is issued at boot, and may also be issued at the command prompt.) auto is one of the options in the set defaults which is always either explicit or implicit in the mount-options field. (If only the default options are to be used, defaults appears as a placeholder. If other options are used, they are deviations from defaults, which is then implicit.) If you do not want to auto-mount a filesystem you can use the option noauto.

The fstab contains a sequence of pseudo-filesystems that are mounted as well. These are usually kernel tables whose access is useful when the filesystem is running (such as /proc), so an interface is provided to 'mount' the table as if it were a filesystem. I/O operations occuring on a pseudo-filesystem are translated into requests to the kernel for certain types of information, such as process status information. These pseudo-filesystems are identified in the fstab by a descriptive word such as proc or tmpfs in the first field, since there is no filesystem to mount rather than a device file, UUID= or LABEL= . In addition, the logical volume manager dynamically adds entries to the end of /etc/fstab to describe logical volumes. If you add your own disk devices to /etc/fstab it is wise to add them with the static (installed) disk devices in case an entry for a pseudo-filesystem or logical volume is dynamically added later.

A filesystem can also be remote-mounted from a server that accepts such requests. An example of this is an NFS filesystem.

Missing removables entries

If the system automatically mounts a removable without adding an entry to the fstab (as is true on our systems), the device and mount point must be determined by examining the output of mount after the device is automounted. This allows operations to be performed that require the device file, such as mkfs. Simply umount the volume (but do not physically remove the usb device). The device file for the 'entire device', such as /dev/sdb will still be available in /dev and you can use it to partition the device, followed by creating a filesystem. Unfortunately, if the device is not automounted, the determination of the device address may not be so easy. If the device uses SCSI emulation, such as a USB device, and if the kernel understands the device but not the partitions, the 'whole device' /dev entry should still be created when the device is inserted, even though the partition(s) cannot be mounted. Again, use the /dev entry to examine and/or partition the device. Then create filesystem(s) using the (non-existent) device file(s) to indicate the appropriate partition. 

Searching for mounted or unmounted filesystems

If you need to search for a filesystem with a specific label or uuid, use findfs. For example,

findfs LABEL=/root

will look through all attached devices (mounted or unmounted) for a filesystem with the label /root. As discussed in the last section, you can also use the command blkid.

If you need to find filesystem(s) that are either mounted (in mtab) or configured to be mounted (in fstab) with particular parameters, use findmnt. You can specify whether to look in the fstab or the mtab, and can limit the search by type and/or options. By default findmnt searches through all mounted filesystems and outputs information about all of them. For example,

findmnt -t ext4

will output information about all mounted ext4 filesystems, while

findmnt --fstab -t ext4

will output information about all ext4 filesystems in fstab

findmnt -O barrier=1

will output information about all filesystems that have write barriers enabled. Maddeningly, the -O to indicate mount options to look for, is capitalized. -o means something else.

You can see the uuids and labels of currently mounted filesystems and the devices they refer to by examining the symlinks in the directories /dev/disk/by-label and /dev/disk/by-uuid

The Repair Filesystem Trap

If a problem is discovered in the /etc/fstab at reboot, you will be dropped to a single-user shell with a scary Repair Filesystem prompt. The purpose of this is to force you to fix the fstab so that booting will succeed. You can take whatever approach you want at this time to fix the problem, but most people just want to back out their recent change and reboot so that they can do more work on the issue. This sounds simple - just edit the fstab and comment out the change!

Unfortunately, when you are dropped into the Repair Filesystem prompt the initial mounting of the filesystems has been interrupted and the root filesystem is mounted read-only. There is also no guarantee that the root filesystem is safe to write to. Here are the steps you should take:

  1. run fsck on the root filesystem
  2. remount the root filesystem read-write  (mount -o remount,rw /)
  3. comment out the offending line(s) in /etc/fstab (and possibly /etc/crypttab if the problem is an encrypted partition)
  4. reboot

The absolute worst thing you can do is panic! Normally, it is possible to recover a linux system when there is a problem booting so long as you don't lose your head and take some rash action that makes matters worse.

Preview question: The filesystem checking program fsck is used to check the consistency of a filesystem. Most often, fsck is run automatically on filesystems whose state is questionable at boot time, but it can be run by hand. Review the manual page for fsck, concentrating on the -t, -y, -A and -f options.

Prev This page was made entirely with free software on linux:  
the Mozilla Project
and Openoffice.org    
Next

Copyright 2012 Greg Boyd - All Rights Reserved.