Shrinking a Linux filesystem on LVM




Online reduce/shrink

1. Unmount filesystem

if you cant unmount the filesystem on the running system see the offline section below

umount /dev/vg01/lvs-02

2. Perform a check of the filesystem...

e2fsck -f /dev/vg01/lvs-02

3. Resize the filesystem

resize2fs /dev/vg01/lvs-02 15G

2. Reduce the size of the logical volume.

lvreduce -L -15G /dev/vg01/lvs-02

# Optional: you can also shrink down the volume group if desired.

vgreduce vg01 /dev/sdxy




Offline reduce/shrink root filesystem

1. boot from rescue media

if san connected append "linux mpath" to boot options

Do not mount filesystems when booting from rescue media

select the menu option that skips the mounting of your filesyetsms

2. Identify the Volume group

/usr/sbin/lvm vgscan
/usr/sbin/lvm vgdisplay

note: you have to run lvm {operand}... instead of the aliases lvscan

3. Activate the the volume group

/usr/sbin/lvm vgchange {VG-name} -a y

4. Perform a check of the filesystem...

/usr/sbin/fsck.ext2 -f /dev/vg01/lvs-02

5. Resize the filesystem

resize2fs /dev/vg01/lvs-02 15G

6. Reduce the size of the logical volume.

/usr/sbin/lvm lvreduce -L -15G /dev/vg01/lvs-02

# Optional: you can also shrink down the volume group if desired.

/usr/sbin/lvm vgreduce vg01 /dev/sdxy

Example: reducing the size of a swap volume

[root@server ~]# swapoff -a

[root@server ~]# lvreduce /dev/vgsys/swap -L 20G
  Found duplicate PV 8RD6mpGQfwBCWprZvaxabcdefg123: using /dev/sdq not /dev/sda
  New size given (640 extents) not less than existing size (625 extents)
  Run `lvreduce --help' for more information.

[root@server ~]# lvreduce /dev/vgsys/swap -L 10G
  Found duplicate PV 8RD6mpGQfwBCWprZvaxabcdefg123: using /dev/sdq not /dev/sda
  WARNING: Reducing active logical volume to 10.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce swap? [y/n]: y
  Reducing logical volume swap to 10.00 GB
  Logical volume swap successfully resized

[root@server ~]# mkswap /dev/vgsys/swap
Setting up swapspace version 1, size = 10737414 kB

[root@server ~]# swapon -a

[root@server ~]# free
             total       used       free     shared    buffers     cached
Mem:      65931888     527968   65403920          0      32036     343660
-/+ buffers/cache:     152272   65779616
Swap:     10485752          0   10485752