Basic LVM Step-By-Step

A presentation by Dustin Laurence for the SGVLUG, 7/8/04.

AnyBrowser.org

What Is LVM? What can it do for me?

Key Benefits Of LVM:

Less interesting (to me) features:

The Plan Of The Presentation

A Little Background

Tools and Requirements

To use LVM, we need to make sure our installation supports it:

Constructing a Logical Volume

Assuming we have the necessary tools, we are ready to use them. I will be using the tools on my home machine as we go (that's the drama part, remember?).

  1. RTFM
        # man lvm
        # lvm help
        # man pvcreate
        
        

    Unfortunately, the man pages are out of date (e.g. lvm2 format is the default, 'man lvm' doesn't list all the commands).

    The LVM-HOWTO

    Daniel Robbin's LVM articles for IBM (Part 1, Part 2).

    Gentoo-specific info

    SuSE-specific info

  2. Configure LVM
        # man lvm.conf
        # emacs /etc/lvm/lvm.conf
        
  3. Create suitable devices to feed to LVM:
  4.     # cfdisk /dev/hda
        

    (Don't forget to set the partition type: 0x8E for LVM, 0xFD for RAID.)

    or

        # emacs /etc/raidtab; mkraid
        

    or

        # mdadm --create /dev/md0 --level=raid1 -n 2 /dev/hda5 /dev/hdc5
        
  5.     # pvcreate /dev/hd[eg]13 /dev/hde14
        
  6.     # pvs
        # pvscan
        # pvdisplay /dev/hde13
        
  7.     # vgcreate -s 32M newsystem /dev/hd[eg]13
        
  8.     # vgs
        # vgscan
        # vgdisplay newsystem
        
  9.     # lvcreate -L 300M --contiguous y --name root newsystem
        
  10.     # lvs
        # lvscan
        # lvdisplay newsystem
        # lvdisplay newsystem/root
        

    Note the logical volume size is a multiple of the 32M physical extent size of the volume group.

  11.     # mkreiserfs -l '/' /dev/newsystem/root
        
  12.     # mkdir /mnt/newsystem
        # emacs /etc/fstab
        # mount /mnt/newsystem
        

A Few Simple Acts Of Humanity

Extending A Logical Volume

  1.     # vgs
        # lvcreate -L 1.1G --contiguous y --name usr newsystem
        

    There weren't enough contiguous extents on a single physical volume. (Note that LVM uses SI prefixes. It's probably a commie plot.)

  2.     # lvcreate -L 1.1G --name usr newsystem
        # mkreiserfs -l '/usr' /dev/newsystem/usr
        # mkdir /mnt/newsystem/usr
        # emacs /etc/fstab
        # mount /mnt/newsystem/usr/
        

    All is well.

  3.     # lvdisplay newsystem/usr
        # lvextend  -L +200M newsystem/usr
        # resize_reiserfs /dev/newsystem/usr
        

    What didn't I do first?

  4.     # resize_reiserfs -s -500M /dev/newsystem/usr
        

    But must umount to shrink.

  5.     # pvcreate /dev/hde14
        # vgextend newsystem /dev/hde14
        # lvextend -L +1G newsystem/usr
        # resize_reiserfs /dev/newsystem/usr
        # pvs
        

    Note that newsystem/usr is larger than any of the physical volumes in the volume group. As long as it isn't forced to be contiguous, LVM can extend a logical volume with any extent on any physical volume in the volume group.

Reducing A Logical Volume

  1.     # umount /mnt/newsystem/usr
        # resize_reiserfs -s -900M /dev/newsystem/usr
        # lvreduce -L -800M /dev/newsystem/usr
        # resize_reiserfs /dev/newsystem/usr
        # mount /mnt/newsystem/usr/
        # df -h
        # pvs
        

Removing (Physical) Partitions

We should be able to do this:

  1. If necessary, shrink some more
        # umount /mnt/newsystem/usr
        # resize_reiserfs -s -900M /dev/newsystem/usr
        # lvreduce -L -800M /dev/newsystem/usr
        # resize_reiserfs /dev/newsystem/usr
        # mount /mnt/newsystem/usr/
        # df -h
        # pvs
        
  2.     # pvmove -v /dev/hde13
        

But it uses a temporary snapshot to do it, and guess what doesn't work yet?

Snapshotting and Backups

LVM and RAID

Booting From LVM (/boot on LVM)

root On LVM

The Problem With Root-On-LVM

Alternatives to LVM

Right now, LVM seems like the best alternative. But on the horizon: