CentOS 8.x Reduce size of ext2, ext3 or ext4 partition

From Notes_Wiki

Home > CentOS > CentOS 8.x > System Administration > Filesystem management > CentOS 8.x Reduce size of ext2, ext3 or ext4 partition

Do LVM and filesystem resize in single step (Preferred)

Since various commands such as lvresize / resize2fs may use different units KB (1000) instead of KiB (1024), it is better to perform both filesystem and LVM resize using a single command and avoid any issues. In that case the reduction can be achieved via:

  1. Validate current usage and free space. We can reduce filesystem to value less than current used space.
    df -h
  2. Umount the filesystem
    umount <device>
  3. Check the filesystem for errors before resizing
    fsck -f <device>
  4. Finally resize both LVM and Ext partition using:
    lvresize --resizefs --size <desired-final-size> <device>
    Here we can specify size as 200g (200 GiB) or 200G (200GB) based on requirement
  5. (Optionally) Check the filesystem again for errors after resizing
    fsck -f <device>


Refer


Running LVM and ext resize separately (Not preferred)

In case size of ext partition (ext2-4) needs to be reduced, it can be done as follows:

  1. Check the occupied and free space on partition:
    df -h
    Ensure that we do not try to resize the partition to value less than free space. Ideally even after resizing try to keep usage at 80% or less.
  2. First umount the partition
    umount /dev/mapper/vg1-lv1
  3. Look at existing block count and block size before resizing using:
    dumpe2fs -h /dev/mapper/vg1-lv1 | grep -i block
    and look for values of 'Block count' and 'Block size'. After resize the 'Block size' would remain same but 'Block count' should decrease.
  4. Then ensure that filesystem is healthy using:
    fsck -f /dev/mapper/vg1-lv1
  5. We can use resize2fs to resize filesystem to desired size using:
    resize2fs /dev/mapper/vg1-lv1 80G
    Here instead of 80GB specify desired size. Also note the point mentioned above related to used and free space. Try to keep at least 20% free space even after resizing. Hence if we are resizing to 80GB. The partition should have data about 63GB or less.
    resize2fs has -M option to minimize the size of partition based on existing data.
  6. Once filesystem is resized, its new size can be checked using:
    dumpe2fs -h /dev/mapper/vg1-lv1 | grep -i block
    and look for updated values of 'Block count' and 'Block size'.
  7. We can now resize the physical partition and make it smaller via fdisk / parted / lvm. The partition size should be at least 'Block count' x 'Block size' bytes long. Ideally keep some buffer for suprises. We can again do resize2fs /dev/mapper/vg1-lv1 to extend / expand the partition to match the partition size.
  8. Optionally run "fsck -f" once again before remounting

Refer:


Home > CentOS > CentOS 8.x > System Administration > Filesystem management > CentOS 8.x Reduce size of ext2, ext3 or ext4 partition