Showing posts with label Reduce size of ext3/ext4 LVM. Show all posts
Showing posts with label Reduce size of ext3/ext4 LVM. Show all posts

Wednesday, October 15, 2014

Reduce size of ext3/ext4 LVM partition



Reduce size of ext3/ext4 LVM partition in RHEL


Sometimes when we are running out of disk space in our linux box and if partition created on LVM , then we can make some free space in the volume group by reducing the LVM using lvreduce command.   
Scenario : Suppose we want to reduce /home by 2GB which is LVM and formated as ext4.
[root@linux ~]# df -h /home/

Filesystem                                              Size       Used    Avail     Use%      Mounted on

/dev/mapper/vg_linux-LogVo              12G         9.2G   1.9G      84%       /home
 
Step:1 Umount the filesystem
[root@linux ~]#  umount  /home
 
Step:2 check the filesystem for Errors using e2fsck command.
[root@linux ~]# e2fsck  -f  /dev/mapper/vgsrv-home
e2fsck 1.41.12 (17-May-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgsrv-home: 12/770640 files (0.0% non-contiguous), 2446686/3084288 blocks
Note: In the above command e2fsck , we use the option '-f' to forcefully check the filesystem , even if the filesystem is clean.
 
Step:3 Shrink the size of /home to desire size.
As shown in the above scenario , size of /home is 12 GB , so by reducing it by 2GB , then the size will become 10GB.
[root@linux ~]# resize2fs /dev/mapper/vgsrv-home 10G
resize2fs 1.41.12 (17-May-2013)
Resizing the filesystem on /dev/mapper/vgsrv-home to 2621440 (4k) blocks.
The filesystem on /dev/mapper/vgsrv-home is now 2621440 blocks long.
 
Step:4 Now reduce the size using lvreduce command.
[root@linux ~]# lvreduce  -L 10G /dev/mapper/vgsrv-home

  WARNING: Reducing active logical volume to 10.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol00? [y/n]: y
  Reducing logical volume LogVol00 to 10.00 GiB
  Logical volume LogVol00 successfully resized
 
Step:5 (Optional) For the safer side , now check the reduced filesystem for errors
[root@linux ~]# e2fsck -f /dev/mapper/vgsrv-home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgsrv-home: 12/648960 files (0.0% non-contiguous), 2438425/2621440 blocks
 
Step:6 Mount the file system and verify the size.
[root@linux ~]# mount /home
[root@linux ~]# df -h /home


Filesystem                                            Size    Used   Avail    Use%        Mounted on


/dev/mapper/vgsrv-home                9.9G    9.2G   208M    98%        /home