/Etc/fstab is a file used to store static information of the file system. In the/etc/directory, you can run the command less/etc/fstab to view the changes. if you want to modify the changes, run the command vi/etc/fstab to modify the changes. When the system starts, the system automatically reads information from this file, the specified file system is automatically mounted to the specified/etc/fstab file to store the static information of the file system. In the/etc/directory, you can run the command less/etc/fstab to view the changes. if you want to modify the changes, run the command vi/etc/fstab to modify the changes.
When the system starts, the system automatically reads information from the file and automatically mounts the specified file system to the specified directory. The following describes how to enter information under this file.
File example
A simple/etc/fstab, using the kernel name to identify the disk:
/Etc/fstab
#
Tmpfs/tmp tmpfs nodev, nosuid 0 0
/Dev/sda1/ext4 defaults, noatime 0 1
/Dev/sda2 none swap defaults 0 0
/Dev/sda3/home ext4 defaults, noatime 0 2
Field Definition
The/etc/fstab file contains the following fields separated by spaces or tabs:
-The partition or storage device to be mounted.
- .
-The file system type of the device or partition to be mounted supports many different file systems: ext2, ext3, ext4, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap and auto. Set it to the auto type. The mount command guesses the file system type used, which is very useful for mobile devices such as CDROM and DVD.
-Parameters used for mounting. Note that some mount parameters are available only for a specific file system. Some common parameters include:
-
Auto-Automatic mounting when the mount-a command is started or typed.
Noauto-only mounted under your command.
Exec-binary files that are allowed to execute this partition.
Noexec-the execution of binary files on this file system is not allowed.
Ro-mount the file system in read-only mode.
Rw-mount the file system in read/write mode.
User-allows any user to mount the file system. If no definition is displayed, the noexec, nosuid, and nodev parameters are implicitly enabled.
Users-allows all users in the users group to mount the file system.
Nouser-can only be mounted by root.
Owner-allows the device owner to mount the disk.
Sync-I/O synchronization.
Async-I/O is asynchronous.
Dev-special block devices on the file system.
Nodev-do not parse block special devices on the file system.
Suid-allows suid operation and sgid setting. This parameter is usually used for some special tasks, so that the general user temporarily elevation of permissions when running the program.
Nosuid-disable the suid operation and set the sgid bit.
Noatime-inode access records on the file system are not updated to improve performance (see atime parameters ).
Nodiratime-inode access records of directories on the file system are not updated, which can improve performance (see atime parameters ).
Relatime-update inode access records in real time. Only when the access time in the record is earlier than the current access time will it be updated. (Similar to noatime, but does not interrupt processes such as mutt or other programs that detect whether a file is modified after the last access .), Improves performance (see atime parameters ).
The flush-vfat option refreshes data more frequently. the copy dialog box or progress bar disappears only after all data is written.
Defaults-use the default Mount parameters of the file system. for example, the default parameters of ext4 are rw, suid, dev, exec, auto, nouser, and async.
The dump tool determines when to back up the file system. dump checks its content and uses numbers to determine whether to back up the file system. The allowed numbers are 0 and 1. 0 indicates ignore. 1 indicates backup. Most users do not install dump. It should be set to 0.
Fsck read To determine the check sequence of the file system to be checked. The allowed numbers are 0, 1, and 2. The root directory should obtain the highest priority 1, and all other devices to be checked are set to 2. 0, indicating that the device will not be checked by fsck.
File system ID
In the/etc/fstab configuration file, you can use three different methods to represent the file system: Kernel name, UUID, or label. The advantage of using UUID or label is that they are irrelevant to the disk order. If you change the order of your storage device in the BIOS, or re-plug the storage device, or because some BIOS may randomly change the order of the storage device, UUID or label is more effective. See persistent block device name.
To display basic partition information, run:
$ Lsblk-f
NAME FSTYPE LABEL UUID MOUNTPOINT
Sda
─ ── Sda1 ext4 Arch_Linux 978e3e81-8048-4ae1-8a06-aa727458e8ff/
2017── sda2 ntfs Windows 6C1093E61093B594
└ ── Sda3 ext4 Storage f838b24e-3a66-4d02-86f4-a2e73e454336/media/Storage
Sdb
├ ── Sdb1 ntfs Games 9E68F00568EFD9D3
─ ── Sdb2 ext4 Backup 14d50a6c-e083-42f2-b9c4-bc8bae38d274/media/Backup
Sdc
└ ── Sdc1 vfat Camera 47FA-4071/media/Camera
Kernel name
You can use fdisk-l to obtain the kernel name with the prefix dev.
Tag
Note:With this method, each tag must be unique.
To display tags of all devices, run the lsblk-f command. Use LABEL = as the start of the device name in/etc/fstab:
/Etc/fstab
#
Tmpfs/tmp tmpfs nodev, nosuid 0 0
LABEL = Arch_Linux/ext4 defaults, noatime 0 1
LABEL = Arch_Swap none swap defaults 0 0
UUID
All partitions and devices have unique UUID. They are generated by the file system generation tool (mkfs. *) when creating a file system.
The lsblk-f command displays the UUID values of all devices. Use UUID = prefix in/etc/fstab:
/Etc/fstab
#
Tmpfs/tmp tmpfs nodev, nosuid 0 0
UUID = 24f28fc6-717e-4bcd-a5f7-32b959024e26/ext4 ULTS ults, noatime 0 1
UUID = 03ec5dd3-45c0-4f95-a363-61ff321a09ff/home ext4 ULTS ults, noatime 0 2
UUID = 4209c845-f495-4c43-8a03-5363dd433153 none swap ULTS 0 0
Tips and tips
Automatic mounting
If the/home partition is large, services that do not depend on the/home partition can be started first. Add the following parameters to the parameter section of the/home project in the/etc/fstab file:
X-systemd.automount, noauto
In this way, the/home partition will be mounted only when access is required. The kernel caches all file operations until/home partition preparation is complete.
Note:In this way, the file system type of/home is recognized as autofs, which is ignored during mlocate queries. The actual acceleration effect varies depending on the configuration, so please weigh whether or not you need it.
The same is true for mounting a remote file system. If you only want to mount it as needed, you can also add noauto, x-systemd.automount parameters. In addition, you can set the x-systemd.device-timeout = # parameter, set the timeout time, to prevent network resources cannot be accessed when a waste of time.
If your encrypted file system requires a key, you need to add the noauto parameter to the corresponding location in the/etc/crypttab file. When systemd is started, the encrypted device will not be turned on. it will wait until the device is accessed and then be mounted using the key file. For example, you can save some time when using an encrypted RAID device, because systemd does not have to wait until the device is available for access. For example:
/Etc/crypttab
Data/dev/md0/root/key noauto
Swap partition UUID
If the swap partition does not have a UUID, you can manually add it. If the lsblk-f command does not list the UUID of the swap partition, this is the case. To specify a UUID for a swap partition, follow these steps:
Confirm swap partition:
# Swapon-s
Disable swap partition:
# Swapoff/dev/sda7
Re-create a swap partition with the new UUID:
# Mkswap-U random/dev/sda7
Activate swap partition:
# Swapon/dev/sda7
The path name has spaces.
If there are spaces in the Mount path, you can use the "\ 040" escape character to indicate spaces (expressed in three octal numbers)
/Etc/fstab
UUID = 47FA-4071/home/username/Camera \ 040 Pictures vfat ULTS ults, noatime 0 2
/Dev/sda7/media/100 \ 040GB \ 040 (Storage) ext4 defaults, noatime, user 0 0
.....}}
External device
External devices are mounted when they are inserted, and are ignored when they are not inserted. This requires the nofail option. you can ignore it if the device does not exist at startup without reporting an error.
/Etc/fstab
/Dev/sdg1/media/backup jfs defaults, nofail 0 2
Atime parameters
Using noatime, nodiratime, or relatime can improve the performance of ext2, ext3, and ext4 disks. Linux uses the atime option by default. each time data is read (or written) on a disk, a record is generated. This is designed for servers and is of little significance in desktop use. The biggest problem with the default atime option is that even if you read files (from memory rather than disk) from the page cache, disk write operations will occur!
The noatime option is used to block write operations when reading files. Most applications work very well. Only a few programs such as Mutt need this information. Mutt users should use the relatime option. After the relatime option is used, the file access time write operation is generated only when the file is modified. The nodiratime option only disables file access time for directories. Relatime is a good compromise. Mutt and other programs can still work, but it can still improve system performance by reducing access time updates.
Note:Noatime already contains nodiratime. You do not need to specify them at the same time.
Tmpfs
Tmpfs is a temporary file system that resides in your swap partition or memory (depending on your usage ). It can improve the file access speed and ensure that these files will be automatically cleared during restart.
Frequently used tmpfs directories include/tmp,/var/lock and/var/run. do not use it in/var/tmp because temporary files in this directory need to be retained during restart. Using the tmpfs/run directory,/var/run and/var/lock are links created to be compatible with older versions. By default,/tmp in/etc/fstab is also tmpfs.
By default, tmpfs partitions are set to half your total memory. of course, you can set this value as needed. Note that the actual usage of memory and swap partitions depends on your usage, while tmpfs partitions do not occupy storage space before they are actually used.
To put/tmp in tmpfs, add/etc/fstab downstream:
/Etc/fstab
.....
Tmpfs/tmp tmpfs nodev, nosuid 0 0
.....
You can specify the size, but do not modify the mode option to ensure that the file has the correct access permission (1777 ). In the above example,/tmp will use up to half of the memory. to specify the maximum space, use the size mounting option:
/Etc/fstab
.....
Tmpfs/tmp tmpfs nodev, nosuid, size = 2G 0 0
.....
Here is a more advanced example to show how to add tmpfs mounting for users. For websites,MysqlTemporary file ,~ /. Vim/, which is useful in other cases. It is important to try and obtain the ideal mount options to accomplish the target. The goal is to try to adopt security policies to prevent abuse. It is safe to specify both uid and gid and mode. More information.
/Etc/fstab
Tmpfs/www/cache tmpfs rw, size = 1G, nr_inodes = 5 k, noexec, nodev, nosuid, uid = 648, gid = 648, mode = 1700 0 0
SeeMountRun the man manual to get more information.
It takes effect only after being restarted. Do not directly execute the mount-a command because the file in the current directory may not be accessible (for example, you should ensure the normal existence of lockfiles ). However, if they are all empty, you can directly mount-a without restarting your computer.
After the application changes, you can use findmnt to check whether the changes take effect:
$ Findmnt -- target/tmp
TARGET SOURCE FSTYPE OPTIONS
/Tmp tmpfs rw, nosuid, nodev, relatime
Use
Generally, programs that require a large number of read/write operations will improve performance when using tmpfs. When some programs put the shared memory on tmpfs, the performance will be greatly improved. for example, after the Firefox Profile folder is put into the memory, the Firefox performance will be greatly improved.
Note:The noexec parameter must be removed when the tmpfs Directory (/tmp) is mounted. otherwise, some compilation programs cannot be executed. In addition, the default size of tmpfs is the memory size, which may cause insufficient space.
The following command allows makepkg to be edited in the tmpfs directory or in/etc/makepkg. conf:
$ BUILDDIR =/tmp/makepkg
Read/write FAT32 for common users
To obtain the write permission for the FAT32 partition, you must modify the/etc/fstab file.
/Etc/fstab
/Dev/sdxY/mnt/some_folder vfat user, rw, umask = 000 0 0
The "users" label means that all users (or even non-root users) can mount or detach the partition '/dev/sdx '. The "rw" label is used to allocate read and write permissions. However, I do not know the meaning of the "umask" tag (umask is the permission mask command umask = 000 indicates that no one has the permission and the permission is 777, that is, everyone can read, write, and execute ). I tried to query in manmount, but there was no result.
For example, if your FAT32 partition is in '/dev/sda9' and you want to mount it to'/mnt/fat32', enter and run
/Etc/fstab
/Dev/sda9/mnt/fat32 vfat user, rw, umask = 111, dmask = 000 0 0