LVM - Logical Volumes

Table of Contents

Documents

Overview

Logical Volumes are used to store your file systems. You create logical volumes in volume groups.

Creating

server# lvcreate -L 1G -n VS-SSH RAID

creates the logical volume "VS-SSH" in the volume group "RAID" with a size of 1 gigabyte.

Renaming

There are two forms of the lvrename command that will rename a logical volume. Either

server# lvrename /dev/RAID/VS-SSH /dev/RAID/SSH-VSERVER

or

server# lvrename RAID VS-SSH SSH-VSERVER

will rename the VS-SSH logical volume in the RAID volume group to SSH-VSERVER.

Deleting

You remove the logical volume VSbzfsbroken as follows:

root@vserver:/etc/vservers# lvremove /dev/RAID/VSbzfsbroken
Do you really want to remove active logical volume "VSbzfsbroken"? [y/n]: y
  Logical volume "VSbzfsbroken" successfully removed
root@vserver:/etc/vservers#

Resizing Volumes

I have a samba vserver on my vserver box. It's been set up for ages. My vservers are LVM on software RAID-1.

I have 2 disks (different sizes) both with a 150GB partition setup as software RAID-1.

On that 150GB partition I've created an LVM physical volume called RAID.

So now I have a 150GB physical volume (disk) with 150GB of free space. I created logical volumes in that for each of my vserver root partitions. This makes each vserver root partition backed by RAID-1 so if a drive fails they still work.

The samba server was set up as 2GB ages ago and it's been running great with about 40% free space.

I need to move more data to that vserver and it doesn't fit. pvscan reports that there's 25GB of unallocated space on my RAID volume. So I just shut down my samba vserver, resize the LVM partition for the samba root partition from 2GB to 6GB, and resize the ext3 partition as follows:

# vserver samba stop
# umount /var/lib/vservers/samba/
# lvresize -L 6G /dev/RAID/VSsamba
# e2fsck -f /dev/RAID/VSsamba
# resize2fs /dev/RAID/VSsamba
# mount /dev/RAID/VSsamba
# vserver samba start

# vserver samba enter
root@samba:/# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hdv1             6.0G 1002M  4.7G  18% /
none                   16M     0   16M   0% /tmp
smaug:/backups        202G  109G   84G  57% /backups
/dev/mapper/RAID-PHOTOS
                       50G   28G   19G  60% /photos

and I'm done. That takes all of about 1 minute to do.

Now my samba vserver is up with 6GB of root file space and I have 21.76GB left of free space on my RAID volume which I can allocate other places I may need it in the future.

I love LVM!

I allocate as little space as I think I need and leave free space in the physical volume that I can use part of later for any volume that needs to expand. This way I don't have to know up front how much space I need to set up (and get it wrong).

Author: Bernt Hansen