About fstab in linux

What Is Linux fstab File and How Can We Configure It?

Linux operating system relies on files. File systems should be mounted in order to be used. Mounting a file system can be with the mount command. In order to mount single or multiple file systems, we need some configuration. There is default configuration while using mount . But if we want to provide different options about mount we can use /etc/fstab file. In fstab we can provide information about the mount and automatically mounted files with during boot.

/etc/fstab File

fstab file is stored under the /etc directory. /etc/fstab file is a simple column based configuration file where configurations are stored as column based. We can open fstab with the text editors like nano , vim , Gnome Text Editor , Kwrite etc. but if we want to save the changes we made we require to get root privileges with the sudo command.

/etc/fstab File

After providing the password for the user ismail to get root privileges with sudo command we will see following fstab file content

/etc/fstab File

Comment

Before starting the detailed configuration about fstab we need to learn comment. In the previous screenshot, we see the turquoise lines those are comments. So lines starting with the # are comments. We can provide comments about newly created or changes configurations between configuration lines.

fstab Columns

As stated previously fstab file consists of columns which stored configuration options. Each row contains a single configuration record to mount and each column in this row contains different configuration options.

fstab Columns

Here is sample configuration row or record.

Each configuration columns is defined in the comment line which starts .

fstab Columns

We can see that the following configuration column is provided where we will explain them in detail.

  • `File System` is the source which we want to mount
  • `Mount Point` is the destination we want to mount
  • `Type` is the file system type of the `File System`
  • `Option` is used to specify the behavior of the mount
  • `Dump` specifies whether the file system will be dumped in the error case
  • `Pass` sets whether the file system check will be performed

File System Column

We will start with the first column which is used to specify the source file system device. Source file system device can be expressed in 2 different ways. The first way is specifying the path of the partition like /dev/sda1 . As dev path is used to store device information. Another way to specify the source file system is providing the UUID information like UUID=e1ea69a0-7566-4002-a47d-3a93d1ebfb96 .

File System Column

We can see that /dev/fd0 is the floppy disk.

We can find the UUID of a disk with the following blkid command which is shot form of Block ID . We should run with the sudo .

blkid list UUID

Mount Point or Dir Column

The second column specifies the path the source will be mounted. Generally, ile system root is specified as / . In this following screenshot, we can see that /dev/sda1 is mounted to the / .

Mount Point or Dir Column

We can see that /dev/fd0 is mounted to the /media/floppy0 . The following mounts are also popular in the Linux world.

  • `/mnt` is used to mounted external hard disk drives or USB.
  • `/boot` is used to mount boot partition and the kernel.
  • `/home` is used to mount users home directories

File System Type Column

Up to now, we have specified the source and destination partitions and locations. But as we know there are a lot of different file system types which is supported by Linux. ext4 , ext3 , fat , ntfs are some of them. In the file system type column, we can specify the file system with a single word.

Читайте также:  Windows 10 privacy picture

File System Type Column

We can see that in this example we are using ext4 and auto filesystems. auto is used to find source partition file system type automatically which can be used in some cases or different file systems like CDROM.

Options Column

Options column is the most comprehensive part of a fstab record. We can specify different behavior options int this part like automount, read-only, noatime etc.If there are multiple options we can delimit them with a comma. Here is an example of options column.

We can see that errors=remounte-ro is provided in the first line. Also rw , user , noauto , exec , utf8 is provided with comma delimiter.

  • `auto/noauto` is used to specify automatically mount given file system on boot. We can also block automount with the `noauto` option during boot.
  • `exec/noexec` is used to set mounted file system files to be executable. If we set to `noexec` the executables in the given file system will not be executed. This can be used to make user home directories `/home` more secure.
  • `ro/rw` is another useful option where we can make file system read-only or read-write. If we do not want to enable file, folder changes and removal we can mount read-only with the `ro` . But in most cases `rw` will be the best solution where we can change file system contents.
  • `sync/async` option is used to specify file system and disk synchronization. This option generally used to make file system more performative. If we select `sync` the changed content will be saved to the disk immediately which create some overload but will be more reliable. `async` will make write operation to the disk more flexible and more performative.
  • `nouser/user` is another important option. By default, normal users cannot mount a file system with the `mount` command and needs `root` privileges to mount. This is depicted with the `nouser`. If we want to normal user mount given file system we should provide `user` option which will enable a normal user to mount given file system.
  • `defaults` is a generic options wich is used in most of the cases which provides default options like `rw,suid,dev,exec,auto,nouser,async`
  • `noatime` option is used to disable access time information to be written to the file system. Disabling access time will boost the disk performance.
  • `suid/nosuid` option is used to allow `suid` and `sgid` bits.

