从下面两张图中可以看出,硬盘有100G,但是LVM的虚拟磁盘只分配了19G,硬盘大约还有80G的空间未使用


一、扩容LVM空间
添加硬盘
# 将剩余硬盘空间添加到新分区root@lixu:/home/lixu# fdisk /dev/sdaWelcome 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
# 扩展硬盘分区添加到VGroot@lixu:/home/lixu# vgextend /dev/ubuntu-vg /dev//sda4Physical volume "/dev//sda4" successfully created.Volume group "ubuntu-vg" successfully extended
扩容LV
# 将VG剩余空间添加到LVroot@lixu:/home/lixu# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lvSize 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--lvresize2fs 1.45.5 (07-Jan-2020)Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing requiredold_desc_blocks = 3, new_desc_blocks = 13The 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 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop1: 71.28 MiB, 74735616 bytes, 145968 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop2: 29.9 MiB, 31334400 bytes, 61200 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectorsDisk model: VMware Virtual SUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 8DD9EF68-48C7-441A-81BD-40E0953D853BDevice 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 filesystemDisk /dev/mapper/ubuntu--vg-ubuntu--lv: 98.102 GiB, 106292051968 bytes, 207601664 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
