Linux: what is fstab and how do I use it?

Wheels machine

When learning Linux system administration one of the basic concept is the fstab file. Many people say you don’t have to touch it, many other say that you should only if things don’t work, but what is its purpose?

The fstab file

The fstab file located in / etc / fstab  is the file that contains the association between filesystems and mountpoints usually used (but not limited to) at boot time. Now let’s look at an example:

# / etc / fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
UUID=a61af247-2b92-4312-8960-55700ff579d8 /               ext4    errors=remount-ro 0       1
UUID=7ecbfb26-a650-4d7e-a853-bab83d59d772 /home           ext4    defaults         0       0
UUID=672efab4-02c2-4252-8185-70a3e3536080 none            swap    sw              0       0
  1. The block device (or special path) is specified in the first field. It can be a block device (/dev/sd*), a Universal Unique ID (as in this case), a Label (prefix: LABEL=) or even a network path like remote:/shared .
  2. The mountpoint is the path on which the device/path will be mounted. Think of it like appending the directory content of a device in another directory. In this example the path /home is empty before the second significant line but becomes populated after it.
  3. The filesystem type is the third fields and needs to be adapted depending on the filesystem contained in the device/path specified in the fist field.
  4. Options passed to the mount command are specified in the fourth field.
  5. Dump is the fifth field. Dump is an old program used to backup filesystems, nowadays it isn’t installed by default on most distributions. This field can be 0 (do not dump) or 1 (execute dump).
  6. Fsck is the sixth field. This field specifies whether the filesystem should be checked (if possible) during boot time. The allowed values are 0, 1, 2. 0 means no fsck will be executed at boot time, 1 and 2 will perform the fsck. Value 1 should be reserved to root directory only.

As you can see it is not so complicated, but beware, an error in the fstab file may render the system unbootable, so always double check when making changes.

Image courtesy of mark | marksei
mark

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.