Logical Volume Manager (LVM)
LVM has some terminology that we need to be familiar with to make sense of what is happening.
- There are physical volumes - designated as pv. These are the same as the partitions that we have previously talked about, and are the individual physical partition of the actual disk drives. These are physical block devices are used by LVM as the raw building material for higher levels of abstraction. Physical volumes are regular storage devices. LVM writes a header to the device to allocate it for management.
- Volume groups, which have the vg extension, are physical volumes that LVM combines into storage pools known as volume groups. Volume groups behave as a single logical device with combined storage capacity of the individual physical volumes.
- Last we have the logical volumes, an extension of lv or lvm. The volume groups can be divided up into any number of logical volumes. Logical volumes are basically equivalent to partitions on a physical disk, but they offer much more flexibility. Logical volumes are the primary component that users and applications will interact with. The logical volumes become the mount points that show up in the Linux filesystem.
Using the image to the left, starting at the bottom of the image: we have 3 physical volumes. Let's call them /dev/sda, /dev/sdb and /dev/sdc. In the picture they are referred to as PV - physical volumes. These are the physical disks with partitions created per the discussion in the last section. The first disk has 3 partitions - 1) is assigned as the boot disk for this machine 2) is represented by green and 3) represented by the red. Disk #2 has a single partition which is the entire disk. Finally, disk #3 has two partitions.
The colors in this picture are just to help us. So, the green partition from disk #1 and the green partition from disk #3 are grouped together to create a volume group, which is also a logical volume, which then gets mounted as / (root) on the system. The three red partitions are grouped together in a volume group, and it is used as logical volume and mounted on /home.
Be aware that the volume groups can be broken into multiple logical volumes - in this example though each volume group is used for a single logical volume. The DM-CRYPT shown in the image is some encryption piece that has nothing to do with our discussion.
Advantages of LVM
LVM gives you more flexibility than just using normal hard drive partitions. Some advantages of LVM:
- Use any number of disks as one big disk.
- Have logical volumes stretched over several disks.
- Create small logical volumes and resize them "dynamically" as they get filled up.
- Resize logical volumes regardless of their order on disk. It does not depend on the position of the LV within VG, there is no need to ensure surrounding available space.
- Resize/create/delete logical and physical volumes online. File systems on them still need to be resized, but some (such as ext4) support online resizing.
- Online/live migration of LV being used by services to different disks without having to restart services.
- Snapshots allow you to backup a frozen copy of the file system, while keeping service downtime to a minimum.
- Support for various device-mapper targets, including transparent filesystem encryption and caching of frequently used data. This allows creating a system with (one or more) physical disks (encrypted with LUKS) and LVM on top to allow for easy resizing and management of separate volumes (e.g. for
/backup, etc.) without the hassle of entering a key multiple times on boot.
Disadvantages of LVM
- Additional steps in setting up the system, more complicated. Requires (multiple) daemons to constantly run.
- If dual-booting, note that Windows does not support LVM; you will be unable to access any LVM partitions from Windows.
- If your physical volumes are not on a RAID-1, RAID-5 or RAID-6 losing one disk can lose one or more logical volumes if you span (or extend) your logical volumes across multiple non-redundant disks.