/etc/fstab file Explanation
The file Fstab contains information about the storage device and its file system on your computer. It is the only file that determines how a hard disk (partition) is used or integrated into the entire system.
The full path to this file is/etc/fstab. It's just a text file that you can open with your favorite editor, but it must be the root user to edit it. At the same time, fsck, Mount, Umount and other commands all use the program.
Specifically: Using Fstab can automatically mount various file system formats of hard disk, partition, mobile devices and remote devices. For Windows and arch dual operating system users, you can share resources under Windows systems in Linux by mounting the FAT format and NTFS-formatted partitions with fstab.
Fstab File Example
Now let's look at a typical fstab file:
# <file System><dir><type><options><dump><pass>none /dev/pts devpts defaults 0 0none /dev/shm tmpfs defaults 0 0/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0/dev/dvd /media/dvd UDF ro,user,noauto,unhide 0 0/dev/fd0 /media/fl auto user,noauto 0 0/dev/hda1 swap Swap defaults 0 0/dev/hda4 / ext3 defaults 0 1/dev/hda3 /Home XFS rw,suid,exec,auto,nouser,async 0 2</pass></dump></options></type></dir ></file>
Fstab detailed
Let's take a detailed look at the usage of fstab. A typical entry has the following fields (fields are separated by a space or tab):
<file system><dir><type><options><dump><pass></pass></dump>< /options></type></dir></file>
- <file systems> is not a file system that we usually understand, but a device (hard disk and its partitions, DVD drives, etc.). It tells us the name of the device (partition), which is used when you mount (Mount), unload (Umount) devices on the command line. So one should substitute for this entry the device name, remote partition, or similar. </file>
- And tell us where the device is mounted.
- <type> refers to which file system type (e.g. Ext2, ext3, ReiserFS, XFS, JFS, Smbfs, iso9660, VFAT, NTFS, swap, etc.) the mounted device or partition is. ArchLinux supports many file systems. To get a complete support list look for Mount Man-page. Typical names include these: Ext2, ext3, ReiserFS, XFS, JFS, Smbfs, iso9660, VFAT, NTFS, swap and auto, ' Auto ' is not a file system, but the mount command automatically determines the file type, especially for Mobile device, floppy disk, DVD drive, doing so is necessary because the file type may be mounted inconsistently each time. </type>
- <options>, options, this section is the most useful setting!!! </options>
It allows you to mount the device on the boot automatically loaded, so that the Chinese display does not appear garbled, restrict the mount partition read and write permissions. It is related to the use of the Mount command, and to get a complete list, refer to Mount Manpage.
Noatime off the Atime feature to improve performance, which is an old feature that can be safely turned off and also reduces loadcycle
Defaults uses the default settings. Equal to Rw,suid,dev,exec,auto,nouser,async, the specific meaning of the following explanation.
-
- Automatic and manual mounting
Auto Mount noauto Device (partition) can only manually mount the file system can mounted only explicitly when starting or entering mount-a in the terminal.
iocharset= Add your local code after the = number, it seems that the file IO in this device (partition) is automatically encoded in the format of the conversion. For example: one of your partitions is encoded as UTF8, and the encoding of the files in the device is gb2312, and when you copy the files from your device to your partition, it will automatically encode the conversion. (I don't know if my understanding is right, but it seems to be possible to convert it with the NLS below.) )
-
- The solution of Chinese garbled characters
nls= Add your local code after the = number, your Chinese will not appear garbled.
-
- Read and Write permissions
Umask= This is about read and write permissions, it seems to be more effective than the following RO,RW options!!! For example: umask=000 or 0222, so that when the option in the mount is default, the ordinary user can still read and write the contents of the mounted device. please add!!! ro Mount as read-only permission RW mount as read-write permission
EXEC is a default setting that enables executable binaries in that partition to execute. noexec binary files are not allowed to execute. Never take this option in your root partition!!!
Sync All I/O will be synchronously asynchronous all I/O will be done in a non-synchronous manner
User allows any users to mount the device. implies Noexec,nosuid,nodev unless overridden. Nouser only allows root users to mount. This is the default setting.
Suid Permit The operation of Suid, and sgid bits. They is mostly used to allow users in a computer system to execute binary executables with temporarily elevated privilege s in order to perform a specific task. Nosuid Blocks The operation of Suid, and sgid bits.
- <dump> is the dump utility used to decide whether to make a backup. After installation (the default for Arch Linux is not to install dump), dump checks the entry and uses the numbers to determine whether to back up the file system. The allowed numbers are 0 and 1. If it is 0,dump will ignore the file system, if it is 1,dump will make a backup. Most of the users are not installing dump, so for them <dump> this entry should be written as 0. </dump></dump>
- <pass> Fsck checks the number of the bosses to determine the order in which the file system is checked (looks at the numbers substituted for <pass> and determines in which order th E file systems should be checked). The allowed numbers are 0, 1, and 2. The file system <pass> option is 0 will not be checked by fsck utility. The root filesystem should have the highest priority, 1, and all other file systems, if you want it to be check, should be written in 2. </pass></pass></pass>
Note: In addition to using the device (partition) name directly, you can also use the UUID or volume name. Format label= or uuid=<uuid>. For example, ' label=boot ' or ' uuid=3e6be9de-8139-11d1-9106-a43f08d823a6 '. </uuid>
Automatically mount FAT32 and NTFS partitions with Fstab
1. First use FDISK-L (may need to be under root) to obtain the disk information table, for example:
# Device Boot Start End Blocks Id system/dev/sda1 * 1 2397 19253871 b W95 fat32/dev/sda2 2398 3144 6000277+ , linux/dev/sda3 3145 9729 5 extended/dev/sda5 3145 3152 64228+ 52894012+ linux/dev/sda6 3153 3276 995998+ swap/solaris/dev/sda7 3277 7340 32644048+ 83 linux/dev/sda8 7341 9729 19189611 7 Hpfs/ntfs
From the above, there is only one hard disk on this computer, and the partition SDA1 and SDA8 are NTFS format, SDA1 is the disk which can be started, and thus may be the system of window. The system disk is mounted in read-only mode, and the non-system disk SDA8 is mounted in read-write mode (cannot be mounted on "/" and any of the following directories).
2. Open the/etc/fstab in the terminal with your favorite editor, for example:
Nano/etc/fstab
At the end of the file, add:
/DEV/SDA1/MNT/WINDOWSC vfat defaults,codepage=936,iocharset=cp936,umask=0222 0 0/DEV/SDA8/MNT/WINDOWSD NTFS defaults , Iocharset=utf8,umask=000,nls=utf8 0 0
Save, exit.
Warning: the use of 936 codepage hanging in the FAT32 partition may cause Linux under the recognition of Chinese normal but to Windows instead of garbled, recommended to replace the UTF8, but DMESG hint warning, no relationship, n A lot of people have been using this for a long time.
/DEV/SDA1/MNT/WINDOWSC vfat user,utf8,umask=000 0 0
3. Enter in the terminal
Mount-a
You should be able to find your system partition SDA1 content under/MNT/WINDOWSC, and find sda8 content in/HOME/USERNAME/WINDOWSD (where username refers to the user name).
The relationship between/etc/mtab and/etc/fstab
This file is best not to move it, it is for you to see, not for you to change
Fstab file Presumably everyone is familiar with the record of the computer on the hard disk partition information, when starting Linux, check the partition of the fsck command, and mount the partition mount command, all need the information in the Fstab, to properly check and mount the hard disk.
We can take a look at the contents of the mTAB file (this is the contents of the mTAB file on my Computer):
# Cat/etc/mtab
/dev/sda4/reiserfs rw,noatime 0 0
PROC/PROC proc Rw,nosuid,nodev,noexec 0 0
Sysfs/sys Sysfs rw,nosuid,nodev,noexec 0 0
Udev/dev Tmpfs rw,nosuid 0 0
Devpts/dev/pts devpts rw,nosuid,noexec 0 0
/dev/sda2/boot ext2 rw,noatime 0 0
Shm/dev/shm Tmpfs Rw,noexec,nosuid,nodev 0 0
/dev/sda1/mnt/winxp NTFS rw,utf8,umask=0 0 0
Usbfs/proc/bus/usb Usbfs rw,noexec,nosuid,devmode=0664,devgid=85 0 0
/dev/sdb5/media/swap vfat rw,nosuid,nodev,shortname=lower,uid=1000 0 0
At first glance, the structure and content of the Fstab file are basically the same, but the difference is that the mTAB file records the partition information that is currently mounted.
Whenever mount Mount partition, Umount unload partition, will dynamically update mtab,mtab always maintain the current system mounted partition information, FDISK, DF Such programs, must read the mTAB file, in order to obtain the current system in the partition mount situation.
/etc/fstab Documents and/etc/mtab