Dump Column

Dump column is used to specify whether the there will a dump in an error event. This is designed in the old times and should be set to . 1 means enable dumping.

Pass Column

File systems can be corrupted in different situations like disk hardware problem, electricity problem or software bug. This requires a file system check. We can enable an automatic fsck by setting 1 . We should enable fsck for the root / file system. But we can skip for file systems like NTFS and FAT automatic file system check during reboot which can be accomplished after the start.

Mounting All File Systems In fstab

mount command is used to mount file systems in fstab . We can mount all filesystems given in fstab by using -a or —all option. Only the noauto file systems will be skipped and not mounted. Mount command will skip already mounted file systems too.

Umount File System

We can also mount an already mounted file system with the umount command. We just need to provide the file system or mounting point. In this example, we will umount /mnt .

uid or UUID Identifier

Harddisks or Partitions can be specified with the UUID or Unified Unique Identifier. This makes mount operations more stable because as its name suggests every disk or partition on the each will have a unique UUID. So they can not overlap accidentally. We can list uid with the following command.

uid or UUID Identifier

We can see that partition named /dev/sda1 has e1ea69a0-7566-4002-a47d-3a93d1ebfb96 as UUID.

noatime Mount Option

Performance is a very important factor in computer usage. The disk is one of the most important parts of computer performance. We can increase the performance of the file system or disk by skipping unnecessary disk operations like metadata storage. noatime will disable to store access time about file and folders in a file system.

Читайте также:  Сколько времени будет работать windows 10

Источник

fstab

The fstab(5) file can be used to define how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem.

Each filesystem is described in a separate line. These definitions will be converted into systemd mount units dynamically at boot, and when the configuration of the system manager is reloaded. The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like NFS or Samba are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in /etc/fstab should work out-of-the-box. See systemd.mount(5) for details.

The mount command will use fstab, if just one of either directory or device is given, to fill in the value for the other parameter. When doing so, mount options which are listed in fstab will also be used.

Contents

Usage

A simple /etc/fstab , using file system UUIDs:

  • describes the block special device or remote filesystem to be mounted; see #Identifying filesystems.
  • describes the mount directory.
  • the file system type.
  • the associated mount options; see mount(8) § FILESYSTEM-INDEPENDENT_MOUNT_OPTIONS and ext4(5) § MOUNT_OPTIONS .
  • is checked by the dump(8) utility. This field is usually set to 0 , which disables the check.
  • sets the order for filesystem checks at boot time; see fsck(8) . For the root device it should be 1 . For other partitions it should be 2 , or 0 to disable checking.

All specified devices within /etc/fstab will be automatically mounted on startup and when the -a flag is used with mount(8) unless the noauto option is specified. Devices that are listed and not present will result in an error unless the nofail option is used.

Identifying filesystems

There are different ways to identify filesystems that will be mounted in /etc/fstab : kernel name descriptor, file system label and UUID, and GPT partition label and UUID for GPT disks. UUID or PARTUUID must be privileged over kernel name descriptors and labels. See Persistent block device naming for more explanations. It is recommended to read that article first before continuing with this article.

In this section, we will describe how to mount filesystems using all the mount methods available via examples. The output of the commands lsblk -f and blkid used in the following examples are available in the article Persistent block device naming.

To use kernel name descriptors, use /dev/sdxy in the first column.

Kernel name descriptors

Run lsblk -f to list the partitions and prefix the values in the NAME column with /dev/ .

