The Benefits of Using Linux Logical Volume Manager
This is the first of a three-part series, designed to introduce new users to the concept of logical volume management in Linux. To have the others delivered automatically to you, you may subscribe to our RSS feed by clicking on the RSS icon diagonally above this paragraph
Logical Volume Management is a method of partitioning hard disk drives that provides more flexibility in managing storage space than the traditional method of disk partitioning. The Linux version, Logical Volume Manager or LVM, has been a feature of the Linux kernel since about 1999, and was contributed (to the Linux kernel) by Sistina Software, Inc, a company that was later acquired by Redhat.
Other UNIX-like operating systems – AIX, HP-UX, and Sun Solaris – have their own implementation of logical volume management. Until recently, there was no equivalent technology – feature-wise – in the BSD distributions. FreeBSD only recently added experimental support for Zone File System (ZFS), a recent Sun Solaris technology with LVM-like features as a subset of its capability.
Other UNIX-like operating systems – AIX, HP-UX, and Sun Solaris – have their own implementation of logical volume management. Until recently, there was no equivalent technology – feature-wise – in the BSD distributions. FreeBSD only recently added experimental support for Zone File System (ZFS), a recent Sun Solaris technology with LVM-like features as a subset of its capability.
In the early days, the installers of all three major distros – Fedora (was Redhat), openSUSE (was known as SUSE at the time), and Mandriva (was known as Mandrake back then) had support for LVM (and RAID). Today, only a handful of distros gives you the ability to configure LVM during installation. Some distros have support for LVM in their server distribution, but not in their desktop edition. We think that LVM is a technology that all distros – desktop or server – should configure by default, especially since it is already a part of the Linux kernel.
Using LVM has many benefits, but we are only going to address the very basic benefit of (using) LVM for the home user in this article. To get a better understanding of the benefits of using LVM, let’s take a brief overview of the traditional method of disk partitioning in Linux.
Using the traditional disk partitioning method, a hard disk may be partitioned into a maximum of four primary partitions. Alternatively, you may create less than four (primary) partitions, and one or more extended partitions, with each extended partition holding as many as 16 logical partitions. For this example, let’s consider the scenario where four primary partitions are created on a computer with a 40 GB hard disk:
Using the traditional disk partitioning method, a hard disk may be partitioned into a maximum of four primary partitions. Alternatively, you may create less than four (primary) partitions, and one or more extended partitions, with each extended partition holding as many as 16 logical partitions. For this example, let’s consider the scenario where four primary partitions are created on a computer with a 40 GB hard disk:
- Primary partition 1 – /var (500 MB)
- Primary partition 2 – / (the root file system – 1.5 GB)
- Primary partition 3 – /usr (2 GB)
- Primary partition 4 – /home (27.5 GB)
Under this partitioning scheme, the sum of the partitions sizes must equal the size of the hard disk, i.e, the free space on the disk must be completely allocated. If not, the unallocated space will be unusable by the system. Now what happens if, for example, you run out of space in /home (partition 3)? There are solutions. You could, for instance, attach a new disk to the system, create a much larger /home partition in the new disk, and copy the contents of the existing /home to the new one. It works, but not very flexible, and a pain to pull off.
Now, let’s consider the same example, using the same 40 GB hard disk with LVM as the partitioning scheme.
To configure LVM, these are the steps involved:
- Starting with a hard disk drive, create a physical volume – PV
- Create a volume group – VG. A volume group is a virtual container for one or more physical volumes (hard disks)
- Add physical volume to volume group. The size of the VG equals the size of the PV, or the sum of the PVs, if more than one
- Create logical volumes. A logical volume, LV, is the LVM equivalent of a partition
- Assign filesystems to logical volumes
With LVM, it is not necessary to allocate all the available free space to the logical volumes. In fact, it is recommended that you only assign enough space that is needed to each logical volume. So using the 40 GB disk example, and the creating four logical volumes as in the example above, we have:
- Logical volume 1 – /var (200 MB)
- Logical volume 2 – / (the root file system – 1 GB)
- Logical volume 3 – /usr (5 GB)
- Logical volume 4 – /home (7 GB)
Notice that the sum of the storage space allocated to the logical volumes is less than the size of the VG. The unallocated space is still available and usable by the system. Now, what happens if, for example, you run out of space in logical volume 3, housing /home? This is where LVM shines. All you need to do is allocate more space (resize upwards) to the logical volume by taking some of the VG’s free space. Depending on the file system in use, you may increase the size of a logical volume while it is online or offline. By “online or offline”, we mean that the logical volume may be resized without first unmounting it or after it has been unmounted. Reiserfs and XFS allows online resizing, but Ext3, the default journaling file system in most Linux distros, requires that a logical volume be unmounted before it can be resized.
We should point out that you may also choose to resize downwards or shrink a logical volume. However, this should never need to happen if LVM is well implemented. Shrinking a logical volume is hazardous. It could lead to loss of data. One of the most important points you should remember when configuring LVM is that you should only allocate just enough space to each logical volume, that the system needs to run. You can always increase the size of a logical volume at any time.
Beyond the ability to resize a logical volume, let’s consider a situation where all the free space in the volume group is allocated. What then? Easy. You just attach a new disk (external or internal) to the system, make it a physical volume, assign it to the volume group, and – voila! – you have more free space to use. It’s so easy and so helpful for storage management, it’s difficult to fathom why most Linux desktop distros are shunning it. We do know that some distro developers have no idea what LVM is. It’s hard to believe, but it’s true.
There are more advanced benefits of using LVM that we did not touch in the article, but the ability to dynamically resize a disk partition (logical volume) is one that we think will be of special interest to most new users.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.