CentOS 7 LVM 调整分区大小

需求:

分区格式调整前调整后
centos-rootext45G19.5G
centos-homeext434.5G20G

特别注意的是:

  • resize2fs:针对的是ext2、ext3、ext4文件系统(增大和减小都支持)
  • xfs_growfs:针对的是xfs文件系统(只支持增大)
一、缩减 centos-home

先缩减逻辑卷的逻缉边界,再缩减物理边界 

1、查看挂载

[root@10-3-0-229 ~]# df -Th

# 显示
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root ext4      4.8G  1.3G  3.4G  27% /
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                   tmpfs     3.9G  8.6M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1               ext4      477M  114M  334M  26% /boot
/dev/mapper/centos-home ext4       34G   49M   33G   1% /home
tmpfs                   tmpfs     783M     0  783M   0% /run/user/0

2、因为不能在线缩减,所以先卸载 home 目录

umount /home

3、检查文件

# 在缩减之前应该先强行检查文件,以确保文件系统处于一致性状态
[root@10-3-0-229 ~]# e2fsck -f /dev/mapper/centos-home

# 显示
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/centos-home: 12/2260992 files (0.0% non-contiguous), 186999/9043968 blocks

4、缩减 逻辑边界

# 调整 centos-home 逻辑边界大小为20G
[root@10-3-0-229 ~]# resize2fs -p /dev/mapper/centos-home 20G

# 显示
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/centos-home to 5242880 (4k) blocks.
Begin pass 3 (max = 276)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/centos-home is now 5242880 blocks long.

5、缩减 物理边界

# 缩减 centos-home 物理边界大小为 20G
[root@10-3-0-229 ~]# lvreduce -L 20G /dev/mapper/centos-home

# 显示
  WARNING: Reducing active logical volume to 20.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 34.50 GiB (8832 extents) to 20.00 GiB (5120 extents).
  Logical volume centos/home successfully resized.

6、重新挂载回来

[root@10-3-0-229 ~]# mount /home

7、查看卷组的可用空间大小

# 查看可用空间大小
[root@10-3-0-229 ~]# vgdisplay

# 显示
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               39.50 GiB
  PE Size               4.00 MiB
  Total PE              10112
  Alloc PE / Size       6400 / 25.00 GiB
  Free  PE / Size       3712 / 14.50 GiB    # 可用空间
  VG UUID               cTaSHz-1w8P-nk5Y-cre1-fq1p-3NMH-jJTEoi
二、扩展 centos-root

先扩展逻辑卷的物理边界,再扩展逻缉边界

1、扩展 物理边界

# 为 centos-root 扩展 14.5G 物理边界
[root@10-3-0-229 ~]# lvextend -L +14.5G /dev/mapper/centos-root

# 显示
  Size of logical volume centos/root changed from 5.00 GiB (3712 extents) to 19.50 GiB (4992 extents).
  Logical volume centos/root successfully resized.

2、扩展 逻辑边界

# 扩展 centos-root 逻辑边界和物理边界一样大
[root@10-3-0-229 ~]# resize2fs -p /dev/mapper/centos-root

# 显示
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/centos-root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/mapper/centos-root is now 5111808 blocks long.

3、查看调整后的大小

# 查看调整后的分区大小 centos-root 分区已完成扩容
[root@10-3-0-229 ~]# df -Th

# 显示
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root ext4       20G  1.3G   18G   7% /
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                   tmpfs     3.9G  8.6M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda1               ext4      477M  114M  334M  26% /boot
tmpfs                   tmpfs     783M     0  783M   0% /run/user/0
/dev/mapper/centos-home ext4       20G   45M   19G   1% /home
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值