Http://blog.mcuol.com/User/xiaoxiaopig/Article/21147_1.htm
Many people often modify the/etc/fstab file, but many of them are not clear about the meaning of the file, as long as they follow a certain pattern, you can easily add a row of mounting information without fully understanding the principles. Next let's take a look at what we don't know.
/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 the file and automatically mounts the specified file system to the specified directory. The following describes how to enter information under this file.
In this file, we need to pay attention to its six domains:, and :,,,,,. The following describes the meanings of these six domains in detail.
1. file system. It is used to specify the device name or block information of the file system to be mounted, or remote file system. Anyone who has developed an embedded Linux system may know the significance of the Mount 192.168.1.56:/home/nfs/mnt/nfs/-O nolock (which can be other IP addresses) command. Its task is to mount the/home/nfs/directory on the remote host whose IP address is 192.168.1.56 to the/mnt/nfs/directory on the local machine. If you want to write it into the/etc/fstab file, enter/192.168.1.56:/home/nfs/as the file system /. If you want to mount a device on the local machine, write the following statements:/dev/sda1,/dev/hda2, or/dev/CDROM, /dev/sda1 indicates the first partition of the first serial hard disk or the first partition of the first SCSI hard disk./dev/hda1 indicates the first partition of the first IDE hard disk, /dev/CDROM indicates the optical drive. In addition, it can be represented by a label (volume label) or UUID (globally unique identifier of a universal unique identifier. Before using a label, you must first create an e2label, for example, e2label/dir_1/dir_2, which means/dir_2 is used to represent the name of/dir_1. Then, add label =/dir_2/dir_2 under/etc/fstab. After the restart, the system will mount/dir_1 to the/dir_2 directory. You can use vol_id-U/dev/sdax to obtain the UUID. For example, if you want to mount the first partition of the first hard disk, use the vol_id-U/dev/sda11 command to obtain the uuid, for example, 5dc08a62-4402-471b-9ef5-0a91e5e2c126. Then, enter: UUID = 5dc08a62-4402-471b-9ef5-0a91e5e2c126, which indicates/dev/sda11. Red Hat Linux generally uses label, while Ubuntu Linux generally uses UUID.
2. mount point. Mount point, that is, find one or create a Dir (directory), and then mount the file system to this directory. Then, you can access the file system to be mounted from this directory. For swap partitions, enter none in this field, indicating that no mount point exists.
3. type. The file system type is specified here. The following file systems are currently supported by Linux: ADFs, BEFS, CIFS, ext3, ext2, ext, iso9660, kafs, minix, msdos, vfat, umsdos, Proc, reiserfs, swap, squashfs, NFS, HPFs, ncpfs, NTFS, affs and UFS.
4. Options. The setting options are used here. Each option is separated by a comma. Because there are many options, and the space here is limited, we will not introduce them in detail. For more information, see the man mount command. However, here is a very important keyword to understand: defaults, which contains options RW, SUID, Dev, exec, auto, nouser, and async.
5. Dump. If this parameter is set to 1, the entire content is backed up; if it is set to 0, no backup is performed. Currently, dump is rarely used. Select 0 here.
6. Pass. It is used to specify how to use fsck to check the hard disk. If this field is set to 0, no check is performed. If the mount point is/(root partition), 1 must be entered here, and none of the other fields can be set to 1. If the number of partitions is greater than 1, after checking the root partition, check the number from small to large. Check the number at the same time. For example, enter 2 for the first and second partitions, 3 for the third and fourth partitions, and then check the first and second partitions after checking the root partitions, check the third and fourth partitions at the same time.
Fstab Parameters
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.
Fstab file DETAILS 2
/Etc/fstab is a text file in which each file system (including partitions or devices) is described in one row. In each row, 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.
Example (sdb1 is the new hard disk ):
#/Etc/fstab: static file system information.
#
#
Proc/proc defaults 0 0
/Dev/sda1/ext3 errors = remount-ro 0 1
/Dev/sda6/home ext3 defaults 0 2
/Dev/sda5 none swap SW 0 0
/Dev/HDC/Media/cdrom0 UDF, iso9660 user, noauto 0 0 0
/Dev/fd0/Media/floppy0 auto RW, user, noauto 0 0
/Dev/sdb1/release El ext3 defaults 0 2
Column 1 and Column 2: devices and default mount points
Column 3: File System Type
Column 4: Mount options (hard to understand)
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: use default configurations for all options, 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
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.