Resize LVM without data loss

Solution 1:

You have to shrink the ext4 filesystem before to reduce the logical volume size. You have to unmount the root partition so in order to shrink the filesystem you have to boot the server with a USB/DVD Linux iso and execute the rescue mode.

Example: https://www.thegeekdiary.com/centos-rhel-how-to-shrink-lvm-root-file-system/

Solution 2:

From the link offered by NoNoNo above, the resize2fs + lvreduce commands can be done in one liner, which I think is best. Especially because the lvreduce will otherwise spit out a really bad warning.

BEFORE RUNNING THOSE INSTRUCTIONS, MAKE SURE TO BACKUP YOU IMPORTANT DATA.

The instructions can be resumed to:

  1. boot on a live CD/DVD (Linux or GParted Live)

  2. make sure your root partition is not mounted

    umount /dev/[partition-name]
    
  3. make sure LVM is up (probably not required, at least on GParted Live)

    vgchange -ay
    
  4. clean up

    e2fsck -f /dev/[volumegou]/[logicalvolume]
    

    Repeat until no more errors occur to increase chances that things will work as expected while resizing the file system.

  5. reduce partition

    lvresize --resizefs -L [newlvsize] /dev/[volumegroup]/[logicalvolume]
    

    Because of the --resizefs the lvresize will take a long time (assuming you have a large partition, my 1.8Tb took about 5 hours to reduce to about 1.1Tb). You should be getting some feedback in your console.

    Note: The LVM environment offers three commands to resize: lvresize, lvreduce, and lvextend. The resize let you change the size (bigger or smaller), the reduce only allows smaller sizes (i.e. at most X Gb) and the extend only allows larger sizes (i.e. at least X Gb).