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

From Notes_Wiki
Revision as of 12:18, 22 July 2022 by Saurabh (talk | contribs) (Created page with "Home > CentOS > CentOS 8.x > System Administration > Filesystem management > CentOS 8.x Reduce size of ext2, ext3 or ext4 partition In case size of ext partition (ext2-4) needs to be reduced, it can be done as follows: # Check the occupied and free space on partition: #:<pre> #:: df -h #:</pre> #: Ensure that we do not try to resize the partition to value less than free...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

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