[20170926]tune2fs调整保留块百分比.txt
--//今天春节后给生产系统dg增加磁盘空间,在建立文件系统时没有调整保留区百分比.
--//当时想都建立文件系统,也开始转移文件了.再重新来非常麻烦.也就放弃了.
--//正好前一段时间使用tune2fs修改文件系统参数,
--//参考链接
--//[20141229]关于linux文件系统的一些问题.txt
--//主要问题是linux服务器长期不重启,有几种情况会导致重启在fsck上浪费许多时间.
# tune2fs -l /dev/mapper/vg_gxqyy-lv_home
tune2fs 1.41.12 (17-May-2010)
...
Block count: 106288128
Reserved block count: 5314406
...
Maximum mount count: 23
Last checked: Wed Sep 24 13:05:12 2014
Check interval: 15552000 (6 months)
Next check after: Mon Mar 23 13:05:12 2015
--//可以发现最大安装次数23次,如果达到这个次数,下次启动要扫描文件系统.
--//检查interval设置6个月,也就是Mon Mar 23 13:05:12 2015后如果启动机器,会自动调用fsck检查文件系统.
Check interval: 15552000 (6 months)
Next check after: Mon Mar 23 13:05:12 2015
--//发现Reserved block count也显示出来,感觉应该可以使用tune2fs修改这个参数.
--//自己做一个测试看看:
1.首先说明为什么要这样做:
--//现在磁盘都很大,基本都是百G,如果1T的磁盘,Reserved block保留5%(缺省值),这样1T空间就有50G磁盘空间浪费.
--//实际上保留1%已经足够,这样10G也是很大的磁盘空间.实际上这个区在磁盘空间满的情况,留给root用户可以写入的.
--//如果建立文件系统使用mkfs.ext3 -m指定保留区百分比.
--//如果已经建立文件系统了,可以使用tune2fs调整.
2.测试:
# dd if=/dev/zero of=100m bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.272268 seconds, 385 MB/s
--//注:bs=1M,M要大写.
# mkfs.ext3 100m
mke2fs 1.39 (29-May-2006)
100m is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
--//注意看提示:This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use
--//tune2fs -c or -i to override.缺省38次,180天.
# tune2fs -l 100m
tune2fs 1.39 (29-May-2006)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 9e470cdc-18d6-43f2-82af-70a3c1d9e9a7
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal resize_inode dir_index filetype sparse_super
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 25688
Block count: 102400
Reserved block count: 5120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free blocks: 93486
Free inodes: 25677
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 1976
Inode blocks per group: 247
Filesystem created: Tue Sep 26 09:13:20 2017
Last mount time: n/a
Last write time: Tue Sep 26 09:13:20 2017
Mount count: 0
Maximum mount count: 38
Last checked: Tue Sep 26 09:13:20 2017
Check interval: 15552000 (6 months)
Next check after: Sun Mar 25 09:13:20 2018
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
Default directory hash: tea
Directory Hash Seed: 4dc137e2-6fcb-4393-92e1-ca030dd20108
Journal backup: inode blocks
--//我建立的文件系统块大小1K,Reserved block count: 5120.
# tune2fs -m 1 100m
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 1% (1024 blocks)
# tune2fs -l 100m | grep "Reserved block count"
Reserved block count: 1024
--//现在已经设置1M.
# tune2fs -l 100m | grep "Reserved block count"
Reserved block count: 0
--//看了man文档那个,也可以使用-r参数,指定Reserved block count数量.
-r reserved-blocks-count Set the number of reserved filesystem blocks.
# tune2fs -r 100 100m
tune2fs 1.39 (29-May-2006)
Setting reserved blocks count to 100
# tune2fs -l 100m | grep "Reserved block count"
Reserved block count: 100
3.测试看看:
# tune2fs -m 5 100m
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 5% (5120 blocks)
--//设置为缺省5%.
# mount -o loop 100m /mnt/backup/
# df | egrep "backup|File"
Filesystem Size Used Avail Use% Mounted on
/home/oracle/100m 97M 5.6M 87M 7% /mnt/backup
--//已经使用5.6M文件系统.
# dd if=/dev/zero of=/mnt/backup/96m bs=1M count=96
dd: writing `/mnt/backup/96m': No space left on device
91+0 records in
90+0 records out
95350784 bytes (95 MB) copied, 1.27471 seconds, 74.8 MB/s
--//可以发现仅仅建立91M的文件大小(不到),不要给后面的结果迷惑
--//95350784/1024/1024 = 90.93359375.
# tune2fs -m 1 100m
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 1% (1024 blocks)
# dd if=/dev/zero of=/mnt/backup/96m bs=1M count=96
dd: writing `/mnt/backup/96m': No space left on device
91+0 records in
90+0 records out
95350784 bytes (95 MB) copied, 1.30347 seconds, 73.2 MB/s
--//重新mount看看.
# umount /mnt/backup
# mount -o loop 100m /mnt/backup/
# df | egrep "backup|File"
Filesystem Size Used Avail Use% Mounted on
/home/oracle/100m 97M 5.6M 87M 7% /mnt/backup
--//嗯,无效.
# tune2fs -l 100m | grep "Reserved block count"
Reserved block count: 5120
--//看来mount状态下修改无效.
# umount /mnt/backup
# tune2fs -m 1 100m
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 1% (1024 blocks)
# mount -o loop 100m /mnt/backup/
# df | egrep "backup|File"
Filesystem Size Used Avail Use% Mounted on
/home/oracle/100m 97M 5.6M 91M 6% /mnt/backup
# dd if=/dev/zero of=/mnt/backup/96m bs=1M count=96
dd: writing `/mnt/backup/96m': No space left on device
91+0 records in
90+0 records out
95350784 bytes (95 MB) copied, 1.43205 seconds, 66.6 MB/s
--//噢,这个限制对root用户无效.也就是从avail 91M也可以看出空间变大.前面显示87M.
# mkdir /mnt/backup/test
# chown oracle:oinstall /mnt/backup/test
# chmod 777 /mnt/backup/test
$ dd if=/dev/zero of=/mnt/backup/test/96m bs=1M count=96
dd: writing `/mnt/backup/test/96m': No space left on device
90+0 records in
89+0 records out
94318592 bytes (94 MB) copied, 0.564504 seconds, 167 MB/s
--//oracle用户仅仅建立94318592字节.在(保留区1%的情况下).
# umount /mnt/backup
# tune2fs -m 5 100m
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 5% (5120 blocks)
# mount -o loop 100m /mnt/backup/
$ dd if=/dev/zero of=/mnt/backup/test/96m bs=1M count=96
dd: writing `/mnt/backup/test/96m': No space left on device
86+0 records in
85+0 records out
90157056 bytes (90 MB) copied, 0.528077 seconds, 171 MB/s
--//oracle用户仅仅建立90157056字节(大约85-86M).在(保留区5%的情况下).
4.总结:
--//可以在磁盘空间紧张的情况下,修改这个参数,腾出1点空间.但是要umount后修改才有效.
--//突然想起来如果调整Maximum mount count是否在mount状态下也无效.
--//在mount状态下执行:
# tune2fs -c 0 100m
tune2fs 1.39 (29-May-2006)
Setting maximal mount count to -1
# tune2fs -l 100m | grep "Maximum mount count:"
Maximum mount count: -1
# umount /mnt/backup
# tune2fs -l 100m | grep "Maximum mount count:"
Maximum mount count: 38
--//在mount状态下修改无效,这点在工作中注意,这样我前面的修改是无效的.^_^.
--//实际上还是在前期要做好这些工作,也就是要做好相关知识的储备,这样不至于后期操作,减少一些不必要的维护以及错误.