Learn to understand and edit fstab

Source: Internet
Author: User

If you are familiar with Linux, it is necessary to be familiar with some core configuration files, and fstab is one of them. This file describes information about various file systems in the system. The application reads the file and automatically mounts the file according to its content. Therefore, we need to understand the content, understand how it works with the mount command, and be able to modify its own situation.

As a system configuration file, fstab is usually located in the/etc directory. It contains information about all partitions and storage devices, and how they should be mounted. If you encounter something similar to the failure to mount your windows partition, you cannot use your optical drive, and you cannot write to a partition, you can basically conclude that, there is a problem with your fstab content. That is to say, you can modify it to solve these problems, instead of having to go to the Forum and kneel down for answers.

After talking about it for a long time,/etc/fstab is actually a text file that can be opened with gedit or VI. Of course, the premise is root permission. In this file, each file system (including partitions or devices) is described in one line. In each line, fields are separated by spaces or tabs, lines starting with * in the file are comments. Sorting records in fstab files is very important. This is because programs such as fsck, mount, and umount perform their work in this order. The following is a detailed explanation. This article assumes that the reader has the basic knowledge of mounting file systems and partitions.

Before explaining this, let's talk about how different systems are used by everyone, including hardware types and systems used. Therefore, the fstab file must be different. But its basic structure will not change as described above. Therefore, we will first describe the fstab content as a template.

First, take the following example:
/Dev/hda2/ext2 defaults 1 1
/Dev/hdb1/home ext2 defaults 1 2
/Dev/CDROM/Media/CDROM auto Ro, noauto, user, exec 0 0
/Dev/fd0/Media/Floppy auto RW, noauto, user, sync 0 0
Proc/proc defaults 0 0
/Dev/hda1 swap pri = 42 0 0

What do these seemingly meaningless characters represent? What does each column mean in each row of corresponding partition or storage device information? The first column indicates the device name, the second column indicates the mount point of the device, the third column is the file system, and the fourth column is the mount option, the Fifth Column is the dump option (represented by a number), and the sixth column (the following number) represents the file system check option. Now, we will introduce the specific meanings of these parameters in detail.

Column 1 and Column 2: devices and default mount points


To be honest, the content in the first and second columns is the simplest and most direct. Their role is to tell the mount command What partitions or devices I want to mount, and where I want the mount point. The mount point specified for a device in fstab is its default mount point, that is, if you do not manually specify other directories when mounting the directory, the system mounts the device to this directory. Most Linux distributions create dedicated directories for mount points, most of which are under/mnt, but some distributions (such as SuSE or UBUNTU) are under/media. I use Ubuntu, so the/Media Directory is also used in the sample information.

According to the fstab example

$ Mount/dev/fd0

Your drive will be mounted to/Media/floppy, because this is the default mount point that you tell the system. Without this information, when you press the mount command, the mount will be confused: Damn it, where do you want me to mount it? Of course, if you see that the default mount point specified by the fstab release is not pleasing to the eye, you can modify it as needed and change it to any directory you want. If the directory does not exist, create the directory first. You know, fstab won't pack all your work for you.

In addition, some partition and storage devices are automatically mounted when the Linux system is started. For example, let's take a look at the fstab sample information just listed. There are two rows like this:
/Dev/hda2/ext2 defaults 1 1
/Dev/hdb1/home ext2 defaults 1 2

As we mentioned earlier, the two lines indicate that/dev/hda2 is mounted to the/root directory by default, while/dev/hdb1 is mounted to the/home directory by default ,. This work will be automatically completed by reading fstab when your Linux system is started. Otherwise ...... Imagine what kind of suffering you will suffer. All programs are under the/root directory, but you cannot use it because you have not mounted/root directory! Well, I promise this will be a frustrating system experience.

In addition to the displayed device name, you can use the uuid of the device or the volume label of the device, for example, you can write "labal = root" or "UUID = 3e6be9de-8139-11d1-9106-a43f08d823a6" in this field to make the system more scalable. For example, if your system adds or removes a SCSI hard disk, this may change your device name, but it will not change your volume tag.

For the NFS mount operation, this field should contain information in the Host: Dir format, such as knuth. AEB. NL:/. For the process File System procfs, use Proc.

Column 3: File System Type

The third column in fstab indicates the file system type of the device or partition. It supports many types of file systems. Here we will only introduce the most commonly used file systems. If you want to know which file systems your kernel currently supports, you can view the/proc/filesystems content. If this field is defined as SWAP, this record is associated with a file or partition for the purpose of exchange. If this field is defined as ignored, this row will be ignored. This is very useful for displaying partitions that are not currently in use.

Ext2 and ext3: The ext2 File System in Linux is a standard file system in GNU/Linux systems. It features excellent file access performance, small and Medium files show more advantages, mainly because of the excellent design of the cluster cache layer. As for the ext3 file system, it belongs to a log file system and is an extension of the ext2 system. The advantage of a log-type file system is that it records the write operations of the entire disk in a certain area of the disk so that it can be traced back when necessary. Because every detail is recorded in detail, when a process is interrupted, the system can review and refresh the interrupted part based on these records, it does not have to take time to check other parts. Therefore, when the file system detects inconsistencies, the reorganization process is fast and almost no time is required.

