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

Ubuntu 20.4.1LVM空间扩容 - 图1

Ubuntu 20.4.1LVM空间扩容 - 图2

一、扩容LVM空间

添加硬盘

  1. # 将剩余硬盘空间添加到新分区
  2. root@lixu:/home/lixu# fdisk /dev/sda
  3. Welcome to fdisk (util-linux 2.34).
  4. Changes will remain in memory only, until you decide to write them.
  5. Be careful before using the write command.
  6. GPT PMBR size mismatch (41943039 != 209715199) will be corrected by write.
  7. Command (m for help): n #输入“n“创建新硬盘,剩下保持默认
  8. Partition number (4-128, default 4):
  9. First sector (41940992-209715166, default 41940992):
  10. Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-209715166, default 209715166):
  11. Created a new partition 4 of type 'Linux filesystem' and of size 80 GiB.
  12. Command (m for help): w #保存并退出
  13. The partition table has been altered.
  14. Syncing disks.
  1. root@lixu:/home/lixu# partprobe # 刷新下分区状态

将硬盘添加到VG

  1. # 扩展硬盘分区添加到VG
  2. root@lixu:/home/lixu# vgextend /dev/ubuntu-vg /dev//sda4
  3. Physical volume "/dev//sda4" successfully created.
  4. Volume group "ubuntu-vg" successfully extended

扩容LV

  1. # 将VG剩余空间添加到LV
  2. root@lixu:/home/lixu# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  3. Size of logical volume ubuntu-vg/ubuntu-lv changed from <19.00 GiB (4863 extents) to 98.99 GiB (25342 extents).
  4. Logical volume ubuntu-vg/ubuntu-lv successfully resized.
  1. # 刷新分区状态
  2. root@lixu:/home/lixu# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
  3. resize2fs 1.45.5 (07-Jan-2020)
  4. Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
  5. old_desc_blocks = 3, new_desc_blocks = 13
  6. The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 25950208 (4k) blocks long.
  1. root@lixu:/home/lixu# fdisk -l #查看分区
  2. Disk /dev/loop0: 54.98 MiB, 57626624 bytes, 112552 sectors
  3. Units: sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk /dev/loop1: 71.28 MiB, 74735616 bytes, 145968 sectors
  7. Units: sectors of 1 * 512 = 512 bytes
  8. Sector size (logical/physical): 512 bytes / 512 bytes
  9. I/O size (minimum/optimal): 512 bytes / 512 bytes
  10. Disk /dev/loop2: 29.9 MiB, 31334400 bytes, 61200 sectors
  11. Units: sectors of 1 * 512 = 512 bytes
  12. Sector size (logical/physical): 512 bytes / 512 bytes
  13. I/O size (minimum/optimal): 512 bytes / 512 bytes
  14. Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
  15. Disk model: VMware Virtual S
  16. Units: sectors of 1 * 512 = 512 bytes
  17. Sector size (logical/physical): 512 bytes / 512 bytes
  18. I/O size (minimum/optimal): 512 bytes / 512 bytes
  19. Disklabel type: gpt
  20. Disk identifier: 8DD9EF68-48C7-441A-81BD-40E0953D853B
  21. Device Start End Sectors Size Type
  22. /dev/sda1 2048 4095 2048 1M BIOS boot
  23. /dev/sda2 4096 2101247 2097152 1G Linux filesystem
  24. /dev/sda3 2101248 41940991 39839744 19G Linux filesystem
  25. /dev/sda4 41940992 209715166 167774175 80G Linux filesystem
  26. Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 98.102 GiB, 106292051968 bytes, 207601664 sectors
  27. Units: sectors of 1 * 512 = 512 bytes
  28. Sector size (logical/physical): 512 bytes / 512 bytes
  29. I/O size (minimum/optimal): 512 bytes / 512 bytes