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** .. code-block:: bash :linenos: # Pick a disk from the list. For this example, we will use /dev/sdb cat /proc/partitions # Set our variables for the example mydisk=/dev/sdb # we do not want to rely on a particular disk order namespace=squirrel # this is just an example name partname=data # this is also an example fstype=ext4 # alternately, xfs or anything you like # Prepare a physical volume /usr/sbin/pvcreate ${mydisk} # Create a volume group. Think of this as a namespace. /usr/sbin/vgcreate ${namespace} ${mydisk} # Create a logical volume in that volume group. # 100%FREE is a special size that fills all available space /usr/sbin/lvcreate -n ${partname} -l 100%FREE ${namespace} # Create a file system on that logical volume mkfs.${fstype} /dev/${namespace}/${partname} # Mount the logical volume where you want it to be mount /dev/${namespace}/${partname} /mnt # Make that mount appear automatically at boot echo "/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.