Extend Linux Lvm(Short)

How to extend a Linux LVM

  1. 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.

  2. Check the disk in the VM

    Verify that the VM detected the expanded virtual disk with some free space by running: sudo cfdisk

    Disk size

    If the disk size isn’t showing, run: sudo echo 1>/sys/class/block/sda/device/rescan and sudo cfdiskagain.

  3. Resize the disk

    Move the cursor to the last device in the list and choose RESIZE and hit enter, then move to WRITE and hit enter again. Type yes to confirm the change and then choose QUIT

    Resize disk

  4. Resize LVM partition

    pvdisplay to get info about free space.
    Type sudo pvresize /dev/sda3 to expand the LVM partition

  5. Show info about the Volume Group

    Type sudo vgdisplay and find the free space

    vgdisplay verbose

  6. 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.

  7. 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

Related Posts