Introduction to fstab
Last Updated: Wed, May 27, 2009The fstab is one of the first configuration files new Linux users get their hands on. Fstab stands for File System Table. It is basically a config file that will tell your computer which devices (or virtual devices) to use on boot.
The Fstab
In almost all distributions the fstab file is located in ‘/etc/fstab/’. You can open it up with your favorite editor:
vim /etc/fstab
Syntax
<file system> <dir> <type> <options> <dump> <pass>
File System
The first one, file system revers the block device:
- /dev/cdrom
- /dev/sda1
- /dev/dvd
- UUID=8af8255331ab
- LABEL=
Dir
This will be the directory where the device will be mounted to. In other words this will be the directory you will need to access in order to view the contents of the device. The general rule of thumb is that physical internal mounts are stored in /mnt and removable media is stored in /media.
Typical directories
- /mnt/someDrive
- /media/cdrom
- /media/dvd
- /media/someNFS
Type
The type specifies which type of file system you are trying to mount.
Common types are:
- ext3 - Linux FS
- ext4 - Version 4 of ext
- auto - Usually used for CD-ROM mounts
- ntfs-3g - NTFS (Windows)
- cifs - Windows file sharing
- nfs - Linux file sharing
To see all the file systems you have currently supported, do:
cat /proc/filesystems
Options
This section is where you specify file system specific options.
Dump
This field is used for file systems that use the dump command. A zero here will mean that the file system does not need to be “dumped”. Dump is a utility that will do a backup on the file system. Usually this value is set to zero.
Pass
Pass is the fsck (file system check) order. There are only 3 valid options here.
- 0 - do not check.
- 1 - check this partition first.
- 2 - check this partition(s) next
Usually you set your root partition to be checked first with ‘1’ and set all other partitions to ‘2’.
If you want to disable file system checking all together on the device use a ‘0’. This is commonly done on network shares and remote file systems.
Remount Everything in Fstab
It is common to want to update the system after you have made changes to the fstab config without having to reboot the computer.
To remount everything in fstab without restarting do:
sudo mount -a
Mount by UUID
You can run into problems when mounting removable devices using the ‘/dev/sdb1’ style. This style of pointing to devices depends on the order in which they are detected in boot which can change depending on if you add or change a hard drive or plug multiple USB devices in. For this reason I have been mounting all of my devices with the UUID instead.
Using the UUID of the hard drive we can mount the same drive no matter which order it comes up in boot or when it is detected. The UUID is a unique identifier for that particular drive. Linux will make no mistake when it comes to mounting file systems that are mapped by their UUID in fstab.
For example:
UUID=18EC910AEAEA90D084 /mnt/someDrive ntfs-3g defaults,user 0 1
This drive will always be mounted at the mount point ‘/mnt/someDrive’ even if we add or remove one of the other drives in the system.
To get the UUID of a drive first find traditional unix stlye map with:
sudo fdisk -l
This will give you a list of drives with some good identifying material, such as file system type and disk size. Look for the section that starts with ‘/dev/’ and remember what it says. For example mine says, ‘/dev/sdd1’.
Then do:
ls -l /dev/disk/by-uuid
This will print out all the UUIDs for each device.
Mounting NFS Shares
Here is an example of mounting an NFS share.
192.168.1.X:/media/sharename /media/sharename nfs rsize=8192,wsize=8192 0 0
Mounting Samba (Windows) Shares
Many systems are in a network with other operating systems. In order to communicate with Windows shares you will need to use cifs or smbfs.
//192.168.1.X/sharename /media/sharename cifs rw,user,username=username,password=password 0 0
Inevitably you are going to run across a Windows share that has a space in its name. Be sure to read: Mounting a Samba Share that has Spaces to find out how to work around the problem.
Mounting NTFS Shares
In order to mount NTFS (Windows) drives in Linux you will need to get the ntfs-3g driver. Which is the third generation of NTFS drivers. Ntfs-3g supports reading and writing to NTFS drives where older NTFS drivers only support reading.
UUID=18EC910AEAEA90D084 /mnt/someDrive ntfs-3g defaults,user 0 1
You might also want to check out Setting up sshfs. To mount directories over the secure protocol, SSH.