Logical Volume Management

Note

Not using lvm in the modern Linux environment requires an explanation.

Why LVM

  • This is especially important when creating cloud-served templates, AMIs, etc. to ensure disk addressability after deployment.

  • LVM allows dynamism not only in size, but specificity in mounts.

  • Disks can reorder, UUIDs might change as you replace disks and drives.

  • LVM allows you to manage your storage with name spaces that stay consistent…

    • …across architectures.

    • …across installations.

    • …across verions.

    • …across operating systems.

  • This is a risk reduction measure that also applies to changing disk allocation requirements.

LVM Basics

  • For this example, we will create…

    • …a disk-filling file system called data

    • …in a namespace called squirrel

    • on physical drive /dev/sdb

    • to mount into /mnt

 1# Pick a disk from the list.  For this example, we will use /dev/sdb
 2cat /proc/partitions
 3# Set our variables for the example
 4mydisk=/dev/sdb # we do not want to rely on a particular disk order
 5namespace=squirrel # this is just an example name
 6partname=data # this is also an example
 7fstype=ext4 # alternately, xfs or anything you like
 8# Prepare a physical volume
 9/usr/sbin/pvcreate ${mydisk}
10# Create a volume group.  Think of this as a namespace.
11/usr/sbin/vgcreate ${namespace} ${mydisk}
12# Create a logical volume in that volume group.
13#  100%FREE is a special size that fills all available space
14/usr/sbin/lvcreate -n ${partname} -l 100%FREE ${namespace}
15# Create a file system on that logical volume
16mkfs.${fstype} /dev/${namespace}/${partname}
17# Mount the logical volume where you want it to be
18mount /dev/${namespace}/${partname} /mnt
19# Make that mount appear automatically at boot
20echo "/dev/${namespace}/${partname} /mnt ext4 rw,defaults 0 0" >> /etc/fstab
  • That is it! You never have to think about whether your disk appeared as /dev/xvfdb, /dev/sdb, or /dev/sdx.