LVM的安装和LVM的在线增大比较简单,LVM的分区离线缩小坑较多
要缩小LVM设备为/dev/mapper/test-lv_test 的大小为200M
第一步:卸载设备(减小文件系统时需要卸载,文件系统和resize工具都不支持在线减小。)
umount /dev/mapper/test-lv_test
第二步:执行文件系统检查(先检查一下分区的完整性。)
fsck -f /dev/mapper/test-lv_test
第三步:调整文件系统大小(将文件系统减小到200M)
resize2fs /dev/mapper/test-lv_test 200M
第四步:缩小分区
lvreduce -L 200M /dev/mapper/test-lv_test 将分区缩小到200M
PS:参数:-200M 缩小了200M,参数:200M 缩小到200M
[root@master ~]# mkfs.ext3 /dev/mapper/test-lv_test
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@master ~]# mount /dev/mapper/test-lv_test /aas/
1.lvm在线扩展200M的磁盘使用空间
[root@master aas]# lvextend -L +200M /dev/mapper/test-lv_test
Extending logical volume lv_test to 700.00 MiB
Logical volume lv_test successfully resized
出现这个successfully关键词代表成功扩大了空间
然后用df命令查看空间增大后的情况
[root@master aas]# df -h /dev/mapper/test-lv_test
2.用resize2fs命令刷新新建lv的大小
[root@master aas]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/test-lv_test is mounted on /aas; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/test-lv_test to 716800 (1k) blocks.
The filesystem on /dev/mapper/test-lv_test is now 716800 blocks long.
[root@master aas]# df -h /dev/mapper/test-lv_test
二.LVM离线减少分区大小的步骤
步骤严谨中间漏掉会报错:坏块,比较难修复,需要将大小恢复后再格式化
用df命令查看下磁盘使用情况
[root@master /]# umount /dev/mapper/test-lv_test
[root@master /]#
[root@master /]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-lv_test: 12/178816 files (0.0% non-contiguous), 33358/716800 blocks
[root@master /]#
[root@master /]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-lv_test: 12/178816 files (0.0% non-contiguous), 33358/716800 blocks
[root@master /]# resize2fs /dev/mapper/test-lv_test 200M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/test-lv_test to 204800 (1k) blocks.
The filesystem on /dev/mapper/test-lv_test is now 204800 blocks long.
[root@master /]# lvreduce -L 200M /dev/mapper/test-lv_test
WARNING: Reducing active logical volume to 200.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 200.00 MiB
Logical volume lv_test successfully resized
[root@master /]# mount /dev/mapper/test-lv_test /aas/
用df命令查看下磁盘使用情况
错误案例:
不按照步骤进行,看似成功减小实际并没有,因为没有写入文件系统4
resize2fs该命令执行报错,则未写入到文件系统中
用df命令查看下磁盘使用情况
[root@master /]# umount /aas/
[root@master /]# lvreduce -L -500M /dev/mapper/test-lv_test
WARNING: Reducing active logical volume to 724.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 724.00 MiB
Logical volume lv_test successfully resized
至此缩小分区出错,导致文件系统出现坏块,需要执行文件系统检查
[root@master /]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
请先运行 'e2fsck -f /dev/mapper/test-lv_test'.
这里检查出来节点不对,但是修复不了,需要后面自己增大空间
[root@master /]# e2fsck -f /dev/mapper/test-lv_test
e2fsck 1.41.12 (17-May-2010)
The 文件系统 size (according to the 超级块) is 1253376 块s
The physical size of the 设备 is 741376 块s
Either the 超级块 or the partition table is likely to be corrupt!
中断
第一步: 检查inode,块,和大小
Error reading block 745475 (无效的参数) while getting next inode from scan. 忽略错误
强制覆盖
Error writing block 745475 (无效的参数) while getting next inode from scan. 忽略错误
Error reading block 745476 (无效的参数) while getting next inode from scan. 忽略错误
强制覆盖
Error reading block 745478 (无效的参数) while getting next inode from scan. 忽略错误
Error while scanning inodes (184912): Can't read next inode
e2fsck: 已中止
[root@master ~]#
修复的方法:
1.挂载,查看大小并没有减小
[root@master ~]# mount /dev/mapper/test-lv_test /aas/
用df命令查看下磁盘使用情况
2.按照错误步骤减小了多少,就增加回来
[root@master ~]# lvextend -L +500M /dev/mapper/test-lv_test
Extending logical volume lv_test to 1.20 GiB
Logical volume lv_test successfully resized
用df命令查看下磁盘使用情况
提示并没有修改文件系统,原大小没有更改
[root@master ~]# resize2fs /dev/mapper/test-lv_test
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 1253376 blocks long. Nothing to do!
按照正常缩小分区的步骤再来一遍即可
[root@master ~]# umount /dev/mapper/test-lv_test
[root@master ~]# fsck -f /dev/mapper/test-lv_test
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/test-lv_test: 12/310896 files (0.0% non-contiguous), 50246/1253376 blocks
[root@master ~]# resize2fs /dev/mapper/test-lv_test -500M
resize2fs 1.41.12 (17-May-2010)
resize2fs:无效选项 -- 5
Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size]
[root@master ~]# resize2fs /dev/mapper/test-lv_test 500M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/test-lv_test to 512000 (1k) blocks.
The filesystem on /dev/mapper/test-lv_test is now 512000 blocks long.
[root@master ~]# lvreduce -L -500M /dev/mapper/test-lv_test
WARNING: Reducing active logical volume to 724.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
Reducing logical volume lv_test to 724.00 MiB
Logical volume lv_test successfully resized
[root@master ~]# mount /dev/mapper/test-lv_test /aas/
用df命令查看下磁盘使用情况