Extend Linux Lvm(Short)
How to extend a Linux LVM
-
Add more disk space to the VM
Do this by expanding the virtual disk of the VM in your hypervisor (kvm/esx/hyper-v)
Reboot the vm if the vm/hypervisor don’t support “hot add” of storage. -
Check the disk in the VM
Verify that the VM detected the expanded virtual disk with some free space by running:
sudo cfdisk
If the disk size isn’t showing, run:
sudo echo 1>/sys/class/block/sda/device/rescanandsudo cfdiskagain. -
Resize the disk
Move the cursor to the last device in the list and choose
RESIZEand hit enter, then move toWRITEand hit enter again. Typeyesto confirm the change and then chooseQUIT
-
Resize LVM partition
pvdisplayto get info about free space.
Typesudo pvresize /dev/sda3to expand the LVM partition -
Show info about the Volume Group
Type
sudo vgdisplayand find the free space
-
Extend the logical volume by 10GB
Get the free space by typing
sudo lvdisplay
sudo lvextend -L+10G /dev/ubuntu-vg/ubuntu-lvor
sudo lvextend -l+100%FREE /dev/ubuntu-vg/ubuntu-lvto extend all space.Another
sudo lvdisplayshould show the new size. -
Resize the Logical Volume
Run
df -hto get the filsystem name. And then:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Run another
df -hto confirm the expanded space