How to resize partitions in Linux using LVM

25 viewsLinux

Sometimes you need to make some changes on your disk partition sizes, How to shrink or extend partitions in Linux without losing data ?

Answered question

EXT3/EXT4 FS can be easily resize /shrink , but XFS  FS can’t be  shrink  due to FS design

FS Extend :-  Check disk volume group have enough  free space to extend. If not enough  space is available then add new  disk to VG to  extend.

# vgs  –> check VG having enough free space

# lvresize -r -L +10G /dev/testvg/testlv  — > Increasing  testlv by 10G


# lvextend -L +10G /dev/testvg/testlv

# resize2fs /dev/testvg/testlv

Shrink FS :-

#  df -h  | grep  $testlv   –> check FS is already mounted on server. If FS is mounted then  umount  first

# umount  /dev/testvg/testlv

# resize2fs /dev/testvg/testlv 2G  –> Shrinking testlv FS  size to 2G. This could recommended to  run e2fsck on FS

# e2fsck -b /dev/testvg/testlv

#  resize2fs /dev/testvg/testlv 2G

# e2fsck -b /dev/testvg/testlv  –> Execute FSCK again to  confirm no errors on  FS

# lvreduce -L -10G  /dev/testvg/testlv  –> Shrinking 10G  from FS testlv

# mount  /dev/testvg/testlv  –> Mount the testlv FS and verify the  new size

Answered question