Centos7 扩容LVM
参考资料
- 链接: centos LVM分区动态扩容.
- 链接: linux centos7扩容:创建新的PV VG LV以及新的挂载点.
- 链接: 详解centosLVM扩容.
- 链接:Centos 8系统ext4文件系统类型进行扩容缩容 (LVM)
步骤
- 扩容/分区所在的磁盘
- 扩容物理卷
- 扩容逻辑卷
- 扩容文件系统
当前情况
原有系统为虚拟机,有50G的磁盘
步骤1-扩容磁盘
扩容虚拟机/分区所在物理磁盘,步骤略。
参考我另一篇笔记: CentOS 7 扩展磁盘分区.
- 查看当前分区情况
[root@Centos7-2243 ~]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 8.9M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/centos_centos7--2243-root 49G 5.0G 45G 11% /
/dev/sda1 1014M 170M 845M 17% /boot
tmpfs 6.4G 0 6.4G 0% /run/user/0
[root@Centos7-2243 ~]# fdisk -l
磁盘 /dev/sda:107.4 GB, 107374182400 字节,209715200 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000bbcad
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 209715199 103808000 83 Linux
磁盘 /dev/mapper/centos_centos7--2243-root:52.6 GB, 52609155072 字节,102752256 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
步骤2-扩容物理卷
2.1 查看当前卷信息
- 查看物理卷
[root@Centos7-2243 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos_centos7-2243
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12543
Free PE 0
Allocated PE 12543
PV UUID 1qSjaL-Cl9V-PSzL-r7Iw-SCbv-7ASP-gUKQ2r
- 查看卷组
[root@Centos7-2243 ~]# vgdisplay
--- Volume group ---
VG Name centos_centos7-2243
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12543 / <49.00 GiB
Free PE / Size 0 / 0
VG UUID 23t3I9-wf6j-P9bl-Y3A0-UVhB-evJQ-8nqvXi
- 查看逻辑卷
[root@Centos7-2243 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos_centos7-2243/root
LV Name root
VG Name centos_centos7-2243
LV UUID Y9T54F-I4SF-c3sK-KHJw-65ze-dCXO-5XKkKA
LV Write Access read/write
LV Creation host, time centos7-2243, 2024-08-20 04:35:38 +0800
LV Status available
# open 1
LV Size <49.00 GiB
Current LE 12543
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
2.2 扩容物理卷
因此没有新增磁盘,所以直接扩容当前物理卷,无需加入卷组。
- 扩容物理卷
[root@Centos7-2243 ~]# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
- 查看扩容结果
[root@Centos7-2243 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos_centos7-2243
PV Size <99.00 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25343
Free PE 12800
Allocated PE 12543
PV UUID 1qSjaL-Cl9V-PSzL-r7Iw-SCbv-7ASP-gUKQ2r
步骤3-扩容逻辑卷
- 查看当前逻辑卷
[root@Centos7-2243 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos_centos7-2243/root
LV Name root
VG Name centos_centos7-2243
LV UUID Y9T54F-I4SF-c3sK-KHJw-65ze-dCXO-5XKkKA
LV Write Access read/write
LV Creation host, time centos7-2243, 2024-08-20 04:35:38 +0800
LV Status available
# open 1
LV Size <49.00 GiB
Current LE 12543
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
- 扩容逻辑卷
[root@Centos7-2243 ~]# lvextend -l +100%FREE /dev/centos_centos7-2243/root
Size of logical volume centos_centos7-2243/root changed from <49.00 GiB (12543 extents) to <99.00 GiB (25343 extents).
Logical volume centos_centos7-2243/root successfully resized.
步骤4-文件系统
- 查看当前文件系统
[root@Centos7-2243 ~]# df -hlT
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 9.0M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/centos_centos7--2243-root xfs 49G 5.0G 45G 11% /
/dev/sda1 xfs 1014M 170M 845M 17% /boot
tmpfs tmpfs 6.4G 0 6.4G 0% /run/user/0
- 扩容文件系统
# 如果是ext4文件系统 使用 resize2fs/dev/mapper/centos_centos7--2243-root
[root@Centos7-2243 ~]# xfs_growfs /dev/mapper/centos_centos7--2243-root
meta-data=/dev/mapper/centos_centos7--2243-root isize=512 agcount=4, agsize=3211008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=12844032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6271, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12844032 to 25951232
- 扩容后结果
[root@Centos7-2243 ~]# df -Thl
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 9.0M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/centos_centos7--2243-root xfs 99G 5.0G 95G 5% /
/dev/sda1 xfs 1014M 170M 845M 17% /boot
tmpfs tmpfs 6.4G 0 6.4G 0% /run/user/0