LVM扩容
LVM扩容
背景:
做了LVM的磁盘,现在新加一块硬盘,并扩容根分区。
查看硬盘状况
[root@localhost jumpserver]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
磁盘 /dev/sdb:8000.5 GB, 8000450330624 字节,15625879552 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):262144 字节 / 524288 字节
磁盘标签类型:gpt
Disk identifier: A205DD2F-9019-481D-AE5B-87ABCE955BB2
# Start End Size Type Name
1 2048 6143 2M BIOS boot
2 6144 1030143 500M Microsoft basic
3 1030144 15625877503 7.3T Linux LVM
磁盘 /dev/sda:4000.8 GB, 4000787030016 字节,7814037168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-root:7965.6 GB, 7965557915648 字节,15557730304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):262144 字节 / 524288 字节
磁盘 /dev/mapper/centos-swap:34.4 GB, 34359738368 字节,67108864 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):262144 字节 / 524288 字节
可以看到/dev/sda
就是新加的硬盘
创建PV
[root@localhost jumpserver]# pvcreate /dev/sda
Physical volume "/dev/sda" successfully created.
查看PV
[root@localhost jumpserver]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb3
VG Name centos
PV Size <7.28 TiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 1907329
Free PE 0
Allocated PE 1907329
PV UUID amX22C-ehmp-YiZj-zaRd-jdnG-kqOM-Guzhd3
"/dev/sda" is a new physical volume of "<3.64 TiB"
--- NEW Physical volume ---
PV Name /dev/sda
VG Name
PV Size <3.64 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1j6Ana-TNqG-xPpF-zHVf-lxSS-opoz-LmaVJU
PV加入VG组
先查看现有VG组
[root@localhost jumpserver]# vgdisplay
--- Volume group ---
VG Name centos # VG组名后面需要用到
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <7.28 TiB
PE Size 4.00 MiB
Total PE 1907329
Alloc PE / Size 1907329 / <7.28 TiB
Free PE / Size 0 / 0
VG UUID b38igr-UBJB-IBJk-1WxY-u9Z8-CsQw-djIsws
将/dev/sda
添加到VG组里
[root@localhost jumpserver]# vgextend centos /dev/sda
Volume group "centos" successfully extended
再次查看:
[root@localhost jumpserver]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 10.91 TiB
PE Size 4.00 MiB
Total PE 2861190
Alloc PE / Size 1907329 / <7.28 TiB
Free PE / Size 953861 / <3.64 TiB # 这里是增加的容量
VG UUID b38igr-UBJB-IBJk-1WxY-u9Z8-CsQw-djIsws
扩容LV
将新的VG(Free PE)添加至LV;
运行完可再次查看vgdisplay 正常情况下Free会见少;
按free PE的百分比添加:
lvextend -l +100%FREE /dev/mapper/centos-root
按指定大小添加;
lvextend -L +4000G /dev/mapper/centos-root
这里我们采用百分比添加:
[root@localhost jumpserver]# lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from 7.24 TiB (1899137 extents) to 10.88 TiB (2852998 extents).
Logical volume centos/root successfully resized.
重载分区
centos7 默认使用xfs文件系统
[root@localhost jumpserver]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=32, agsize=60772416 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1944716288, imaxpct=5
= sunit=64 swidth=128 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=521728, version=2
= sectsz=512 sunit=64 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1944716288 to 2921469952
查看容量变化
[root@localhost jumpserver]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 19M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/centos-root 11T 9.6G 11T 1% /
/dev/sdb2 492M 187M 305M 38% /boot
tmpfs 6.3G 0 6.3G 0% /run/user/0
tmpfs 6.3G 0 6.3G 0% /run/user/1001
overlay 11T 9.6G 11T 1% /var/lib/docker/overlay2/a04692799c75fce974f541f798f9dae46ebe6410bc5b3fe9601f54dc56123d4b/merged