How to extend LVM disk in ubuntu when I have seeing this error message “Insufficient free space”

If you’re encountering an “Insufficient free space” error when trying to extend an LVM volume, it’s likely that you don’t have enough free space in the volume group to extend the logical volume to the desired size. You’ll need to first ensure you have enough free space in the volume group or add more physical storage to it.

Follow these steps to extend an LVM disk in Ubuntu:

  1. Check available space in the volume group:

    vgdisplay
    

    This will show the volume groups and the free space available in each one.

  2. If you don’t have enough space:

    a. You can reduce the size of another logical volume (assuming you have one that can be shrunk).

    b. Add a new physical disk or partition to the volume group.

    To add a new physical volume (assuming /dev/sdx is your new partition or disk):

    pvcreate /dev/sdx
    vgextend [volume-group-name] /dev/sdx
    

    Replace [volume-group-name] with the name of your volume group.

  3. Extend the logical volume:
    Once you have enough free space in the volume group, extend the logical volume:

    lvextend -l +100%FREE /dev/[volume-group-name]/[logical-volume-name]
    

    Replace [volume-group-name] with your volume group name and [logical-volume-name] with your logical volume name.

    Alternatively, if you know the exact size you want to add (e.g., 10G), you can use:

    lvextend -L +10G /dev/[volume-group-name]/[logical-volume-name]
    
  4. Resize the filesystem:
    Most modern filesystems, like ext4, can be resized online (while they’re mounted). Use resize2fs to resize the file system of the logical volume:

    resize2fs /dev/[volume-group-name]/[logical-volume-name]
    
  5. Finally, check the new size of your logical volume using the df command:

    df -h
    

By following the steps above, you should be able to extend the LVM disk in Ubuntu successfully. Always ensure that you have backups before performing disk operations to prevent potential data loss.