信息采集
挂载点及扩容大小
确定挂载点,确定可扩容大小(比如本例 89G->890.7G)
$ lsblk
sda 8:0 0 893.8G 0 disk
├─sda1 8:1 0 1G 0 part /boot/efi
├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 890.7G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 89G 0 lvm /
扩容的文件系统类型
确定文件系统类型,这里可以通过type字段知道是ext4;
$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 26G 2.9M 26G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 89G - 89G - /
Volume Group
通过vgs、lvdisplay确定vg组信息;确认逻辑卷所在组正常,否则需要手动将lvm加入vg组管理;
$ vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz--n- <890.70g 0
$ lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID -
LV Write Access read/write
LV Creation host, time ubuntu-server, 2024-01-05 17:22:52 +0000
LV Status available
# open 1
LV Size <890.70 GiB
Current LE 228018
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 253:0
扩容
扩容LVM
$ lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
可以通过命令 lvdisplay /dev/mapper/ubuntu–vg-ubuntu–lv 查看发现由89G->890G;
但是df -Th 查看发现文件系统大小仍然没变;
$df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 26G 2.9M 26G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 98G 16G 78G 17% /
扩容文件系统
确定文件系统类型,这里可以通过type字段知道是ext4;
$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 26G 2.9M 26G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 89G - 89G - /
因为这里是ext4,所以
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
回测
查看扩容结果
$ df -h /dev/mapper/ubuntu--vg-ubuntu--lv
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 877G 16G 824G 2% /
扩展
如果是xfs,则是以下命令:
xfs_growfs /dev/mapper/ubuntu--vg-ubuntu--lv