To:/etc/fstab

Source: Internet
Author: User
Tags gparted
/Etc/fstab official documentation
  • 1. What is fstab?
  • 2 fstab file example
  • 3 fstab file Composition
  • 4. File System ID
    • 4.1 Kernel naming
    • 4.2 UUID
    • 4.3 Label
  • 5. Suggestions
    • 5.1 atime Parameters
    • 5.2 tmpfs
      • 5.2.1 fixed shutdown exception caused by/var Partition
    • 5.3 solve the problem that path names with spaces cannot be used.
    • 5.4 external devices
  • 6 Use fstab to automatically mount FAT32 and NTFS partitions
  • 7. Related content
  • 8 references
What is fstab?

The file fstab contains information about the storage devices on your computer and their file systems. It determines how a hard disk (partition) is used or integrated into a unique file in the system.

The full path of this file is/etc/fstab. It is just a text file. You can open it in your favorite editor, but it must be a root user to edit it. At the same time, fsck, mount, umount and other commands all use this program.

Specifically, fstab can be used to automatically mount hard disks, partitions, removable devices, and remote devices in various file system formats. For Windows and arch operating systems, you can use fstab to mount partitions in the FAT format and NTFS format to share resources in Linux.

Fstab file example

Now let's take a look at a typical fstab file:

# <file system>        <dir>         <type>    <options>             <dump> <pass> none                   /dev/pts      devpts    defaults                0      0 none                   /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 

The following is another example, where more mounting options are used and the LABEL = method is used as the identifier of the mounted device.

proc    /proc           proc        rw,relatime                                             0 0 udev    /dev            devtmpfs    rw,nosuid,relatime,size=10240k,nr_inodes=94876,mode=755 0 0 sys     /sys            sysfs       rw,relatime                                             0 0 devpts  /dev/pts        devpts      rw,relatime,mode=600,ptmxmode=000                       0 0 none    /dev/shm        tmpfs       defaults,rw,relatime,size=400M                          0 0 tmpfs   /tmp            tmpfs       defaults,noatime,mode=1777                              0 0  LABEL=BOOT      /boot           ext2 defaults              0 1 LABEL=ROOT      /               ext4 defaults,noatime      0 1 LABEL=USR       /usr            ext4 defaults,noatime      0 0 LABEL=VAR       /var            ext4 defaults,noatime      0 0 LABEL=OPT       /opt            ext4 defaults,noatime      0 0 LABEL=HOME      /home           ext4 defaults,noatime      0 0 
Fstab file Composition

Let's have a detailed understanding of the usage of fstab. /Etc/fstab is composed of the following fields (separated by spaces or tabs ):

<file system> <dir> <type> <options> <dump> <pass> 
  • <File systems>-ID of the storage device (I. e./dev/sda1 ).
  • <Dir>-Tell the mount command where to mount the file device.
  • <Type>-Defines the type of the device or partition file system to be mounted, and supports many different file systems, such as ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. The 'auto' type allows the mount command to guess the file system type, which is very useful for removable devices such as CDROM and DVD.
  • <Options>-Special parameters for different file systems are defined. Parameters for different file systems are different. Some common parameters include the following:
  • The auto-File System will be automatically mounted at startup or when the 'mount-a' command is entered.
  • Noauto-the file system is mounted only under your command.
  • Exec-binary files that are allowed to execute this partition (default ).
  • Noexec-binary files on this file system cannot be executed.
  • Ro-mount the file system in read-only mode.
  • Rw-mount the file system in read/write mode.
  • Sync-I/O synchronization.
  • Async-I/O is asynchronous.
  • Flush-specify the FAT format to refresh data more frequently, so that the copy dialog box or progress bar continues until the file is written to the disk.
  • User-allows any user to mount the device (with the attributes of noexec, nosuid, and nodev parameters ).
  • Nouser-can only be mounted by root (default ).
  • Defaults-default mounting settings (rw, suid, dev, exec, auto, nouser, async ).
  • 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 sgid bit.
  • Noatime-do not update inode access records on the file system to improve performance (see atime_options ).
  • Nodiratime-do not update the directory access inode record on the file system to improve performance (see atime_options ).
  • 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 .), Improve performance (see atime_options ).
  • <Dump>Dump utility is used to determine when to back up the file system. After installation (ArchLinux is not installed by default), dump checks its content and determines whether to back up the file system with numbers. The allowed numbers are 0 and 1. 0 indicates ignore. 1 indicates backup. Most users do not install dump. For them, <dump> should be set to 0.
  • <Pass>Fsck reads the value of <pass> 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: description by kernal naming, 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.

