从下面两张图中可以看出,硬盘有100G,但是LVM的虚拟磁盘只分配了19G,硬盘大约还有80G的空间未使用
一、扩容LVM空间
添加硬盘
# 将剩余硬盘空间添加到新分区
root@lixu:/home/lixu# fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (41943039 != 209715199) will be corrected by write.
Command (m for help): n #输入“n“创建新硬盘,剩下保持默认
Partition number (4-128, default 4):
First sector (41940992-209715166, default 41940992):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-209715166, default 209715166):
Created a new partition 4 of type 'Linux filesystem' and of size 80 GiB.
Command (m for help): w #保存并退出
The partition table has been altered.
Syncing disks.
root@lixu:/home/lixu# partprobe # 刷新下分区状态
将硬盘添加到VG
# 扩展硬盘分区添加到VG
root@lixu:/home/lixu# vgextend /dev/ubuntu-vg /dev//sda4
Physical volume "/dev//sda4" successfully created.
Volume group "ubuntu-vg" successfully extended
扩容LV
# 将VG剩余空间添加到LV
root@lixu:/home/lixu# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <19.00 GiB (4863 extents) to 98.99 GiB (25342 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
# 刷新分区状态
root@lixu:/home/lixu# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 25950208 (4k) blocks long.
root@lixu:/home/lixu# fdisk -l #查看分区
Disk /dev/loop0: 54.98 MiB, 57626624 bytes, 112552 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 71.28 MiB, 74735616 bytes, 145968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 29.9 MiB, 31334400 bytes, 61200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8DD9EF68-48C7-441A-81BD-40E0953D853B
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 41940991 39839744 19G Linux filesystem
/dev/sda4 41940992 209715166 167774175 80G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 98.102 GiB, 106292051968 bytes, 207601664 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes