16 - / etc / fstab file

Lecture



The last lecture was devoted to mounting file systems and a *** *** mount unmount com. Today we will continue the topic and take a closer look at such an important system component as the / etc / fstab file . The file / etc / fstab contains a description of the file systems existing in the system. The file system here means the file system of the block device section existing in the operating system. The / etc / fstab file is used by programs such as mount, umount, and fsck . In order not to write all necessary options in the mount command, you can describe them in the / etc / fstab file , and then use mount in an abbreviated form. Each file system is described in a separate file line. The line is divided into fields using spaces or tabs. There are six fields in total. The following is a variant of the / etc / fstab file :

# / etc / fstab: static file system information.
#
# proc / proc proc defaults 0 0
# / was on / dev / sda1 during installation
UUID = 8d6bccd3-0bdf-487c-8b92-70e5b65aa756 / ext3 relatime, errors = remount-ro 0 1
# swap was on / dev / sda8 during installation
UUID = 49d78fcc-9bbc-43a6-a750-b0d85921a04c none swap sw 0 0
# / media / disk on / dev / sda2
UUID = d822a992-8a4f-48f0-8b7d-a529af066106 / media / disk ext3 nodev, rw, user 0 0
/ dev / scd0 / media / cdrom0 udf, iso9660 user, noauto, exec, utf8 0 0
/ dev / fd0 / media / floppy0 auto rw, user, noauto, exec, utf8 0 0

Lines beginning with # are comments. Consider the fields that each line of the / etc / fstab file consists of. For example, take the following line:

UUID = 8d6bccd3-0bdf-487c-8b92-70e5b65aa756 / ext3 relatime, errors = remount-ro 0 1

The first field contains an indication of the partition whose file system will be mounted on the system. The block device section can be specified directly - / dev / sda1 or through the UUID parameter. You can also specify a partition label. In the first case, our line would look like this:

/ dev / sda1 / ext3 relatime, errors = remount-ro 0 1

The UUID is a unique identifier for each partition on the hard disk. It is unique not only within your operating system, but also other systems. If you connect the drive to another computer with the Linux operating system, the UUID will be the same. Mounting in / etc / fstab through the UUID parameter is considered preferable because it allows you to uniquely identify any disk in the system. To view the UUID partitions of your disk. You must run the following com *** at:

igor @ adm-ubuntu: ~ / linux $ ls -l / dev / disk / by-uuid /
total 0
lrwxrwxrwx 1 root root 10 2009-11-16 11:05 362CA5282CA4E459 -> ../../sda6
lrwxrwxrwx 1 root root 10 2009-11-16 11:05 49d78fcc-9bbc-43a6-a750-b0d85921a04c -> ../../sda8
lrwxrwxrwx 1 root root 10 2009-11-16 11:05 8d6bccd3-0bdf-487c-8b92-70e5b65aa756 -> ../../sda1
lrwxrwxrwx 1 root root 10 2009-11-16 11:05 A24E667C4E6648DD -> ../../sda5
lrwxrwxrwx 1 root root 10 2009-11-16 11:05 C06A6F286A6F1A84 -> ../../sda7
lrwxrwxrwx 1 root root 10 2009-11-16 11:05 d822a992-8a4f-48f0-8b7d-a529af066106 -> ../../sda2

If you look at the contents of the / dev / disk directory, you can see that you can see other information about the disk partitions, for example, about the disk label (by-label):

igor @ adm-ubuntu: ~ / linux $ ls -l / dev / disk /
total 0
drwxr-xr-x 2 root root 360 2009-11-17 17:37 by-id
drwxr-xr-x 2 root root 80 2009-11-17 17:37 by-label
drwxr-xr-x 2 root root 220 2009-11-17 17:37 by-path
drwxr-xr-x 2 root root 160 2009-11-17 17:37 by-uuid

The second field in the / etc / fstab file contains the mount point . In our example, the partition with UUID = 8d6bccd3-0bdf-487c-8b92-70e5b65aa756 (or / dev / sda1 ) is mounted to the root of the file system - / . It should be understood that the mount point must exist. For example, if you write a line in the / etc / fstab file about mounting the / dev / sda3 partition to the / mnt / disk mount point, then the / mnt / disk directory should already exist.

