Linux /etc/fstab文件,linuxetcfstab文件


一,作用

/etc/fstab是用来存放文件系统的静态信息的文件,当系统启动时,系统会自动地从这个文件读取信息,并且会自动将此文件中指定的文件系统挂在到执行的目录

二,挂载的限制


1,根目录是必须挂载的,而且一定要先于其他mount point被挂载.因为mount是所有目录的根目录,其他目录都是由根目录/ 衍生出来的
2,挂载点的指定可以任意,但必须遵守必要的系统目录架构原则
3,挂载点必须是已经存在的目录
4,所有挂载点在同一时间只能被挂载一次
5,所有分区在同一时间只能挂在一次
6,若进行卸载,必须将工作目录退出挂载点(及其子目录)之外

三,/etc/fstab文件中的参数

cat /etc/fstab 查看当前系统已经存在的挂载信息
[root@server ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Mar 24 19:30:39 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=fd93d9dc-e277-4926-8a83-c731b5600f8b / ext4 defaults 1 1
UUID=c9517f8f-081d-444f-8510-92d236671b37 /boot ext4 defaults 1 2
UUID=bd841c60-daf5-4c5d-8392-95d4e8b9f4e7 /opt ext4 defaults 1 2
UUID=fe6dd69c-99f4-478d-acc7-ef7e156e5bc5 /usr/local ext4 defaults 1 2
UUID=1e71b8a2-bb4e-4e39-a894-e04fb6480e2e swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0

第一列:Device:磁盘设备文件或者该设备的Label或者UUID

The first field, (fs_spec), describes the block special device or remote filesystem to be mounted.
1),查看分区的label和uuid
Label就是分区的标签,在最初安装系统时填写的挂载点就是标签的名字.可以通过查看一个分区的superblock中的信息找到UUID和Label Name
如:要查看/dev/sda1这个设备的uuid和label name
命令1:dumpe2fs -h /dev/sda1
[root@server ~]# dumpe2fs -h /dev/sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /boot ---->这个就是Label name
Filesystem UUID: c9517f8f-081d-444f-8510-92d236671b37 ---->UUID
Filesystem magic number: 0xEF53

命令2:blkid
[root@server ~]# blkid
/dev/sda1: UUID="c9517f8f-081d-444f-8510-92d236671b37" TYPE="ext4"
/dev/sda2: UUID="1e71b8a2-bb4e-4e39-a894-e04fb6480e2e" TYPE="swap"
2),使用设备名和label及uuid作为标识的不同
使用设备名称(/dev/sda)来挂载分区时是被固定死的,一旦磁盘的插槽顺序发生了变化,就会出现名称不对应的问题。因为这个名称是会改变的。
不过使用label挂载就不用担心插槽顺序方面的问题。不过要随时注意label name,至于uuid,每个分区被格式化以后就会有一个UUID作为唯一的标识好。使用UUID作为唯一的标识号,使用UUID挂载的话就不用担心会发生错乱的问题

第二列: Mount point:设备的挂载点,就是要挂载到哪个目录下
The second field, (fs_file), describes the mount point for the filesystem. For swap partitions, this field should be specified as ‘none’. If the name of the mount point contains spaces these can be escaped as ‘\040’.


第三列:filesystem:磁盘文件系统的格式支持许多不同的文件系统:ext2,ext3,ext4,reiserfs,xfs,jfs,smbfs,iso9660,vfat,swap及auto,设置成auto类型,mount命令会猜测使用的文件系统类型,对CDROM和DVD等移动设备是非常有用的

The third field, (fs_vfstype), describes the type of the filesystem. Linux supports lots of filesystem types, such as adfs,affs, autofs, coda, coherent, cramfs, devpts, efs, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, ntfs, proc,qnx4, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs, and possibly others. For more details, see mount(8). For the filesystems currently supported by the running kernel, see /proc/filesystems. An entry swap denotes a file or partition to be used for swapping, cf. swapon(8). An entry ignore causes the line to be ignored. This is useful to show disk partitions which are currently unused. An entry none is useful for bind or move mounts.

第四列:parameters:文件系统的参数

 The fourth field, (fs_mntops), describes the mount options associated with the filesystem.

参数用途说明
auto 在启动时或键入了mount -a命令时,自动挂载
noauto 只在命令下被挂载
exec 允许执行此分区的二进制文件
noexec 不允许执行此文件系统上的二进制文件
ro 以只读模式挂载文件系统
rw 以读写模式挂载文件系统
user 允许任意用户挂载此文件系统,若无显示定义,隐含启用noexec、nosuid、nodev参数
users 允许所有users组中的用户挂载此文件系统
nouser 只能被root挂载
owner 允许设备所有者挂载
sync I/0同步进行
async I/O异步进行
dev 不解析文件系统上的块特殊设备
suid 允许suid操作和设定sgid位,这一参数通常用于一些reshuffle任务,使一般用户运行程序时提升权限
nosuid 禁止suid操作和设定sgid位
noatime 不更新文件系统上的inode访问记录,可以提升性能
nodiratime 不更新文件系统上的目录的inode访问记录
relatime 实时更新inode access记录,只有在记录中的访问时间早于当前访问才会被更新(与noatime相似,但不会打断如mutt或其它程序探测文件在上次访问后是否被修改的进程)
flush - vfat的选项 频繁的刷新数据,复制对话框或进度条在全部数据都写入后才消失
defaults 使用文件系统的默认挂载参数,例如:ext4的默认参数为:rw,suid,dev,exec,auto,nouser,async



第五列:能否被dump备份命令作用:dump是一个用来作为备份的命令,通常这个参数的值为0或1

  The fifth field, (fs_freq), is used for these filesystems by the dump(8) command to determine which filesystems need to be dumped. If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped.

数值说明
0 代表不要做dump备份
1 代表要每天进行dump的操作
2 代表不定日期的进行dump操作



第六列:是否检验扇区:开机的过程中,系统默认会以fsck检验我们系统是否为完整(clean)

   The sixth field, (fs_passno), is used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time. The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware. If the sixth field is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked.

数值说明
0 不要检验
1 最早检验(一般根目录会选择)
2 1级别检验完成之后进行检验



相关内容