说明:有部分内容参考资料

一.简介:

tune2fs是调整和查看ext2/ext3文件系统的文件系统参数,Windows下面如果出现意外断电死机情况,下次开机一般都会出现系统自检。Linux系统下面也有文件系统自检,而且是可以通过tune2fs命令,自行定义自检周期及方式。

二.用法:

tune2fs [ -l ] [ -c max-mount-counts ] [ -e errors-behavior ] [ -f ] [ -i interval-between-checks ] [ -j ] [ -J journal-options ] [ -m
reserved-blocks-percentage ] [ -o [^]mount-options[,...] ] [ -r reserved-blocks-count ] [ -s sparse-super-flag ] [ -u user ] [ -g
group ] [ -C mount-count ] [ -L volume-name ] [ -M last-mounted-directory ] [ -O [^]feature[,...] ] [ -T time-last-checked ] [ -U
UUID ] device

常用选项说明:
-l 查看文件系统信息
-c max-mount-counts 设置强制自检的挂载次数,如果开启,每挂载一次mount conut就会加1,超过次数就会强制自检
-i interval-between-checks[d|m|w] 设置强制自检的时间间隔[d天m月w周]
-m reserved-blocks-percentage 保留块的百分比
-j 将ext2文件系统转换为ext3类型的文件系统
-L volume-label 类似e2label的功能,可以修改文件系统的标签
-r reserved-blocks-count 调整系统保留空间
-o [^]mount-option[,...] Set or clear the indicated default mount options in the filesystem. 设置或清除默认挂载的文件系统选项

三.例如:

tune2fs -c 30 /dev/hda1 设置强制检查前文件系统可以挂载的次数
tune2fs -c -l /dev/hda1 关闭强制检查挂载次数限制。
tune2fs -i 10 /dev/hda1 10天后检查
tune2fs -i 1d /dev/hda1 1天后检查
tune2fs -i 3w /dev/hda1 3周后检查
tune2fs -i 6m /dev/hda1 半年后检查
tune2fs -i 0 /dev/hda1 禁用时间检查

tune2fs -j /dev/hda1 添加日志功能,将ext2转换成ext3文件系统

tune2fs -r 40000 /dev/hda1 调整/dev/hda1分区的保留空间为40000个磁盘块

tune2fs -o acl,user_xattr /dev/hda1 设置/dev/hda1挂载选项,启用Posix Access Control Lists和用户指定的扩展属性

开机取消自检:

tune2fs -l /dev/sdb1 | grep -E ‘Maximum mount count:|Check interval’
tune2fs -i 0 -c 0 /dev/sdb1

更改文件系统标签:

[root@bogon ~]# blkid /dev/sda1 查看文件系统卷标,文件系统类型(e2labal可以直接查看文件系统的标签)
/dev/sda1: UUID="b3585a93-fa57-4028-abf2-0832f930fc5f" TYPE="ext4"

[root@bogon ~]# tune2fs -L NIHAO /dev/sda1 增加标签
tune2fs 1.41.12 (17-May-2010)
[root@bogon ~]# blkid /dev/sda1
/dev/sda1: UUID="b3585a93-fa57-4028-abf2-0832f930fc5f" TYPE="ext4" LABEL="NIHAO"

查看文件系统详细信息:

[root@bogon ~]# tune2fs -l /dev/sda1 (文件系统的详细信息值得好好研究)
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name:   NIHAO
Last mounted on:          /boot
Filesystem UUID:          b3585a93-fa57-4028-abf2-0832f930fc5f
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              51200
Block count:              204800
Reserved block count:     10240
Free blocks:              171578
Free inodes:              51162
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      256
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Sun Dec  2 02:39:00 2012
Last mount time:          Wed Mar 13 20:01:41 2013
Last write time:          Thu Mar 14 20:24:26 2013
Mount count:              9
Maximum mount count:      -1
Last checked:             Sun Dec  2 02:39:00 2012
Check interval:           0 (<none>)
Lifetime writes:          25 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:              128
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      5a5c2014-c124-4db8-9596-6fa976119dc2
Journal backup:           inode blocks