Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the fstab file in linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What is the fstab file in linux? for this question, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

/ etc/fstab is a file used to store static information about the file system. Located in the / etc/ directory, you can view it with the command less / etc/fstab, and if you want to modify it, modify it with the command vi / etc/fstab.

When the system starts, the system automatically reads information from this file and automatically mounts the file system specified in this file to the specified directory. Now I will introduce how to fill in the information under this document.

File example

A simple / etc/fstab that uses 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 Tab:

-the partition or storage device to be mounted.

-the mount position of.

-the file system type of the device or partition to be mounted, which supports many different file systems: ext2, ext3, ext4, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap and auto. Set to the auto type, the mount command guesses the type of file system used, which is useful for mobile devices such as CDROM and DVD.

-parameters used when mounting. Note that some mount parameters are unique to specific file systems. Some of the more common parameters are:

Auto-mounts automatically at startup or when the mount-a command is typed.

Noauto-mounted only at your command.

Exec-binaries that allow execution of this partition.

Noexec-binary files on this file system are not allowed to be executed.

Ro-Mount the file system in read-only mode.

Rw-Mount the file system in read-write mode.

User-allows any user to mount this file system, implicitly enabling noexec, nosuid, nodev parameters if there is no display definition.

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.

Sync-I PUBO was carried out synchronously.

Async-I PUBO is carried out asynchronously.

Dev-parses block special devices on the file system.

Nodev-Block special devices on the file system are not resolved.

Suid-allows suid to operate and set sgid bits. This parameter is usually used for special tasks to temporarily elevate privileges when the average user runs the program.

Nosuid-disables suid operation and setting the sgid bit.

Noatime-performance can be improved by not updating the inode access record on the file system (see the atime parameter).

Nodiratime-does not update the directory inode access records on the file system, which can improve performance (see the atime parameter).

Relatime-updates the inode access record in real time. Only the access time in the record is earlier than the current access will be updated. Similar to noatime, but does not interrupt processes such as mutt or other programs that detect whether files have been modified since they were last accessed. To improve performance (see the atime parameter).

Flush-vfat option to refresh data more frequently, copy dialog boxes or progress bars do not disappear until all data has been 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, async.

The dump tool uses it to determine when to make a backup. Dump examines its contents and uses numbers to determine whether to back up the file system. The allowed numbers are 0 and 1. 0 means ignore, 1 means backup. Most users do not have dump installed, so it should be set to 0 for them.

The value read by fsck determines the check order of the file system that needs to be checked. The allowed numbers are 0, 1, and 2. The root directory should be given the highest priority 1, and all other devices that need to be checked are set to 2. 0 to indicate that the device will not be checked by fsck

File system identification

You can represent the file system in three different ways in the / etc/fstab configuration file: kernel name, UUID, or label. The advantage of using UUID or label is that they are independent of disk order. If you change the order of your storage devices in BIOS, or reseat storage devices, or because some BIOS may randomly change the order of storage devices, it would be more efficient to use UUID or label. See persistent block device name.

To display basic information about the partition, run:

$lsblk-fNAME FSTYPE LABEL UUID MOUNTPOINTsda ├─ sda1 ext4 Arch_Linux 978e3e81-8048-4ae1-8a06-aa727458e8ff / ├─ sda2 ntfs Windows 6C1093E61093B594 └─ sda3 ext4 Storage f838b24e-3a66-4d02-86f4-a2e73e454336 / media/Storagesdb ├─ sdb1 ntfs Games 9E68F00568EFD9D3 └─ sdb2 ext4 Backup 14d50a6c-e083-42f2-b9c4-bc8bae38d274 / media/Backupsdc └─ sdc1 vfat Camera 47FA-4071 / media/Camera kernel name

You can use fdisk-l to get the kernel name, prefixed with dev.

Label

Note: using this method, each label must be unique.

To display the labels for all devices, use the lsblk-f command. Use LABEL= as the beginning of the device name in / etc/fstab:

/ etc/fstab# tmpfs / tmp tmpfs nodev,nosuid 0 0 LABEL=Arch_Linux / ext4 defaults,noatime 0 1LABEL=Arch_Swap none swap defaults 0 0UUID

All partitions and devices have a unique UUID. They are generated by the file system generation tool (mkfs.*) when the file system is created.

The lsblk-f command displays the UUID values for all devices. Use the UUID= prefix in / etc/fstab:

/ etc/fstab# tmpfs / tmp tmpfs nodev,nosuid 0 UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 / ext4 defaults,noatime 0 1UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff / home ext4 defaults Noatime 0 2UUID=4209c845-f495-4c43-8a03-5363dd433153 none swap defaults 0 0 hints and tips automatically mount

If the / home partition is large, services that do not depend on the / home partition can be started first. Just add the following parameters to the parameters section of the / home project in the / etc/fstab file:

Noauto,x-systemd.automount

In this way, the / home partition will be mounted only if access is needed. The kernel caches all file operations until the / home partition is ready.

Note: doing so will cause the file system type of / home to be recognized as autofs, causing the directory to be ignored when mlocate queries. The actual acceleration effect varies from configuration to configuration, so weigh whether you need it or not.

The same goes for mounting a remote file system. If you only want to mount when needed, you can also add the noauto,x-systemd.automount parameter. In addition, you can set the x-systemd.device-timeout=# parameter and set the timeout to prevent time-wasting when network resources are inaccessible.

