/etc/fstab

From Leo's Notes
Last edited on 14 February 2022, at 19:58.

The fstab (short for file system tab) file contains all the filesystems that the system should be aware of.

There are a couple benefits for defining mount points in the fstab. Mounts defined here will automatically be mounted on startup or with the mount -a command unless it has the mount noauto option. Additionally, all mounts defined in the fstab can be mounted using the mount command with either its source or target without needing so specify its type or mount options. For example, rather than running something like mount -t iso9660 -o ro,owner,users /dev/sr0 /media, you can add this into /etc/fstab and only need to run mount /dev/sr0.

Quick introduction

The /etc/fstab file contains 6 fields that are separated by one or more space.

Field Notes and examples
Source / device or location You can use any storage device or location. This gets passed to the appropriate mount command as specified by the filesystem type.
  • Block device: /dev/sda, LABEL=xxx
  • Device by UUID as determined by blkid: /dev/disk/by-uuid/xxx, UUID=xxx
  • NFS: server:/export
  • SMB: //server/share
Mount location Where the filesystem will be mounted to.

Use none for swap. If your mount locations require white spaces, replace spaces with \040 and tabs with \011.

Filesystem type The filesystem type, such as nfs, xfs, ext4, etc.

This determines which mount command will be used (eg. mount.xfs, mount.nfs).

Mount options The mount options. Multiple options can be separated by a comma. Common ones include:
  • defaults - implies rw,suid,dev,exec,auto,nouser,async
  • noauto - don't mount when calling mount -a or on startup
  • user / owner - allow a user / owner to mount
  • nofail - ignore if device does not exist.
Dump Determines which filesystems need to be dumped.

Typically set to 0 unless you use the dump utility to create filesystem backups.

fsck check order number Determines the order in which filesystem checks are performed at startup.

Example fstab file

Here's a fabricated example fstab file showing various types of filesystem types.

UUID=77b3f648-c22c-4d6b-8bd2-755eff159d61 /                xfs     defaults                      1 1
UUID=da826930-98dd-4693-b665-499caa90f2de /boot            ext2    defaults                      1 2
netapp:/Home                              /home            nfs     vers=3,intr,hard,retry=1      0 0
//netapp/OS                               /mnt/OS          cifs    credentials=/etc/cifspw       0 0
/dev/mapper/rl-swap                       none             swap    defaults                      0 0

Other notes

NFS

freebsd:/storage/downloads      /mnt/downloads  nfs     defaults        0 0

CIFS / Samba

See More at Mounting / Unmounting Samba

//10.1.1.123/share     /mnt/share      cifs      credentials=/etc/cifs_passwd     0 0

The credentials file should contain two lines. Make sure that it's not world readable (chmod 600 it!)

username=leo
password=53cr3T$

If you wish to put in the username/password directly (and thereby making visible to anyone doing a df), you can pass in username and password directly as the mount options:

//10.1.1.123/share     /mnt/share      cifs      username=leo,password=secret    0 0

Network Mounts

For mounts that require the network interface to be started (such as iSCSI targets), you will need _netdev. eg:

UUID=bd1d7f88-5845-4df1-8bac-e28ce019847f       /data                   ext3    _netdev 1 2

Troubleshooting

Wrong fs type

The first time I ran mount -a, I got the following error:

root@server:~# mount -a
mount: wrong fs type, bad option, bad superblock on //box/Volume_1,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

with dmesg showing:

CIFS VFS: No username specified
CIFS VFS: cifs_mount failed w/return code = -22

Error -22 means the executable doesn't exist. To resolve this, install cifs-utils

# yum -y install cifs-utils