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...")
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:
- 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.
- First umount the partition
- umount /dev/mapper/vg1-lv1
- 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.
- Then ensure that filesystem is healthy using:
- fsck -f /dev/mapper/vg1-lv1
- 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.
- 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'.
- 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.
- 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