How to extend disk space in lvm on Ubuntu

Before, I allocated 64G of my 128 SSD to lvm when installing Ubuntu server, now I need more disk space. So I learn and extend my lvm space on Ubuntu today. Now let me share with you how to do it.

Log in your Ubuntu server as root.

1
lvdisplay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID iT1JD2-k2is-5rA3-bDF6-jWeZ-VFmc-ra0Lqg
LV Write Access read/write
LV Creation host, time ubuntu-server, 2022-11-27 18:25:54 +0800
LV Status available
# open 1
LV Size <116.19 GiB
Current LE 29744
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

There you will find your LV path, which is needed in next step.

1
2
3
4
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv # you need to use your own LV path.
resize2fs /dev/ubuntu-vg/ubuntu-lv # use this if you use ext4 same with me. you can use df -T to check it.
lvs # to check whether it takes effect
df -h # to check whether it takes effect

Reference

  1. https://cloud.tencent.com/developer/article/1965711