文件系统的维护
A、ext2/ext3文件系统的优化与高级特性
B、磁盘检查
C、磁盘配额
D、自动挂载分区
                                          优化Ext2/Ext3文件系统
文件的存放形式,可以根据文件的大小来分配块的大小。
如一个分区,主要是存放小的文件,文件大小为3K的,那么我们可以将此分区以1K的大小划分块的大小,这样只分配给此文件3个模块即可。如果是以4K 的大小来划分一个块的话,一个3K大小的文件就浪费了3/4的空间,即分配给它一个4K大小的块,但仅存放了3K大小的文件,有1K的大小浪费。。所以可以根据硬盘里存放的文件类型的大小尺寸来决定到底使用多大的数据块(Block size)常用的有三种块大小:1024、2048和4096
例: #f disk /dev/sdb
# mkfs.ext3 –b 1024 /dev/sdb1
# mkfs.ext3 –b 4096 /dev/sdb4
# mount /dev/sdb1 /mnt/d1
# mount /dev/sdb4 /mnt/d2
# mkdir /mnt/d1/dir
# mkdir /mnt/d2/dir
# echo “hi”>/mnt/d1/dir/test
# echo “hi”>/mnt/d2/dir/test
[root@localhost root]# ls -lh /mnt/d[1-2]/dir
/mnt/d1:
total 13K
drwxr-xr-x    3 root     root         1.0K Mar 12 15:14 dir
drwx------    2 root     root          12K Mar 12 15:13 lost+found
/mnt/d1:
total 20K
drwxr-xr-x    3 root     root         4.0K Mar 12 15:14 dir
drwx------    2 root     root          16K Mar 12 15:13 lost+found
# ls –lh /mnt/d[1-2]/dir/test
[root@localhost root]# ls -lh /mnt/d[12]/dir/test
-rw-r--r--    1 root     root            3 Mar 12 15:20 /mnt/d1/dir/test
-rw-r--r--    1 root     root            3 Mar 12 15:20 /mnt/d2/dir/test
[root@localhost root]# du -sh /mnt/d[12]/dir
2.0K    /mnt/b1/dir
8.0K    /mnt/c1/dir  <----------------------浪费磁盘空间
文件索引区(index)的优化
将文件的索引节点由2个合并成一个以提高一点访问的速度
# mkfs.ext3 –b 4096 –i 4096 /dev/sda2
例:# mkfs.ext3 –b 4096 –i 4096 /dev/sdb1
     # mkfs.ext3 –b 4096 –i 8192 /dev/sdb4
# tune2fs –l /dev/sdb1 |more
[root@localhost root]# tune2fs -l /dev/sdb1
tune2fs 1.32 (09-Nov-2002)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          4a81dac9-2f55-4393-99bd-36d82a6aa1bd
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal filetype sparse_super
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              548352   <--------- 1
Block count:              548218    <--------- 1  <两者之比接近1:1 比较适合存放小文件>

Reserved block count:     27410
Free blocks:              522829
Free inodes:              548341
First block:              0
Block size:               4096
Fragment size:            4096
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         32256
Inode blocks per group:   1008
[root@localhost root]# tune2fs -l /dev/sdb4
tune2fs 1.32 (09-Nov-2002)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          323807f2-9f40-4706-82a6-02a5083ef69b
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal filetype sparse_super
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              274176   <------------ 1
Block count:              548218    <------------ 2 <两者之比接近1:2 比较适合存放大文件>

