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/rescan
andsudo cfdisk
again. -
Resize the disk
Move the cursor to the last device in the list and choose
RESIZE
and hit enter, then move toWRITE
and hit enter again. Typeyes
to confirm the change and then chooseQUIT
-
Resize LVM partition
pvdisplay
to get info about free space.
Typesudo pvresize /dev/sda3
to expand the LVM partition -
Show info about the Volume Group
Type
sudo vgdisplay
and 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-lv
or
sudo lvextend -l+100%FREE /dev/ubuntu-vg/ubuntu-lv
to extend all space.Another
sudo lvdisplay
should show the new size. -
Resize the Logical Volume
Run
df -h
to get the filsystem name. And then:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Run another
df -h
to confirm the expanded space