Resizing (extending) Logical Volumes and filesystems
Live LogicalVolume and Filesystem extension in a single step (-r)
Determine the free space/extents withing the Volume Group
vgdisplay {vgname} | grep Free
Decide if you want to declare the size in relative or absolute terms
lvextend -r /dev/vgroot/lvtmp -L 30G # set size to 30GB
or
lvextend -r /dev/vgroot/lvtmp -L +5G # increase size by 5GB
or
lvextend -r /dev/vgroot/lvtmp -l +100%FREE # increase the LV to use up all free extents within the VG
Live LogicalVolume extension with a separate step to extend the filesystem
Determine the free space/extents within the Volume Group
vgdisplay | grep Free
Extend the Logical Volume
lvextend -L +100MB /dev/vgsys/tmp # Increase size by 100MB
Extend the Filesystem to fill the logical Volume
resize2fs /dev/vgsys/tmp # optional size parameter
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vgsys/tmp is mounted on /tmp; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vgsys/tmp to 557056 (4k) blocks.
The filesystem on /dev/vgsys/tmp is now 557056 blocks long.
Reconfigure swap
expanding swap
swapoff -a # turn swap off
lvextend /dev/vgroot/lvswap -L 30G # set size to 30GB
or
lvextend /dev/vgroot/lvswap -L +5G # increase size by 5GB
or
lvextend /dev/vgroot/lvswap -l +100%FREE # increase the LV to use up all free extents within the VG
mkswap /dev/vgroot/lvswap # recreate the swap filesystem
swapon -a # turn swap on
removing swap (to free up disk for filesystem expansion)
swapoff -a
Edit /etc/fstab && remove the swap line, to stop it from activating upon next boot
/dev/vgsys/swap swap swap defaults 0 0
Remove the swap logical volume
lvremove /dev/vgroot/lvswap
now you can use the swap space for something else
turn the swap back on
swapon -a
show the swap
swapon -s
free -g
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 asdfgpGQfwBCWprZvax4wy: 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 asdfgpGQfwBCWprZvax4wy: 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