If your encrypted file system requires a key, you need to add the noauto parameter to the corresponding location in the / etc/crypttab file. Systemd will not turn on the encryption device when it is powered on and will wait until the device is accessed before using the key file to mount. For example, you can save some time when using encrypted RAID devices, because systemd does not have to wait until the device is available before it can be accessed. For example:

/ etc/crypttabdata / dev/md0 / root/key noauto exchange partition UUID

If the swap partition does not have a UUID, you can join it manually. This occurs if the UUID of the swap partition is not listed using the lsblk-f command. Here are the steps to specify UUID for the swap partition:

Determine the swap partition:

# swapon-s

Disable swapping:

# swapoff / dev/sda7

Recreate the swap partition with the new UUID:

# mkswap-U random / dev/sda7

Activate the swap partition:

# swapon / dev/sda7 pathname has a space

If there is a space in the mounted path, you can use the "\ 040" escape character to represent the space (represented by three octets)

/ etc/fstabUUID=47FA-4071 / home/username/Camera\ 040Pictures vfat defaults,noatime 0 2/dev/sda7 / media/100\ 040GB\ 040 (Storage) ext4 defaults,noatime,user 00

.}}

peripheral

External devices are mounted when plugged in and ignored when not plugged in. This requires the nofail option, which can be ignored without reporting an error if the device does not exist at startup.

/ etc/fstab/dev/sdg1 / media/backup jfs defaults,nofail 0 2atime parameter

Using noatime, nodiratime or relatime can improve the performance of disks in ext2, ext3 and ext4 formats. Linux uses the atime option by default, and a record is generated each time data is read (or written) on disk. This is designed for servers and doesn't make much sense in desktop use. The biggest problem with the default atime option is that disk writes occur even if files are read from the page cache (from memory instead of disk)!

The use of the noatime option prevents writing when reading the file. Most applications work well. Only a few programs such as Mutt need this information. Users of Mutt should use the relatime option. With the relatime option, file access time writes occur only if the file is modified. The nodiratime option disables file access time only for directories. Relatime is a good compromise, and programs such as Mutt can still work, but can still improve system performance by reducing access time updates.

Note: noatime already includes nodiratime. You don't need to specify it at the same time.

Tmpfs

Tmpfs is a temporary file system that resides in your swap partition or memory (depending on your usage). Use it to improve file access speed and ensure that these files are automatically cleared when you restart.

The directories that often use tmpfs are / tmp, / var/lock and / var/run. Do not use it on / var/tmp because temporary files in this directory need to be retained during the restart process. Using the tmpfs / run directory, / var/run and / var/lock are links made to be compatible with older versions. The / tmp in the default / etc/fstab is also tmpfs.

By default, the tmpfs partition is set to half your total memory, which you are free to set. Note that the actual use of memory and swap partitions depends on your usage, while tmpfs partitions do not take up storage space until they are actually used.

To put / tmp into tmpfs, add the following line to / etc/fstab:

/ 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 (1777). In the above example, / tmp will use up to half of the memory. To specify the maximum space, use the size mount option:

/ etc/fstab.tmpfs / tmp tmpfs nodev,nosuid,size=2G 0 0.

Here is a more advanced example of how to add tmpfs mounts for users. This is useful for websites, mysql temporary files, ~ / .vim /, and other situations. It is important to try and get the ideal mount option to achieve the goal. The goal is to use safe policies as far as possible to prevent abuse. It is very safe to limit the size and specify both uid and gid plus mode. More information.

/ etc/fstabtmpfs / www/cache tmpfs rw,size=1G,nr_inodes=5k,noexec,nodev,nosuid,uid=648,gid=648,mode=1700 00

Refer to the mount command man manual for more information.

It will not take effect until it is rebooted. Be careful not to execute the mount-a command directly, as it may make it impossible to access files in the current directory (for example, you should ensure the normal existence of lockfiles). However, if they are all empty, you can execute mount-a directly without having to restart the computer.

After applying the changes, you can check whether the changes are in effect through findmnt:

$findmnt-target / tmpTARGET SOURCE FSTYPE OPTIONS/tmp tmpfs tmpfs rw,nosuid,nodev,relatime use

Programs that require a lot of read and write operations generally improve performance when using tmpfs. The performance of some programs will be greatly improved when they store the shared files on tmpfs, for example, after putting the Firefox Profile folder in memory, the performance of Firefox will be greatly improved.

Note: the noexec parameter needs to be removed when mounting the tmpfs directory (/ tmp), otherwise some compilers cannot be executed. In addition, the default size of tmpfs is the average amount of memory, which may cause the problem of insufficient space.

The following command allows makepkg to be edited in the tmpfs directory or set in / etc/makepkg.conf:

$BUILDDIR=/tmp/makepkg makepkg ordinary users read and write FAT32

In order to get write access to the FAT32 partition, you must modify the / etc/fstab file.

/ etc/fstab/dev/sdxY / mnt/some_folder vfat user,rw,umask=000 00

The "users" tag means that any user (even a non-root user) can mount or unmount the partition'/ dev/sdX'. The "rw" tag assigns read and write access. But I don't know the meaning of the "umask" tag (umask is the permission mask command umask=000, which means that anyone has no privileges, and the permission is 777, that is, everyone can read, write, and execute). I tried to query in "man mount", but to no avail.

For example, if your FAT32 partition is in'/ dev/sda9', and you want to mount it to'/ mnt/fat32', then you need to type and run it.

/ etc/fstab/dev/sda9 / mnt/fat32 vfat user,rw,umask=111,dmask=000 00 this is the answer to the question about what the fstab file in linux is. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report