lvreduce and lvextent a Linux partition, a quick “howto”!

Scenario : Yeah Disk space issues!! /var and /var/log are seperate partitions and /var/log is getting filled-up with the current logrotation settings which we dont want to change. /var is allocated with 50G and has got lot of free space left in it. So we decided to go-ahead with the decision to re-size the partitions and thereby providing more disk space to /var/log partition.
AIM paraphrased : Reduce the LVM partition for /var and then Expand /var/log
Execute the command lvdisplay to list the sizes of all logical volumes.
/dev/vg01/lv_var is the mouted partition for /var and
/dev/vg01/lv_var_log is the mounted partition for /var/log
The change has got two stages :
Stage 1: Reduce the Logical Volume /dev/vg01/lv_var size to 40G
Unmount /var partition before lvreduce.
Make sure /var of not being used by any process.
[bash][root@server ~]# lsof /var/
[root@server ~]#
[root@server ~]# fuser -m /var/[/bash]
Both the commands should not give us any output. If displayed then Stop or Kill all associated programs/processes that are accessing /var .
[bash]fuser –m /var[/bash]
will list all the PID’s accessing /var.
Either kill the processes one-by-one or kill them all by executing the below command
[bash]fuser -km /var[/bash]
then
[bash]umount /var[/bash]
You may get the below error message while unmounting
[bash]umount: /var: device is busy
umount: /var: device is busy[/bash]
Make sure no processes are associated with /var partition
Just to be one the safer side execute the below commands again.
[bash]lsof /var
fuser -m /var[/bash]
and if no results are displayed, forcefully unmount the partition
[bash]umount -f /var[/bash]
Then run :
[bash]e2fsck -f /dev/vg01/lv_var[/bash]
REDUCING THE TOTAL SIZE TO 40G:
[bash]resize2fs /dev/vg01/lv_var 40G[/bash]
[bash]lvreduce -L40G /dev/vg01/lv_var[/bash]
Re-mount the partition :
[bash]mount /dev/vg01/lv_var /var[/bash]
Stage 2: Expand the Logical Volume /dev/vg01/lv_var_log size to 10G
To expand an LVM, there is no need to have it unmounted.
MAKING THE TOTAL SIZE FOR /VAR/LOG TO 10G:
[bash]lvextend -L10G /dev/vg01/lv_var_log[/bash]
[bash]e2fsck -f /dev/vg01/lv_var_log[/bash]
[bash]resize2fs /dev/vg01/lv_var_log[/bash]
lvdisplay and df -h should show the updated disk spaces.
Cheers,