Overview of Fstab

Budhdi Sharma
7 min readMay 17, 2020
Linux Fstab

What Is Fstab?

Fstab is your operating system’s file system table. In the old days, it was the primary way that the system mounted files automatically. Nowadays, you can plug in a USB drive of any kind and it’ll just pop up in Nautilus as it does in Windows and Mac OS, but once upon a time, you had to manually mount those disks to a specific folder using the “mount” command. This held true for DVDs, CDs, and even floppies.

Back then, your only alternative was the tell the computer that anytime a specific device was plugged in, it should be automatically mounted in a specific place. This is where fstab came in, and it was awesome. Suppose you swapped hard disks on your IDE or SCSI controller. The computer could load the file systems in a different order, potentially messing things up. Fstab is configured to look for specific file systems and mount them automatically in the desired way each and every time, preventing a myriad of disasters from occurring.

The /etc/fstab file is a system configuration file that contains all available disks, disk partitions, and their options. Each file system is described on a separate line. Each line contains six fields separated by one or more spaces or tabs. If you add a new hard disk or have to repartition the existing one, you’ll probably need to modify this file.

Here is a sample /etc/fstab file:

sys info

As you can see from the output above, each line consists of six fields. Here is a description of each of them:

  • Device — the first field specifies the mount device. These are usually device filenames. Most distributions now specify partitions by their labels or UUIDs.
  • Mount point — the second field specifies the mount point, the directory where the partition or disk will be mounted. This should usually be an empty directory in another file system.
  • File system type — the third field specifies the file system type.
  • Options — the fourth field specifies the mount options. Most file systems support several mount options, which modify how the kernel treats the file system. You may specify multiple mount options, separated by commas.
  • Backup operation — the fifth field contains a 1 if the dump utility should back up a partition or a 0 if it shouldn’t. If you never use the dump backup program, you can ignore this option.
  • File system check order — the sixth field specifies the order in which fsck checks the device/partition for errors at boot time. A 0 means that fsck should not check a file system. Higher numbers represent the check order. The root partition should have a value of 1 , and all others that need to be checked should have a value of 2.

Consider the following line from our sample /etc/fstab file:

This line specifies that the partition /dev/sdc1 should be mounted on /novi_disk. The partition should be formatted with ext3. The mount, dump and fsck options are also specified.

Note: The /etc/mtab file lists the file systems currently mounted and their mount points. The mount and umount commands affect the state of mounted file systems and modify the /etc/mtab file.

The kernel also keeps information for /proc/mounts, which lists all currently mounted partitions. For troubleshooting purposes, if there is a conflict between /proc/mounts and /etc/mtab information, the /proc/mounts data is always more current and reliable than /etc/mtab.

View Currently Mounted File Systems

You can view the file systems currently mounted by entering the command mount. Information similar to the following appears:

# mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=487424k,nr_inodes=121856,mode=755)

/dev/vda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

You can also view this information in the file /proc/mounts.

# cat /proc/mounts

Mounting File Systems

A file system residing on a SATA/PATA or SCSI device needs to be mounted manually to access it. The mount command allows the root user to manually mount a file system. The first argument of the mount command specifies the file system to mount. The second argument specifies the target directory where the file system is made available after mounting it. The target directory is referred to as a mount point.

The mount command expects the file system argument in one of two different ways:

  • The device file of the partition holding the file system, residing in /dev.
  • The UU/D, a universally unique identifier of the file system.

Note: As long as a file system is not recreated, the UUID stays the same. The device file can change; for example, if the order of the devices is changed or if additional devices are added to the system.

The blkid command gives an overview of existing partitions with a file system on them and the UUID of the file system, as well as the file system used to format the partition.

# blkid/dev/vda1: UUID="74309cb6-4564-422f-bd07-a13e35acbb7a" TYPE="xfs"/dev/vdb: UUID="2018-04-26-04-03-48-00" LABEL="config-2" TYPE="iso9660"

To mount a device file pr partition which holds the filesystem:

# mount /dev/vda1 /mount_point

To mount the file system by a universally unique id, or the UUID, of the file system.

# mount UUID="46f543fd-7Bc9-4526-a857·244811be2dBB" /mount_point

