1.增加硬盘容量,虚拟机关闭情况下,通过工具扩充磁盘容量
2.fdisk /dev/sda #进入分区界面
输入n #新建一个分区
回车默认 #分区号
回车默认 #设置起始分区地址
回车默认 #设置大小
输入w #保存
sudo partx -u /dev/sda #创建完成,刷新分区
3.创建物理卷
root@ubuntu03:~# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
4.查看卷组
root@ubuntu03:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
...
5.把创建的物理卷加入卷组
root@ubuntu:~# vgextend ubuntu-vg /dev/sda4 加入卷组
Volume group "ubuntu-vg" successfully extended
6.查看扩容的文件路径
root@ubuntu03:~# df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 197M 1.2M 196M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 12G 8.4G 2.3G 79% /
tmpfs tmpfs 982M 0 982M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 ext4 2.0G 251M 1.6G 14% /boot
tmpfs tmpfs 197M 4.0K 197M 1% /run/user/0
7.把卷组剩余内存容量加到扩容的文件系统上,我这里是 /dev/mapper/ubuntu--vg-ubuntu--lv
root@ubuntu03:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <11.50 GiB (2943 extents) to 37.99 GiB (9726 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
8.刷新逻辑卷
root@ubuntu03:~# 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 = 2, new_desc_blocks = 5
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 9959424 (4k) blocks long.
9.df -Th 查看内存情况,已成功扩容。
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 197M 1.2M 196M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 38G 8.4G 28G 24% /
tmpfs tmpfs 982M 0 982M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 ext4 2.0G 251M 1.6G 14% /boot
tmpfs tmpfs 197M 4.0K 197M 1% /run/user/0