Reduce size of ext3/ext4 LVM partition in RHEL & CentOS
Scenario : Suppose we want to reduce /opt to 2GB which is LVM and formated as ext4. XFS filesystem type cannot be shrinked.
[root@rhlab01 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_rhlab01-opt 3,5G 11M 3,2G 1% /opt [root@rhlab01 /]# lvs | grep opt WARNING: Not using lvmetad with older version. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert opt centos_rhlab01 -wi-ao---- 3,50g
[root@rhlab01 /]# umount /opt
[root@rhlab01 /]# e2fsck -f /dev/mapper/centos_rhlab01-opt e2fsck 1.42.9 (28-Dec-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/centos_rhlab01-opt: 12/229376 files (0.0% non-contiguous), 34375/916480 blocks
As shown in the above scenario , size of /opt is 3,5 GB , so by reducing it by 1,5 GB , then the size will become 2 GB.
[root@rhlab01 /]# resize2fs /dev/mapper/centos_rhlab01-opt 2g resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/mapper/centos_rhlab01-opt to 524288 (4k) blocks. The filesystem on /dev/mapper/centos_rhlab01-opt is now 524288 blocks long.
[root@rhlab01 /]# lvreduce -L 2g /dev/mapper/centos_rhlab01-opt WARNING: Not using lvmetad with older version. WARNING: Reducing active logical volume to 2,00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce centos_rhlab01/opt? [y/n]: y Size of logical volume centos_rhlab01/opt changed from 3,50 GiB (895 extents) to 2,00 GiB (512 extents). Logical volume centos_rhlab01/opt successfully resized.
[root@rhlab01 /]# e2fsck -f /dev/mapper/centos_rhlab01-opt e2fsck 1.42.9 (28-Dec-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/centos_rhlab01-opt: 12/131072 files (0.0% non-contiguous), 27309/524288 blocks
[root@rhlab01 /]# mount /opt [root@rhlab01 /]# df -h /opt Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_rhlab01-opt 2,0G 11M 1,8G 1% /opt
Reduce size of ext3/ext4 LVM partition in RHEL & CentOS
Scenario : Suppose we want to extend / to +1000MB which is LVM and formated as ext4.
[root@rhlab01 /]# df -h / Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_rhlab01-root 3,9G 3,8G 0 100% /
[root@rhlab01 /]# lvextend -L +1000M /dev/mapper/centos_rhlab01-root WARNING: Not using lvmetad with older version. Size of logical volume centos_rhlab01/root changed from 4,00 GiB (1024 extents) to 4,98 GiB (1274 extents). Logical volume centos_rhlab01/root successfully resized.
[root@rhlab01 /]# resize2fs /dev/mapper/centos_rhlab01-root resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/mapper/centos_rhlab01-root is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/mapper/centos_rhlab01-root is now 1304576 blocks long.
[root@rhlab01 /]# df -h / Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_rhlab01-root 4,8G 3,8G 742M 84% /