Reserved block count:     27410
Free blocks:              531397
Free inodes:              274165
First block:              0
Block size:               4096
Fragment size:            4096
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16128
Inode blocks per group:   504
Filesystem created:       Thu Mar 12 16:26:04 2009
Last mount time:          n/a
Last write time:          Thu Mar 12 16:26:04 2009
Mount count:              0
Maximum mount count:      29
Last checked:             Thu Mar 12 16:26:04 2009
Check interval:           15552000 (6 months)
Next check after:         Tue Sep  8 16:26:04 2009
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               128
Journal UUID:             <none>
Journal inode:            8
Journal device:           0x0000
First orphan inode:       0
保留块:为管理员保留的磁盘管理空间,默认为总数据块的5%
用法:mkfs.ext3 –b 4096 –i 8192 –m /dev/sda2 设置保留块的数量占总数量的2%
如:# mkfs.ext3 –b 4096 –i8192 –m 5 /dev/sdb1
[root@localhost root]# tune2fs -l /dev/sdb1 |grep Reserved
Reserved block count:     27410
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
[root@localhost root]# tune2fs -l /dev/sdb1
tune2fs 1.32 (09-Nov-2002)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          5ae1c6e2-93b9-4775-b575-abc3d48f588e
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal filetype sparse_super
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              274176
Block count:              548218
Reserved block count:     27410    <------------27410/548218 ~~=5%约等于5%

Free blocks:              531397
Free inodes:              274165
First block:              0
Block size:               4096
Fragment size:            4096
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16128
Inode blocks per group:   504
[root@localhost root]# tune2fs -l /dev/sdb1 |grep count
Inode count:              274176
Block count:              548218
Reserved block count:     27410
Mount count:              0
Maximum mount count:      28
[root@localhost root]# tune2fs -l /dev/sdb1 |grep Reserved
Reserved block count:     27410
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

[root@localhost root]# mkfs.ext3 -b 4096 -i 8192 -m 2 /dev/sdb1
[root@localhost root]# tune2fs -l /dev/sdb1 |grep Reserved
Reserved block count:     10964
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
#df –lh
#df –l
                                         调整Ext2/Ext3文件系统
1)、tune2fs:调整ext2/ext3文件系统特性的工具
      -l <device 设备>   查看文件系统信息
               -c  <count 数量> 设置挂载时硬盘强制自检的次数
               -i   <n day 天数> 设置强制自检的间隔时间
              -m  <percentage 百分比> 保留块的百分比
              -j   <journal 日志> 将ext2文件系统转换成ext3的文件格式(Ext3比Ext3增加了日志的功能)
                文件系统检查工具
a)、fsck  <------------检查文件系统完整性工具
用法一:fsck –t ext2 /dev/sdb1
用法二:fsck.ext2 /dev/sdb1
b)、e2fsck 检查ext2/ext3文件系统的工具 (建议不要采用此工具进行检查)
例:# tune2fs –l /dev/sdb1 |grep mount
[root@localhost root]# tune2fs -l /dev/sdb1
tune2fs 1.32 (09-Nov-2002)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          c6bfdc65-1053-4523-b15c-1cf4223b7a7d
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal filetype sparse_super
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              274176
Block count:              548218
Reserved block count:     10964
Free blocks:              531397
Free inodes:              274165
First block:              0
Block size:               4096
Fragment size:            4096
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16128
Inode blocks per group:   504
Filesystem created:       Thu Mar 12 16:42:36 2009
Last mount time:          n/a
Last write time:          Thu Mar 12 16:42:37 2009
Mount count:              0
Maximum mount count:      34
[root@localhost root]# mount /dev/sdb1 /mnt/b1/
[root@localhost root]# tune2fs -l /dev/sdb1
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              274176
Block count:              548218
Reserved block count:     10964
Free blocks:              531397
Free inodes:              274165
First block:              0
Block size:               4096
Fragment size:            4096
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16128
Inode blocks per group:   504
Filesystem created:       Thu Mar 12 16:42:36 2009
Last mount time:          Thu Mar 12 18:35:13 2009
Last write time:          Thu Mar 12 18:35:13 2009
Mount count:              1
Maximum mount count:      34

