LVM partitioning - Logical Volume Manager

This is a basic guide to get you started. It is your responsibilty to learn more about LVM. Sources and Resources are linked at the bottom of this page which will be of help, however the list is definitely not exhaustive.

Applicable for aptosid-2010-03-apate forward.

Logical volumes can span multiple disks and are scalable, unlike the traditional method of partitioning hard drives.

However, whether it be the traditional method of partitioning or partitioning to use LVM, partitioning is not something you do very often, thus it requires deep thought, along with trial and error, before you will be happy with the outcome you desire.

There are 3 basic terms of of terminology you will need to know:

There are 6 basic steps required

The assumption for the following example is based upon new unpartitioned disks or where a new partitioning scheme is required, which will delete all existing data on the partitions you wish to convert to an LVM.

Using cfdisk or fdisk is required, as to date Gparted and KDE Partition Manager, (partitionmanager), do not support LVM partitioning.

Step 1: Create the partition table:

fdisk /dev/sda
 n to create a new partition on the disk
 p  to make this the primary partition
 1  to give the partition the number 1 as an identifier
 ### size allocation  ### Set first and last cylinders to the default values (press enter) to span the entire drive
 t  toggle the type of partition to create
 8e  is the hex code for a Linux LVM
 W  to write your changes to the disk. ##This will write the partition table. If you have realised that you made a mistake at this point, you could restore the old partition layout and your data will be fine.##

Should you want the volume to span 2 or more disks, repeat this process on each of the disks.

Step 2: Setup the partition as a Physical Volume. This will delete any data:

pvcreate /dev/sda1

Repeat the process on any other partitions as required.

Step 3: Create the Volume Group:

vgcreate vulcan /dev/sda1

Should you wish to span 3 disks, for example, you include the other disks in the vgcreate command:

vgcreate vulcan /dev/sda1 /dev/sdb1 /dev/sdc1

If you have done this correctly you'll be able to see the result in the output of:

vgscan

vgdisplay will give you the size properties:

vgdisplay vulcan

Step 4: Creating the Logical Volume. Now it is time for you to decide how big you want the logical volume to be initially. One advantage of LVM is that you can adjust the size of the volume on at will without needing to reboot.

Lets assume that you initially want a 300GB volume called spock within the lvm called vulcan:

lvcreate -n spock --size 300g vulcan

Step 5: Format the volume and be patient while it is formating , it could take a while:

mkfs.ext4 /dev/vulcan/spock

Step 6:

mkdir /media/spock/

Edit fstab with your favorite editor to mount the volume during boot up.

mcedit /etc/fstab

Using /dev/vulcan/spock is better than using UUID numbers with LVM, as then you can clone the filesystem and not have to worry about potential UUID collisions, especially with LVM, as you can end up with multiple filesystems with the same UUID number (snapshots being a prime example).

/dev/vulcan/spock /media/spock/ ext4 auto,users,rw,exec,dev,relatime  0  2

Optional: Change the owner of the volume so that other users have read/write access to the LVM:

chown root:users /media/spock
chmod 775 /media/spock

Your basic LVM should now be set up.

Resizing the volume

It is highly recommended that you use a live ISO to change the partition sizes. Whilst growing the partition 'on the fly' may be error free, the same can not be said when reducing the volume, as anomalies will cause data loss, particularly if / (root) or /home are involved.

To resize the volume from 300GB to 500GB, as used in this example:
umount /media/spock/
lvextend -L+200g /dev/vulcan/spock

Then run the command for the filesystem to be resized:

e2fsck -f /dev/vulcan/spock
resize2fs /dev/vulcan/spock
mount /media/spock
To resize the volume from 300GB down to 280GB, as used in this example:
umount /media/spock/

Then run the command for the filesystem to be resized:

e2fsck -f /dev/vulcan/spock
resize2fs /dev/vulcan/spock 280g

Then resize the volume

lvreduce -L-20g /dev/vulcan/spock
resize2fs /dev/vulcan/spock
mount /media/spock
An LVM GUI

system-config-lvm provides a GUI and is available to help you manage your LVMs which is started from the command line as root:

apt-get install system-config-lvm
system-config-lvm2
man system-config-lvm  # required reading
Sources and Resources:
Page last revised 26/07/2011 2325 UTC