如何扩大ubuntu的ubuntu–vg-ubuntu–lv空间/虚拟分区

1 查看根分区空间:
root@ggc:/home/ggc# df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              1.5G  1.3M  1.5G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   98G   14G   80G  15% /
tmpfs                              7.5G  4.0K  7.5G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          2.0G  127M  1.7G   7% /boot
tmpfs                              1.5G  4.0K  1.5G   1% /run/user/1000
2 查看磁盘分区列表:
root@ggc:/home/ggc# fdisk -l
Disk /dev/loop0: 61.96 MiB, 64970752 bytes, 126896 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: 79.95 MiB, 83832832 bytes, 163736 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: 46.96 MiB, 49242112 bytes, 96176 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/loop3: 49.64 MiB, 52051968 bytes, 101664 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/loop4: 63.24 MiB, 66314240 bytes, 129520 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/loop5: 102.98 MiB, 107986944 bytes, 210912 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: 447.13 GiB, 480103981056 bytes, 937703088 sectors
Disk model: SanDisk SSD PLUS
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: F8CC8F99-71A8-449B-A116-9E3DB789FB3F

Device       Start       End   Sectors   Size Type
/dev/sda1     2048      4095      2048     1M BIOS boot
/dev/sda2     4096   4198399   4194304     2G Linux filesystem
/dev/sda3  4198400 937699327 933500928 445.1G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 100 GiB, 107374182400 bytes, 209715200 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
3 增加根分区:

(这里分配全部剩余空间)

root@ggc:/home/ggc# lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv 
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB (25600 extents) to 445.12 GiB (113952 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

*一些其它常用修改大小命令

lvextend -L 20G /dev/mapper/ubuntu–vg-ubuntu–lv //增大或减小至20G
lvextend -L +20G /dev/mapper/ubuntu–vg-ubuntu–lv //增加20G
lvreduce -L -20G /dev/mapper/ubuntu–vg-ubuntu–lv //减小20G
lvresize -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv //按百分比扩容
4 保存分区信息:
root@ggc:/home/ggc# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 56
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 116686848 (4k) blocks long.
5 查看lvm卷组的信息
root@ggc:/home/ggc# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  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               445.12 GiB
  PE Size               4.00 MiB
  Total PE              113952
  Alloc PE / Size       113952 / 445.12 GiB
  Free  PE / Size       0 / 0   
  VG UUID               4bkNc3-OcUT-NO9B-rNXa-aKfG-tJvO-aITcaT
6 再次查看根分区:
root@ggc:/home/ggc# df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              1.5G  1.3M  1.5G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  438G   14G  406G   4% /
tmpfs                              7.5G  4.0K  7.5G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          2.0G  127M  1.7G   7% /boot
tmpfs                              1.5G  4.0K  1.5G   1% /run/user/1000