(当挂载次数达到最大的次数限制时,分区会强制进行自检)
[root@localhost root]# umount /dev/sdb1
[root@localhost root]# tune2fs -c -1 /dev/sdb1
tune2fs 1.32 (09-Nov-2002)
Setting maximal mount count to –1 <将最大挂载次数设为-1,这样此文件系统永不会自检>
#umount /dev/sdb1
[root@localhost root]# tune2fs -l /dev/sdb1 |grep interval
Check interval:           15552000 (6 months)
[root@localhost root]# tune2fs -c -1 -i 0 /dev/sdb1  <---这样就不会自检,如果想自检,可手工运行命令进行自检。
tune2fs 1.32 (09-Nov-2002)
Setting maximal mount count to -1
Setting interval between check 0 seconds
[root@localhost root]# tune2fs -m 10 /dev/sdb1  <--------设置保留块为10%
tune2fs 1.32 (09-Nov-2002)
Setting reserved blocks percentage to 10 (54820 blocks)
[root@localhost root]# tune2fs -l /dev/sdb1 |grep -i "Reserved"
Reserved block count:     54820
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
例子:# mkfs.ext2 /dev/sdc1
# mount /dev/sdc1 /mnt/c1
[root@localhost root]# df –T  (分区类型)
Filesystem    Type      1K-blocks       Used         Available      Use%     Mounted on
/dev/sda1     ext3       5154852         1127532   3765464          24%         /
none            tmpfs       79152           0             79152            0%         /dev/shm
/dev/sdc1     ext2       2158416          20          2048756          1%       /mnt/c1
[root@localhost root]# cp /etc/services /mnt/c1
[root@localhost root]# ls /mnt/c1
lost+found  services
[root@localhost root]# tune2fs -j /dev/sdc1
tune2fs 1.32 (09-Nov-2002)
Creating journal inode: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost root]# umount /dev/sdc1
[root@localhost root]# mount /dev/sdc1 /mnt/c1
[root@localhost root]# ls /mnt/c1
lost+found  services
[root@localhost root]# df –T  查看分区类型
Filesystem     Type      1K-blocks     Used          Available    Use%   Mounted on
/dev/sda1     ext3       5154852      1127532      3765464     24%       /
none            tmpfs       79152         0               79152         0%     /dev/shm
/dev/sdc1     ext3       2158416     32844         2015932        2%    /mnt/c1
[root@localhost root]# tune2fs -l /dev/sdc1 |grep features
Filesystem features:      has_journal filetype needs_recovery sparse_super   <----------已经添加了日志功能
Ext2文件系统与Ext3文件系统的区别就是:Ext3比Ext2多了日志功能,ext2可以通过tune2fs –j 加上日志功能,变成Ext3文件系统,但是Ext3 不能再次转换成Ext2文件系统。
自检工具:fsck 在使用fsck命令自检文件系统的时候,要看清楚是哪一种文件系统的文件(Ext2还是Ext3),不要用错参数。
# fsck.ext2 /dev/sdb4 
# fsck.ext3 –y /dev/sdc1   <----加入 -y 参数表示自动修复,不用确认。

0

收藏

leekwen

18篇文章,2W+人气,0粉丝

Ctrl+Enter 发布

发布

取消

推荐专栏更多

5353379fc95da1d7d34fd243b9ace17f.jpg
全局视角看大型园区网

路由交换+安全+无线+优化+运维

共40章 | 51CTO夏杰
¥51.00 1683人订阅
45862f289339dc922ffda669fd74ad9b.jpg
网工2.0晋级攻略 ——零基础入门Python/Ansible

网络工程师2.0进阶指南

共30章 | 姜汁啤酒
¥51.00 1567人订阅
a940c66317ecbe58436a2ad3831c2d7d.png
基于Python的DevOps实战

自动化运维开发新概念

共20章 | 抚琴煮酒
¥51.00 430人订阅
629650e188ddde78b213e564c2e9ebff.jpg
负载均衡高手炼成记

高并发架构之路

共15章 | sery
¥51.00 507人订阅
dc6736c5fd50474b5df8b76b040e3d03.jpg
带你玩转高可用

前百度高级工程师的架构高可用实战

共15章 | 曹林华
¥51.00 462人订阅
f92360e227f9d91cdff7ea95120630ef.png
left-qr.jpg

扫一扫,领取大礼包

0

1
分享
qr-url?url=https%3A%2F%2Fblog.51cto.com%2Fleekwen%2F181894
leekwen
noavatar_middle.gif