Centos – LVM: How to re-use unwanted logical volume space on an existing volume

centoslvm

We have this old CentOS4 box and I am trying to increase the space.

I want the full 8GB to show up in a "df -h" but it shows only the first Volume of ~4GB. How can I add the 2nd volume to the first? Can I just edit fstab and mount the Group?? After creating my notes below it looks like the 2nd volume is swap space. Can I just remove the swap space and make it disk space on the first volume? If so how??

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 3.9G  3.1G  662M  83% /
/dev/xvda1                       99M   13M   81M  14% /boot

# vgdisplay -s
"VolGroup00" 7.88 GB   [7.88 GB   used / 0    free]

# lvdisplay | grep Name
LV Name                /dev/VolGroup00/LogVol00
VG Name                VolGroup00
LV Name                /dev/VolGroup00/LogVol01
VG Name                VolGroup00

# sfdisk -s
/dev/xvda:   8388608

# less /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

Best Answer

The question is, erm, a little confusing, but if I understand what you want correctly, you're trying to reclaim the drive space taken up by swap and use it for your LV that holds your root file system. Easy enough, if you have the right underlying filesystem. Ext3 can dynamically expand the file system while hot, which means you're in luck because your root filesystem is ext3. As root (please excuse any naming issuess with the LV tools, it's been months since I've had to do this and I know there are cases where you specify the path rather than simply the name):

swap off
lvremove LogVol01
lvresize --size +3.5G LogVol00
resize2fs / 

The swap off portion does what it says on the tin, which should remove the swap space from active use. The lvremove will blow the swap partition way completely and return it as free space to use in the volume group. The lvresize will then push the partition out, in the process claiming the newly-formed space. The resize2fs then expands the filesystem mountpoint to use all of the partition space it currently resides on.

Don't forget to remove your swap instance from /etc/fstab.

Related Topic