Adventures in LVM

In recent times I have been using Logical Volume Management (LVM) on Linux as a very flexible way of operating a flexible file system. LVM is a very powerful way of dynamically adding and removing disk from a Linux server (or desktop). Rather than mounting individual devices in different parts of the file system LVM lets you place all your physical disk drives together into virtual pools. Inside these pools you can dynamically divide the space up however your like and format each partition in any of the available Linux file formats.

It is a great way to work with disk resources and is very similar to Novell's Network Storage Services (NSS) volumes (minus the very useful 'salvage' tool). To get around the lack of a salvage tool you can create regular snapshots of your data. These snapshots are like CVS branches in that rather than creating a separate copy of the data a snapshot tracks what has changed on disk from a particular time.
For example to create a snapshot of your 'data' volume you perform the following command (Note: you must have the dm-snapshot module loaded into the kernel):

lvcreate -L10G -s -n salvage /dev/system/data

This creates a snapshot of a the data volume (in the system LVM group) and names it salvage. The -L10G command makes the snapshot 10gig in size which means that 10gig of changes can take place within the snapshot before it is marked invalid.

The other day I was left in a bit of a predicament when one of the disks in a LVM group did not come online after a reboot, stopping the successful creation of my LVM groups and hence most of the filesystem. Fortunately in this case I had only just added the drive and no data had been copied onto it yet. To solve the problem at the command line I ran:

vgscan
(This identified the missing physical disk)

vgreduce --removemissing --test system
(this tested the task of removing the disk to make sure things would go okay)

vgreduce --removemissing system
(Remove the missing disk from the volume group)

After a reboot everything came back up and I was able to remove the problematic drive and replace it with a more reliable model. In this scenario I was also helped by the fact my root partition (/) was in a separate, non-LVM partition so I was able to boot into a semi-functional shell to perform maintenance.

Apart from this little adventure I am having no problems running LVM and would recommend it to anyone who needs the ability to dynamically change their disks (or create snapshots for backup). There are some excellent tools out there for SuSE (Yast) and Red Hat (Disk Druid).

This is a good posting on troubleshooting LVM.
Here's a link to the LVM howto which details how to create groups and snapshots.