Kernel naming

You can use fdisk to obtain the kernal naming representation:

# fdisk -l ...    Device Boot      Start         End      Blocks   Id  System /dev/sda1   *           1        2550    20482843+   b  W95 FAT32 /dev/sda2            2551        5100    20482875   83  Linux /dev/sda3            5101        7650    20482875   83  Linux /dev/sda4            7651      121601   915311407+   5  Extended /dev/sda5            7651       10200    20482843+  83  Linux /dev/sda6           10201       17849    61440561   83  Linux /dev/sda7           17850       18104     2048256   82  Linux swap / Solaris /dev/sda8           18105       18113       72261   83  Linux /dev/sda9           18114      121601   831267328+   7  HPFS/NTFS 
UUID

UUID is generated by the file system creation tool (mkfs. The blkid command displays the UUID value of the mounted device:

# blkid /dev/sda1: UUID="76E4F702E4F6C401" LABEL="vista" TYPE="ntfs" /dev/sda2: LABEL="Root" UUID="24f28fc6-717e-4bcd-a5f7-32b959024e26" TYPE="ext4" /dev/sda6: LABEL="Home" UUID="03ec5dd3-45c0-4f95-a363-61ff321a09ff" TYPE="ext4"  /dev/sda7: LABEL="swap" UUID="4209c845-f495-4c43-8a03-5363dd433153" TYPE="swap" /dev/sda10: UUID="0ea7a93f-537c-4868-9201-0dc090c050e4" TYPE="crypto_LUKS" /dev/mapper/sda10: UUID="d3560bbb-b5d5-46c5-a7a8-434c885217c7" UUID_SUB="425ab275-d520-4636-8d16-55fb2b957971" TYPE="btrfs" 

An example of the/etc/fstab configuration file identified by UUID is as follows:

# <file system>        <dir>         <type>    <options>             <dump> <pass> none                   /dev/pts      devpts    defaults                0      0 none                   /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   UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 /     ext4 defaults,noatime  0      1 UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff /home ext4 defaults,noatime  0      2 UUID=4209c845-f495-4c43-8a03-5363dd433153 swap  swap defaults          0      0 
Label

With this method, the device or partition must be identified. You can use some common tools such as e2label to mark ext2, ext3, and ext4 partitions.GpartedIt is also a good tool. Note that not all format partitions support tags (for example, the FAT file system does not support tags ).

The device cannot be mounted when you try to identify the device. You can use a LiveCD, DVD, or USBGpartedOr e2label to identify the device.

 e2label /dev/<disk-or-partition> Arch_Linux 

A label can contain a maximum of 16 characters. In theory, the label can contain spaces, but this will not be recognized by the fstab or GRUB configuration file.

Label naming should be clear enough to prevent possible conflicts. The following example shows how to identify a device with a label in fstab:

# <file system>        <dir>         <type>    <options>             <dump> <pass> none                   /dev/pts      devpts    defaults                0      0 none                   /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   LABEL=Arch_Linux       /             ext4      defaults,noatime        0      1 LABEL=Arch_Swap        swap          swap      defaults                0      0 
Recommended atime Parameters

Using noatime, nodiratime or relatime can improve the performance of ext2, ext3, and ext4 disks. By default, Linux generates a record every time it reads (or writes) data on a disk. This is designed for Linux servers and is of little significance in desktop use. These parameters are valid for most programs. But for mutt (which requires the record information), you should only use the realtime option.

Tmpfs

Tmpfs is a temporary file system that resides in your swap partition or memory (depending on your usage ). It improves the speed of some parts of the system and can automatically clear some files during restart.

Tmpfs can be safely used in/tmp,/var/lock and/var/run. do not use it in/var/tmp because temporary files in this directory are retained during restart.

Warning:Some daemon processes still install some files (or directories) under/var/lock and/var/run. Therefore, you need to edit the scripts under/etc/rc. d to make them work normally (such as lighttpd ).

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 use tmpfs in/tmp,/var/lock, And/var/run, add the following lines to/etc/fstab:

 tmpfs /tmp      tmpfs defaults,nodev,nosuid,mode=1777                 0 0  tmpfs /var/lock tmpfs defaults,nodev,nosuid,noexec,mode=1777,size=10m 0 0  tmpfs /var/run  tmpfs defaults,nodev,nosuid,noexec,mode=0755,size=10m 0 0 

You can specify the size here, but in this case you should highlight the mode part to ensure that they can have the correct permission settings. In the above example,/tmp will occupy half of your memory, and the other two directories are set to occupy 10 MB each.

SeeMountRun the man manual to get more information.

Production only after restart. Note: although this is very attractive and effective, do not directly executeMount-Command, because the current directory may be inaccessible (for example, you should ensure the normal existence of lockfiles ). However, if they are all empty, you can directly executeMount-Instead of restarting the computer. RunMount/tmpTo activate some of these options, and the rest will take effect after restart.

After making the above changes, you can use the df command to check whether it works as expected (Df-h):

 tmpfs                 2.0G   20K  2.0G   1% /tmp  tmpfs                  10M     0   10M   0% /var/lock  tmpfs                  10M   48K   10M   1% /var/run 
Fixed shutdown exception caused by/var Partition

When you mount/var/lock and/var/run to tmpfs, an independent partition/var cannot be detached at shutdown. This is because the tmpfs file system is not uninstalled by rc. shutdown.

To fix this problem, create the/etc/rc. d/functions. d/clean_umount file and add

clean_umount() {     umount /var/lock     umount /var/run } add_hook shutdown_postkillall clean_umount # vim: set ft=sh : 

This will cause/var/lock and/var/run to be uninstalled after all processes and daemon are completed and before/var is uninstalled.

Solve the problem that path names with spaces cannot be used.

You can use the "\ 040" Escape Character to represent spaces (expressed in three Octal numbers)

/dev/sda7                /home/username/Camera\040Picures   ext4  defaults,noatime       0  2 UUID=7D4500B3071E18B2    /media/100\040GB\040(Storage)      ntfs  defaults,noatime,user  0  0 
External Device

External devices can be mounted instantly, but the nofail option is ignored. This is used to prevent startup errors.

/Dev/sdg1/media/backup jfs noauto, nofail, rw, noatime, nodiratime 0 2

Use fstab to automatically mount FAT32 and NTFS partitions

1. first obtain the hard disk information table using fdisk-l (which may require root permission), for example:

#  Device Boot      Start         End      Blocks   Id  System /dev/sda1   *           1        2397    19253871    b  W95 FAT32 /dev/sda2            2398        3144     6000277+  83  Linux /dev/sda3            3145        9729    52894012+   5  Extended /dev/sda5            3145        3152       64228+  83  Linux /dev/sda6            3153        3276      995998+  82  Linux swap / Solaris /dev/sda7            3277        7340    32644048+  83  Linux /dev/sda8            7341        9729    19189611    7  HPFS/NTFS 

As we can see from the above, there is only one hard disk on this computer, where the sda1 and sda8 partitions are in NTFS format, sda1 is able to start, and thus may be the disk of the window system. The system disk is mounted in read-only mode, and the non-system disk sda8 is mounted in read/write mode (it cannot be mounted in any directory "/" or below ).

2. Use your favorite editor to open/etc/fstab in the terminal, for example, nano/etc/fstab.

Add the following content to the end of the file:

/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 and exit.

Warning:Hanging a 936 codepage on a fat32 partition may cause normal Chinese recognition in linux, but garbled characters appear in windows. We recommend replacing it with utf8, but the dmesg prompts a warning. It doesn't matter, n people have been using it for so long.
/dev/sda1 /mnt/WindowsC vfat user,utf8,umask=000 0 0 

3. input mount-a in the terminal, and you will be able to find your system partition sda1 in/mnt/WindowsC, find the content of sda8 in/home/username/WindowsD (username indicates the user name ).

Original article: http://blog.csdn.net/lrunyang/article/details/7028300

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.