Wednesday, February 11, 2015

How to reduce ext3 or ext4 filesystem in Linux ?

Reducing filesystem is a rare sys admin task and first question asked is - 'why we need to that?' Avoid it if you can. Otherwise, follow below step with standard advise - take backup before attempting it !

Note: You need to unmount filesystem to reduce it !

>> In below example, I have reduced filesystem and LV from 8.9G to 7.9 GB

# df -hP /testfs
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv  8.9G  151M  8.3G   2% /testfs

# lvreduce -r -L -1G /dev/mapper/testvg-testlv
Do you want to unmount "/testfs"? [Y|n] y
fsck from util-linux-ng 2.17.2
/dev/mapper/testvg-testlv: 11/589824 files (0.0% non-contiguous), 75584/2359296 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/testvg-testlv to 2097152 (4k) blocks.
The filesystem on /dev/mapper/testvg-testlv is now 2097152 blocks long.

  Reducing logical volume testlv to 8.00 GiB
  Logical volume testlv successfully resized
  (filesystem will be unmounted before resize and mounted)

# df -hP /testfs
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv  7.9G  151M  7.4G   2% /testfs


>> I have tested it in following environment.


# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
# uname -r
2.6.32-358.el6.x86_64


Reference : lvreduce

No comments:

Post a Comment