Difference between revisions of "CentOS 8.x Reduce size of ext2, ext3 or ext4 partition"
From Notes_Wiki
(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...") |
m |
||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 8.x]] > [[CentOS 8.x System Administration|System Administration]] > [[CentOS 8.x File system management|Filesystem management]] > [[CentOS 8.x Reduce size of ext2, ext3 or ext4 partition]] | [[Main Page|Home]] > [[CentOS]] > [[CentOS 8.x]] > [[CentOS 8.x System Administration|System Administration]] > [[CentOS 8.x File system management|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: | |||
# Validate current usage and free space. We can reduce filesystem to value less than current used space. | |||
#:<pre> | |||
#:: df -h | |||
#:</pre> | |||
# Umount the filesystem | |||
#:<pre> | |||
#:: umount <device> | |||
#:</pre> | |||
# Check the filesystem for errors before resizing | |||
#:<pre> | |||
#:: fsck -f <device> | |||
#:</pre> | |||
# Finally resize both LVM and Ext partition using: | |||
#:<pre> | |||
#:: lvresize --resizefs --size <desired-final-size> <device> | |||
#:</pre> | |||
#: Here we can specify size as 200g (200 GiB) or 200G (200GB) based on requirement | |||
# (Optionally) Check the filesystem again for errors after resizing | |||
#:<pre> | |||
#:: fsck -f <device> | |||
#:</pre> | |||
Refer | |||
* https://www.systutorials.com/shrinking-a-ext4-file-system-on-lvm-in-linux/ | |||
==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: | 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: | # Check the occupied and free space on partition: |
Revision as of 03:35, 12 September 2022
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:
- Validate current usage and free space. We can reduce filesystem to value less than current used space.
- df -h
- Umount the filesystem
- umount <device>
- Check the filesystem for errors before resizing
- fsck -f <device>
- 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
- (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:
- 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