Note: If the directory acting as mount point is not empty, the files that exist in that directory are not accessible as long as a file system is mounted there. All files written to the mount point directory end up on the file system mounted there.

Unmounting file systems

To unmount a file system, the umount command expects the mount point as an argument. Change to the /mount_point directory. Try to umount the device mounted on the /mnount_point mount point. It will fail.

# umount /mount_pointumount: /mount_point: target is busy.(In some cases useful info about processes that usethe device is found by lsof(8) or fuser(1))

Unmounting is not possible if the mount point is accessed by a process. For umount to be successful, the process needs to stop accessing the mount point. You can use lsof or fuser commands to identify the processes running on a particular mount point. Once you confirm that no processes are running on the mount point, you can umount the mount point without any error.

# umount /mount_point

What’s the Android equivalent of /etc/fstab?

Don’t think about Android as a heavily modified Linux distribution. Because it’s not. The nearly only thing that Android shares with a Linux distribution is the kernel. And even this component is modified. Also, other core components, like the libc, differ.

Android has no /etc/fstab

You don’t need /etc/fstab to mount a partition. But there is IIRC no mount command either.dev_mount should work (root required).

When we insert an sdcard/usb drive in an Android device, The system automatically mounts them for use. The vold [short for Volume Daemon] is the service responsible for detecting and mounting/unmounting of all the external or extended storage media in Android like usb, sdcard, cdrom.

Its main function involves in helping Android support hot pluggable storage devices.

The vold process receives external storage device connection or disconnection messages from the kernel to manage and control the external storage devices on the Android platform.

They include sdcard plugging, mounting, uninstalling, and formatting.

The filesystem table (/etc/fstab) has a column that contains various parameters that are read by the mounting utility. Many options are applicable to most or all filesystems. Then, there are some filesystem-specific options. Knowing most of these options can be quite beneficial to admins and general users.

General Settings

  • async — Asynchronous read and write
  • auto — Mount the filesystem on bootup
  • defaults — The typical setting for the filesystem being edited
  • dev — Recognize special block device files
  • exec — Allow executables to be executed
  • noauto — Do not mount the filesystem on bootup
  • nodev — Do not recognize special block device files
  • noexec — Do not permit executables to be executed
  • nosuid — Forbid the use of SUID
  • ro — Read-only
  • rw — Read+Write
  • suid — Allow the use of SUID
  • sync — Synchronous read and write

Linux-specific General Settings

  • atime — Last access time
  • ctime — Last status change time
  • mtime — Last modified time
  • noatime — Do not record last access time
  • owner — Allow the specified owner to mount the filesystem (owner=bob)
  • relatime — The last access time is updated if it is older than the last modified time
  • strictatime — Same as atime

Filesystem Specific

CIFS

  • guest — This option indicates that passwords are not required to access the server share
  • iocharset — Set the I/O character set (iocharset=utf8)
  • password — The password needed to access the share; this is the password of the Windows system
  • uid — Declare the owner of the share by UID
  • username — The user trying to access the share; this is the username of the Windows system

EXT2

  • check — Set the fsck checking level (none, normal, or strict)
  • debug — Print debug info
  • sb — Declare the location of the superblock by specifying a block (sb=5)

FAT

  • check — Check filenames to ensure that the correct naming schemes are used; choices include “r” (relaxed), “n” (normal), and “s” (strict)
  • conv — Perform DOS and Unix text-file conversions; choices include “b” (binary), “t” (text), and “a” (auto)

FAT and NTFS

  • dmask — Set the user directory creation mode mask
  • fmask — Set the user file creation mode mask
  • gid — Set the GID to give to files
  • uid — Set the UID to give to files
  • umask — Set the user file/directory creation mode mask
  • windows_names — Only permit characters accepted by Windows to be used in directory and file names

NFS

  • addr — Set the IP address

I hope you enjoyed this session. If you have any comments or questions or suggestions, please join the forum discussion below!

Thanks for the support( follow or Clapp)!!!!!

unix_tips

--

--

Budhdi Sharma

As an AOSP developer, I specialize in creating robust framework and system applications that seamlessly integrate with embedded systems on various SOCs