[CentOS] Consolidating LVM volumes..

Fri Mar 23 12:20:50 UTC 2007
Theo Band <theo.band at xanadu-wireless.com>

WipeOut wrote:
> Hi,
>
> Something I haven't done before is reduce the number of volumes on my 
> server.. Here is my current disk setup..
>
> [root at server1 /]# df -h
> Filesystem            Size  Used Avail Use% Mounted on
> /dev/mapper/VolGroup00-RootVol00
>                        15G  1.5G   13G  11% /
> /dev/md0              190M   42M  139M  24% /boot
> /dev/mapper/VolGroup00-DataVol00
>                        39G   16G   22G  42% /data
> none                  157M     0  157M   0% /dev/shm
> /dev/mapper/VolGroup00-HomeVol00
>                        77G   58G   15G  80% /home
> /dev/mapper/VolGroup00-VarVol00
>                        16G  382M   15G   3% /var
>
> Rather than try and reduce the size of the VarVol00 volume to make 
> more unallocated space which I have heard is a little dangerous.. I 
> would like to get rid of the VarVol00 and have the /var directory on 
> the RootVol00 volume.. Then I can allocate some of the free space to 
> HomeVol00 which is filling up..
>
> So how do I do this?
>
> Do I simply copy /var to /var2 and then edit the /etc/fstab file to 
> remove the line that mounts VarVol00??
>
> Then at what point and how do I rename /var2 to /var to get it all 
> working as normal again?
>
> Should this all be done in "single" mode?
It depends (as always). You need to unmount /var Perhaps this can be 
done in single user mode. If not (some services still running that have 
files open) than just use rescue mode.
# something like this:
rsync -av /var/ /var2
telinit s
umount /var
rmdir /var (it's probably empty)
mv /var2 /var
vi /etc/fstab
telinit 3 (or 5)

To my understanding sometimes it is possible to resize live ext3 
filesystems. (No experience myself). In that case you could simply do 
something like this:

resize2fs /dev/VolGroup00/VarVol00 2G
lvreduce -L2G /dev/VolGroup00/VarVol00

I would still prefer to do this when the disk is unmounted and checked 
(e2fsck -f /dev/VolGroup00/VarVol00). But in that case you of course get 
rid of the partition VarVol00 anyhow.

Theo