File system labels

Run lsblk -f to list the partitions, and prefix the values in the LABEL column with LABEL= or alternatively run blkid and use the LABEL values without the quotes:

File system UUIDs

Run lsblk -f to list the partitions, and prefix the values in the UUID column with UUID= or alternatively run blkid and use the UUID values without the quotes::

GPT partition labels

Run blkid to list the partitions, and use the PARTLABEL values without the quotes:

GPT partition UUIDs

Run blkid to list the partitions, and use the PARTUUID values without the quotes:

Tips and tricks

Automount with systemd

See systemd.mount(5) for all systemd mount options.

Local partition

In case of a large partition, it may be more efficient to allow services that do not depend on it to start while it is checked by fsck. This can be achieved by adding the following options to the /etc/fstab entry of the partition:

This will fsck and mount the partition only when it is first accessed, and the kernel will buffer all file access to it until it is ready. This method can be relevant if one has, for example, a significantly large /home partition.

Remote filesystem

The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the noauto,x-systemd.automount parameters. In addition, you can use the x-systemd.mount-timeout= option to specify how long systemd should wait for the mount command to finish. Also, the _netdev option ensures systemd understands that the mount is network dependent and order it after the network is online.

Читайте также:  Mac os масштабирование мышью

Encrypted filesystem

If you have encrypted filesystems with keyfiles, you can also add the noauto parameter to the corresponding entries in /etc/crypttab . systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd does not have to wait for the device to become available. For example:

Automatic unmount

You may also specify an idle timeout for a mount with the x-systemd.idle-timeout flag. For example:

This will make systemd unmount the mount after it has been idle for 1 minute.

External devices

External devices that are to be mounted when present but ignored if absent may require the nofail option. This prevents errors being reported at boot. For example:

The nofail option is best combined with the x-systemd.device-timeout option. This is because the default device timeout is 90 seconds, so a disconnected external device with only nofail will make your boot take 90 seconds longer, unless you reconfigure the timeout as shown. Make sure not to set the timeout to 0, as this translates to infinite timeout.

Filepath spaces

Since spaces are used in fstab to delimit fields, if any field (PARTLABEL, LABEL or the mount point) contains spaces, these spaces must be replaced by escape characters \ followed by the 3 digit octal code 040 :

atime options

Below atime options can impact drive performance.

  • The strictatime option updates the access time of the files every time they are accessed. This is more purposeful when Linux is used for servers; it does not have much value for desktop use. The drawback about the strictatime option is that even reading a file from the page cache (reading from memory instead of the drive) will still result in a write.
  • The noatime option fully disables writing file access times to the drive every time you read a file. This works well for almost all applications, except for those that need to know if a file has been read since the last time it was modified. The write time information to a file will continue to be updated anytime the file is written to with this option enabled.
  • The nodiratime option disables the writing of file access times only for directories while other files still get access times written.

When using Mutt or other applications that need to know if a file has been read since the last time it was modified, the noatime option should not be used; using the relatime option is acceptable and still provides a performance improvement.

Since kernel 4.0 there is another related option:

  • lazytime reduces writes to disk by maintaining changes to inode timestamps (access, modification and creation times) only in memory. The on-disk timestamps are updated only when either (1) the file inode needs to be updated for some change unrelated to file timestamps, (2) a sync to disk occurs, (3) an undeleted inode is evicted from memory or (4) if more than 24 hours passed since the the last time the in-memory copy was written to disk.

Note that the lazytime option works in combination with the aforementioned *atime options, not as an alternative. That is relatime by default, but can be even strictatime with the same or less cost of disk writes as the plain relatime option.

Remounting the root partition

If for some reason the root partition has been improperly mounted read only, remount the root partition with read-write access with the following command:

GPT partition automounting

When using UEFI/GPT, it is possible to omit certain partitions from /etc/fstab by partitioning according to the Discoverable Partitions Specification and have systemd-gpt-auto-generator(8) mount the partitions. See systemd#GPT partition automounting.

Источник

Оцените статью