The third field indicates the type of file system being mounted. You can see the list of supported file systems in the man fstab or man mount help. Here we will focus on the main ones. ext2, ext3, ext4 are native Linux operating system files. vfat - used to mount file systems of the FAT family (FAT12, FAT16, FAT32) . Also used when mounting flash drives and floppy disks. ntfs - used when mounting NTFS partitions of the Windows operating system. iso9660 and udf - used when mounting CDs, DVDs. Also in the third field there can be values: proc - for the / proc file system, swap - used to specify a special paging area, auto - in this case, an attempt will be made to automatically determine the type of file system. In order to view all the file systems that are supported by the kernel of your system, you need to execute a com *** in cat / proc / filesystems .

The fourth field of the / etc / fstab file contains additional mount options. Options can be both common to all types of file systems, and specific - which are used depending on the value of the third field. General options are discussed in the FILESYSTEM INDEPENDENT MOUNT OPTIONS section of the man fstab help, and specific ones in the FILESYSTEM SPECIFIC MOUNT OPTIONS section of the man fstab help. Options are comma-separated. There are quite a lot of options and more than one lecture will be needed to review them all, so I’ll focus on the most important ones.

sync - I / O operations are performed synchronously. That is, the information is immediately recorded on the device without waiting in a special area called buffer memory. For example, if you copy a small file to a USB flash drive or to a floppy disk, and then immediately pull it out, then without this option, the file may not yet be written to the media, but in the buffer memory.
async — I / O operations are performed asynchronously. Information can be recorded in the buffer memory, and then after some time on the carrier. It is not recommended to set for floppy or flash media.
atime — update file access time each time a file is accessed.
noatime - do not update file access time. It speeds up the file system, but you need to use it carefully.
auto - when the mount command is executed, all systems with the auto key will be automatically mounted. A com *** and mount -a is executed in the system boot scripts, so you can say that setting the auto option will allow you to automatically mount file systems when the system boots.
noauto - file systems with this option will be mounted only manually using the mount command.
exec - option allows to run executable files that are located on this file partition.
noexec - option prohibits to run executable files.
dev - option indicates that device files should be interpreted as device files.
nodev - device files will be interpreted as regular files. It is used if you need to mount the partition with another Linux system .
users - the option indicates that ordinary users can mount and unmount partitions.
user - any user can mount a partition, but only the one who mounted it or root can unmount it. Those. if the test user mounts the partition, then only test and root can unmount it.
nouser - only the root user can mount the partition.
suid - this option allows the use of the setuid and setgid bits.
nosuid - the option prohibits the use of the setuid and setgid bits. If these bits are set they will not be taken into account.
rw - mount file system in read / write mode.
ro - mount file system only in read mode.
defaults - option sets default options: rw, suid, dev, exec, auto, nouser, async .

Additional options for the vfat file system. Consider only a few of the most commonly used options.

uid = - set owner for file system objects.
gid = - set owner group for file system objects.
umask - set the umask parameter.
dmask - set the umask parameter for directories only.
fmask - set the umask parameter for files only.
codepage = - indicates in which code page the names of objects are stored. For Windows operating systems, for example, this parameter is set to cp1251 .
iocharset - indicates with which codepage our system works. This is usually utf8. That is, these two parameters show how to transcode the file names.

We will no longer list all the options for all file systems, since they are all very well described in the man mount help.

At the end of the lecture, I want to mention the option that is used not in the / etc / fstab file , but in the mount command. This is a remount option. This option is used if we need to change the parameters of an already mounted file system without unmounting it. Suppose there is a file system partition / dev / sda5, which is mounted to the mount point / mnt / disk5 . A record of this file system is present in the / etc / fstab file . If you specify both the file system partition and the mount point as parameters in the mount command, all previous mount options will be replaced with the new ones specified in the mount command:

mount -o remount, ro / dev / sda5 / mnt / disk5

If you specify only the mount point in the mount command, the options from the / etc / fstab file will be combined with the options specified in the mount command:

mount -o remount, ro / mnt / disk5

That is, if it is necessary to transfer the file system to read mode, then it is sufficient to simply run the *** at mount with the parameters remount and ro .

Also, do not forget that everything currently mounted is stored in the / etc / mtab file .


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

LINUX operating system

Terms: LINUX operating system