Reiserfs: reiserfs is a very good file system. It is also one of the earliest log file systems used in Linux. Its Mechanism is much more advanced than ext3, which has been used by Xiao Lei. Many distributions now use it as the default file system. Unfortunately, the author had an accident some time ago ...... I don't know the specific situation, and I don't know whether the next generation of reiserfs4 can come out, because ext4 has all of them.

Swap: swap, that is, swap zone. Just think of it as virtual memory.

Vfat and NTFS: The partition format is windows. 98, me and other systems all use vfat, that is, the most popular FAT32 format, while the NT series mostly use NTFS, which is not fixed, of course, therefore, we need to analyze the specific situation of the XP system in 2000. At the beginning, Linux had poor support for NTFs writing. Therefore, we recommend that you use the vfat format for most data, but now the support is quite good, even if you do not re-compile the kernel, you can also write support through the ntfs-3g (refer to this article for specific methods), so don't care too much about this.

Auto: of course, this is not a file system type. Auto indicates that the file system type is automatically detected. In the above example, you will find that the file system types of the soft drive and the optical drive are both Auto. Why? Because their file system types may change at any time, such as a soft drive or USB flash drive, it may be in the vfat format today, and you will format it into NTFS tomorrow. Therefore, the most sensible way is to tell the system that I cannot determine the current type of this thing. You should check it yourself.

UDF: due to the increasing popularity of optical drive burning, in many fstab releases, the file format type of the optical drive is UDF, And the UDF is short for the universal disc format, which is compatible with the ISO 9660 format. It uses standard encapsulation write technology (PW, packet writing) to use CD-R/CD-RW as a hard disk, users can modify and delete files on the disc. When the UDF format is used for burning, the recording software packs the data, creates a special file directory table in the memory, and takes over the system's access to the CD.

Iso9660: This option is also used by many optical drives. Iso9660 is an international standard used to describe the structure of computer files suitable for CD disks. Disks using this standard can be used on different operating systems, such as MAC and windows.

Column 4: Mount options

The fourth column in fstab indicates the mounting options required by the device or partition. This column is also the most complex and error-prone column in fstab. Of course, as long as you know what some of the most common options mean, you can be freed from your headache. If you want to introduce one of the available options ...... Well, I guess I will write it to tomorrow, so I am just analyzing some of the most commonly used options. If you want to know more, turn to man.

Auto and noauto: This option controls whether devices are automatically mounted. Auto is the default option. In this way, the device is automatically mounted according to the fstab content when it is started or you use the Mount-a command. If you do not want this, use the noauto option. In this case, you can only manually mount the device.

User and nouser: This is a very useful option. The user option allows common users to mount devices, while the nouser option only allows root users to mount devices. Nouser is the default option, which is also a headache for many new Linux users, because they find that there is no way to mount the optical drive and Windows partition normally. If you encounter similar problems or other problems as a common identity user, add the user attribute to fstab.

Exec and noexec: exec allow you to execute executable binary programs in the corresponding partition. Likewise, noexec has the opposite effect. If you have a partition and some executable programs on the partition, you can use the noexec attribute if you don't want them, or you cannot execute them in your system. This often happens when Windows partitions are mounted. Exec is the default option. The reason is very simple. If noexec becomes the default option for your/root partition ......

RO: mount the file system in read-only mode.

RW: mount the system with readable and writable attributes.

Sync and async: How should input and output of the file system be completed. Sync means that synchronization is completed. In other words, when you copy something to a device or partition, all write changes will take effect immediately after you enter the CP command, this should be copied to the device or partition immediately. If async is used, that is, asynchronous input and output, When you copy something to a device or partition, it may take a long time after you press the CP command, the actual write operation is executed. In other words, it is buffered.

Sometimes this mechanism is quite good, because sync will affect the running speed of your system, but it will also cause some problems. Think about it. When you want to copy a file to a USB flash drive, you execute the CP command, but forget to execute the umount command (it will forcibly write the buffer content ), the file you copied is not actually on the USB flash disk. If you are using the MV command, and you will soon unmount the USB flash disk ...... Congratulations, the file will disappear from this planet. Therefore, although async is the default attribute, it is recommended that you use the sync option for portable storage devices such as USB flash drives and mobile hard disks.

Defaults: all options use the default configuration, including RW, SUID, Dev, exec, auto, nouser, and async.

Generally, you can use ults directly without special requirements. After reading the introduction, let's go back and look at the content of the previous example. Taking the optical drive as an example, we mainly focus on the mounting options here. We can see that the difference between the optical drive and other partition devices is Ro, because the General optical drive is read-only. Exec allows you to execute some programs directly from the optical drive.

Column 5 and column 6: dump and fsck options

Dump and fsck? What is this? Well, dump is a backup tool, while fsck is a file system scanning and checking tool. I will not introduce them in detail here, because man or Google can get more detailed information.

The Fifth Column of fstab indicates the dump option. The dump tool determines whether the file system needs to be backed up by the number on the option location. If it is 0, dump will be ignored. In fact, most dump settings are 0. The sixth column is The fsck option. The fsck command checks this field to determine the sequence in which the file system scans and checks. The value of the root file system/pair should be 1, other file systems should be 2. If the file system does not need to scan and check at startup, set this field to 0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.