Cenots7对lvm逻辑卷分区大小的调整
(针对xfs和ext4不同文件系统)
1.支持的文件系统类型
特别注意的是:
resize2fs命令
针对的是ext2、ext3、ext4文件系统
xfs_growfs命令
针对的是xfs文件系统
1.1 分区增大、减小命令介绍
1) ext2/ext3/ext4文件系统的调整命令是resize2fs(增大和减小都支持) lvextend -L 120G /dev/mapper/centos-home //增大至120G lvextend -L +20G /dev/mapper/centos-home //增加20G lvreduce -L 50G /dev/mapper/centos-home //减小至50G lvreduce -L -8G /dev/mapper/centos-home //减小8G resize2fs /dev/mapper/centos-home //执行调整 2) xfs文件系统的调整命令是xfs_growfs(只支持增大) lvextend -L 120G /dev/mapper/centos-home //增大至120G lvextend -L +20G /dev/mapper/centos-home //增加20G xfs_growfs /dev/mapper/centos-home //执行调整
2.
对分区进行增大
1) 将上面查到的空闲空间中的90G增减到/home分区上 [root@localhost ~]# lvextend -L +90G /dev/mapper/centos-home //或者使用-l参数(跟PE数量),即lvextend -l +25500 /dev/mapper/centos-home Size of logical volume centos/home changed from 628.00 GiB (160768 extents) to 718.00 GiB (183808 extents). Logical volume centos/home successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/centos-home meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=41156608 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=164626432, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=80384, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 164626432 to 188219392
3 对分区进行减小
虽然xfs文件系统只支持增加,不支持减少。但并不是说在xfs系统文件下不能减小,只是减小后,需要重新格式化才能挂载上。这样原来的数据就丢失了!
系统安装好后,发现home分区过大,想从home分区中拿出100G给/分区
[root@localhost ~]# df –hT [root@localhost ~]# umount /home/ #注意要先备份一下/home目录的重要资料 umount /home 如果提示无法卸载,则是有进程占用/home,使用如下命令来终止占用进程: [root@localhost ~]# fuser -m /home #即使没有占用,也最好执行一下 [root@localhost ~]# lvreduce -L -100G /dev/mapper/centos-home WARNING: Reducing active logical volume to 618.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce centos/home? [y/n]: y Size of logical volume centos/home changed from 718.00 GiB (183808 extents) to 618.00 GiB (158208 extents). Logical volume centos/home successfully resized.
3.1.
格式化 home 分区
[root@localhost ~]# mkfs.xfs /dev/mapper/centos-home –f
3.2.
挂载分区
[root@localhost ~]# mount /dev/mapper/centos-home /home/
进行查看
[root@localhost ~]
# df -hT
上面在重新格式的时候,也可以将这个格式化为ext4格式。
[root@localhost ~]# mkfs.ext4 /dev/mapper/centos-home
[root@localhost ~]# cat /etc/fstab //将home分区的开机挂载设置里的xfs改为ext4
3.3然后将上面从home分区拿出的100G放到/分区下
进行lvm 查看 [root@localhost ~]# vgdisplay [root@localhost ~]# lvextend -L +100G /dev/mapper/centos-root Size of logical volume centos/root changed from 205.00 GiB (52480 extents) to 305.00 GiB (78080 extents). Logical volume centos/root successfully resized. [root@localhost ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=256 agcount=5, agsize=13107200 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 spinodes=0 data = bsize=4096 blocks=53739520, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=25600, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 53739520 to 79953920
进行查看
[root@localhost ~]# df -hT
想法决定行动,行动决定结果。
成功是努力的结晶,只有努力才会有成功。