fstab 详解


:Mr.zhou  阅读: 1,037 次

  /etc/fstab 文件用来定义哪些磁盘分区、其他块设备、或远程文件系统在系统开机时挂载。

  该配置文件每行定义一个要挂载的文件系统。系统启动时会读取此配置文件,并对该配置文件中的文件系统进行自动挂载。默认需要挂载的文件系统如:/ 、/boot,会在挂载前进行必要的检查(fsck)并且在挂载一些远程文件系统前启动所需的服务,如系统会在网络服务启动完成后自动挂载远程的文件系统 NFS 、Samba。

[root@c1-oldbay ~]# cat /etc/fstab
#file system		dir		type     options        dump 		pass
/dev/sda3		/		ext4     defaults        1 		1
/dev/sda1		/boot		ext4     defaults        1 		2
/dev/sda2		swap		swap     defaults        0 		0

  每行中的不同字段用空格或者tab分隔。

  第一列 files system 为要挂载的分区或存储设备。

  第二列 dir 为挂载点。将第一列的文件系统挂载到什么位置。

  第三列 type 为要挂载的分区或设备的文件类型。一般支持的文件类型有:ext2、ext3、ext4、btrfs、reiserfs、xfs、jfs、smbfs、iso9660、vfat、ntfs、swap、auto。当使用auto时会让mount命令来猜测要挂载的文件系统使用的是什么文件类型,常用于挂载cd或dvd。

  第四列 options 为挂载系统时使用的选项。可以查看 mount 的man手册进行了解。

  第五列 dump 是否使用dump工具对文件系统进行备份。当此项值为0时,不对文件系统进行备份,值为1时进行备份。

  第六列 pass 是否使用 fsck 对文件系统进行检查。可选值为 0、1、2。根文件系统(/)的值必须设置为优先级最高的 1。其他需要进行检查的文件系统设为 2。若此项为 0,则不进行检查。

 

  确定要挂载的文件系统。

  第一列要挂载的文件系统可以是设备名、Label、UUID。可以使用 fsblk –f 显示块设备列表。

[root@c1-oldbay ~]# lsblk -f
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda                                                      
├─sda1 ext4         054fd0b1-1624-43d4-8955-1ced9914f2be /boot
├─sda2 swap         92ed7802-e438-416c-ac9a-88a8afa1f6eb [SWAP]
└─sda3 ext4         7612a4dd-9cda-4e64-82db-4cde0f8ab2b8 /
sr0
                                                      
[root@c1-oldbay ~]# cat /etc/fstab //设备名
/dev/sda3	/                       ext4    defaults        1 1
/dev/sda1	/boot                   ext4    defaults        1 2
/dev/sda2	swap                    swap    defaults        0 0

[root@c1-oldbay ~]# cat /etc/fstab  //UUID
UUID=7612a4dd-9cda-4e64-82db-4cde0f8ab2b8 /                       ext4    defaults        1 1
UUID=054fd0b1-1624-43d4-8955-1ced9914f2be /boot                   ext4    defaults        1 2
UUID=92ed7802-e438-416c-ac9a-88a8afa1f6eb swap                    swap    defaults        0 0

  option 选项:

auto / noauto

  With the auto option, the device will be mounted automatically at bootup or when the mount -a command is issued. auto is the default option. If you do not want the device to be mounted automatically, use the noauto option in /etc/fstab. With noauto, the device can be only mounted explicitly.

dev / nodev

  Interpret/do not interpret block special devices on the filesystem.

exec / noexec

  exec lets you execute binaries that are on that partition, whereas noexec does not let you do that. noexec might be useful for a partition that contains no binaries, like /var, or contains binaries you do not want to execute on your system, or that cannot even be executed on your system, as might be the case of a Windows partition.

rw / ro

  Mount the filesystem in either read write or read only mode. Explictly defining a file system as rw can alleviate some problems in file systems that default to read only, as can be the case with floppies or NTFS partitions.

sync / async

  How the input and output to the filesystem should be done. sync means it is done synchronously. If you look at the example fstab, you will notice that this is the option used with the floppy. In plain English, this means that when you, for example, copy a file to the floppy, the changes are physically written to the floppy at the same time you issue the copy command.

suid / nosuid

  Permit/Block the operation of suid, and sgid bits.

user / users / nouser

  user permits any user to mount the filesystem. This automatically implies noexec, nosuid, nodev unless overridden. If nouser is specified, only root can mount the filesystem. If users is specified, every user in group users will be able to unmount the volume.

defaults

  Use default settings. Default settings are defined per file system at the file system level. For ext3 file systems these can be set with the tune2fs command. The normal default for Ext3 file systems is equivalent to rw,suid,dev,exec,auto,nouser,async(no acl support). Modern Red Hat based systems set acl support as default on the root file system but not on user created Ext3 file systems. Some file systems such as XFS enable acls by default. Default file system mount attributes can be overridden in /etc/fstab.

owner (Linux-specific)

  Permit the owner of device to mount.

atime / noatime / relatime / strictatime (Linux-specific)

  The Unix stat structure records when files are last accessed (atime), modified (mtime), and changed (ctime). One result is that atime is written every time a file is read, which has been heavily criticized for causing performance degradation and increased wear. However, atime is used by some applications and desired by some users, and thus is configurable as atime (update on access), noatime (do not update), or (in Linux) relatime (update atime if older than mtime). Through Linux 2.6.29, atime was the default; as of 2.6.30 (9 June 2009), relatime is the default.


转载请注明原文链接:http://www.z-dig.com/fstab-xiangjie.html



正文部分到此结束