Craig's Linux Notes: LVM - Logical Volume Manager

Last modified: 01/01/2007

Contents

What is LVM?
LVM1 versus LVM2
Planning Disk Layout
Growing a partition
Backing up LVM metadata
LVM recovery
Ignoring CD-ROM devices

What is LVM?

LVM allows you to change disk partition sizes dynamically and have partitions that span more than one hard disk. See the LVM Howto for more information. Also see Gentoo's LVM2 installation guide. For most tasks, it effectively replaces repartition utilities such as Partition Magic and GNU Parted.

LVM1 versus LVM2

There are two parts to LVM: the disk format and the utilities to access LVM partitions. LVM2 utilities are backward compatible with the LVM1 disk format, but LVM1 utilities cannot read the LVM2 disk format.

The LVM2 disk format is alleged to be better. You can upgrade your disk format from LVM1 to LVM2 with vgconvert, but may not be able to go back.

2.4 kernels work with LVM1 and LVM2 utilities. 2.6 kernels only work with LVM2 utilities.

Planning Disk Layout

With LVM, it is no longer critical to accurately estimate future disk usage. Partitions may easily be resized, in some cases without unmounting the file system.

Why use multiple partitions at all?

For example, most kernels can read the Ext3 file system, but maybe not more advanced systems such as XFS. The system's root file system is constrained to Ext3, but most of the files can be XFS. Or stripped across multiple disks (similar, but not the same, as RAID 0 stripping).

Rather than give most or all of your entire hard disk to the LVM, consider saving a significant portion as unpartitioned storage. It's easy enough to partition the next chunk and adding it to LVM later. (Nice idea, though not mine.) For example, give the first 20 GB of an 80 GB drive to LVM and leave the rest available for the future. Who knows what could come up?

Growing a partition

To grow a partition "/dev/vg/usr" by 5GB, run:

lvextend -L+5G /dev/vg/usr

Then the file system will have to be resized. Some file systems must be umounted before resizing. Unmounting is not required before enlarging an LVM partition (it is before shrinking one). Also see the LVM Howto: Extending a Logical Volume.

To see how much space is available in the LVM:

# vgdisplay

This is the sequence for growing an ext3 partition by 5 GB:

# telinit 1
# umount /dev/vg/home
   
If this fails, use "lsof | grep '\/home'" to locate processes accessing volume.
# lvextend -L+5G /dev/vg/home
# resize2fs /dev/vg/home
   
May take a few minutes.
   
May advise running e2fsck, which will take a few minutes.
# mount /dev/vg/home
# telinit 3
   
or whatever was the original runlevel was

With the 2.6 kernel, you can grow an ext3 filesystem without unmounting.

Backing up LVM metadata

LVM's metadata tells it where the physical and logical partitions are. If it gets damaged, you can't see your files.

LVM automatically backs up metadata to "/etc/lvm" after each change. However, if you want to explicitly backup the metadata, run "vgcfgbackup".

Use "vgcfgrestore" to restore the metadata if it gets damaged. You will most likely never use this command.

LVM recovery

Can't access your logical volumes? Here are some things to try first:
  1. Verify that drive is recognized by kernel. Review dmesg. Insure that module dm-mod is loaded. If using libata, insure that module ata_piix is loaded (see Gentoo Kernel, Current Issues).
  2. pvscan. Should report which disk partitions are participating as volume groups, and the metadata version (lvm1 or lvm2). Also try "-v", "-vv", or "-vvv" options.
  3. vgscan. Should list all volume groups and metadata type. Also try "-v", "-vv", or "-vvv" options.
  4. vgchange -ay volume-group. Enables a volume group.

Ignoring CD-ROM devices

Tell the LVM utilities to ignore CD-ROM devices by adding the text:

devices { filter=["r/cdrom/"] }

to "/etc/lvm/lvm.conf" (Create the file, if necessary).

Copyright © 2004 Craig Lawson
Index no-thank-you-spam-i-am@i-hate-spam.spam.spam Document made with Nvu