/etc/fstab Explained

D

DevynCJohnson

Guest
On Linux, filesystems are mounted either manually or automatically. Every filesystem has a slightly different way of being mounted. It may help admins and causal users alike to know how to mount the various filesystems and how to setup the mount to occur automatically. Understanding the filesystem table (/etc/fstab) is an important part in having more knowledge in mounting filesystems.

Mounting is the process of linking a filesystem to the whole filesystem tree. For instance, on most Unixoid systems, flash-drives are mounted under a directory in /media/ or /mnt/. Then, the removable storage unit is part of the filesystem tree.

Unmounting is the opposite process where a filesystem is "disconnected" from the filesystem tree.

Anytime a storage unit is mounted, it must be mounted in an empty directory. For instance, to mount a flash-drive under /mnt/card/, the directory "card" must not contain any files. Then, when viewing the contents of /mnt/card/, the user will only see the files that are on the memory card.

On many Unix systems, the /etc/fstab file (commonly called the "Filesystem Table") lists filesystems that will be mounted on boot-up. Both real and virtual filesystems are listed (like the swap space). This file uses the following format template.

device-specification mountpoint fs-type options/parameters dump pass

The specification may be a path or protocol. For example, to mount tmpfs, the value of this field would be "tmpfs". To mount a hard-drive, the user would list the device path (like /dev/sdb3). For some virtual filesystems (like procfs) the value of this field is "none".

The mountpoint declares where the filesystem should be mounted.

The third field declares the filesystem type. This is an important field that users must be sure to properly type.

The options field lists the parameters that will be read by the "mount" command.

The dump field specifies the frequency that the "dump" utility will make a backup of the filesystem. "0" indicates never.

The last field ("pass") indicates when the "fsck" program should check the filesystem for errors. "0" means never, "1" is for the root (main) filesystem, and "2" indicates the filesystem is checked after the root filesystem.

NOTE: Solaris uses /etc/vfstab instead of /etc/fstab.

Some visual examples may help to better explain these concepts.

Code:
# Swap space
/dev/sda6  none  swap  defaults  0 0

# tmpfs
tmpfs  /mnt/tmpfschk  tmpfs  size=100m  0 0

# Proc
none  /proc  proc  defaults  0 0

# FAT, FAT32, etc.
/dev/sdc1  /media/flashdrive  vfat  umask=000  0 0

# NTFS
/dev/sdb1  /mnt/Windows  ntfs-3g  quiet,defaults,locale=en_US.utf8,umask=0,noexec  0 0

# CD/DVD
/dev/cdrom  /mnt/cdrom  udf,iso9660  noauto,owner,ro  0 0

# NFS
SERVER:/SHARE  /media/nfs_share  nfs  rw  0 0

# CIFS
//SERVER/SHARE  /media/cifs_share  cifs  credentials=/root/smbpass.txt  0 0

## By UUID instead of device path

# Home
UUID=7708003f-c85b-4c87-8bb9-d5c0357092bb  /home  ext4  defaults  0 2

# /
UUID=7c08c477-0ed4-4794-b847-982bce578592  /  ext4  errors=remount-ro  0 1

# Swap
UUID=4236dabb-fa7d-4066-b171-91ffa7afb4f4  none  swap  sw  0 0

# /boot
UUID=ba8bb222-1606-4875-a924-c2b905840e62  /boot  ext4  defaults  0 2

NOTE: The spacing between columns in the /etc/fstab file does not need to be consistent. However, at least one space or tab must be between each column.

The main idea/point of the first column is to specify the filesystem that the user wishes to mount. It can be named using UUID, device path, protocol/filesystem-type, or network share name.

Some filesystems (like swap) do not have a mountpoint. Therefore, "none" is an acceptable value for the second column.

In the third column, "vfat" is used to refer to FAT, FAT16, and FAT32 filesystems. "ntfs-3g" is the name of the NTFS driver/module.

Many parameters exist for the various filesystems. Discussing the numerous options is enough information to write a separate article. In general, users should understand the filesystem they are mounting and what they want the filesystem to do. Then, it is easier to figure out what parameters are needed.

After making changes to the /etc/fstab file, run "mount -a" (with Root privileges) to apply changes without rebooting.

Further Reading
 

Attachments

  • slide.jpg
    slide.jpg
    36.4 KB · Views: 31,786
Last edited:

Members online


Top