Chapter 4. LVM Configuration

Contents

4.1. Understanding the Logical Volume Manager
4.2. Creating LVM Partitions
4.3. Creating Volume Groups
4.4. Configuring Physical Volumes
4.5. Configuring Logical Volumes
4.6. Resizing a Volume Group
4.7. Resizing a Logical Volume with YaST
4.8. Resizing a Logical Volume with Commands
4.9. Deleting a Volume Group
4.10. Deleting an LVM Partition (Physical Volume)

This section briefly describes the principles behind Logical Volume Manager (LVM) and its basic features that make it useful under many circumstances. The YaST LVM configuration can be reached from the YaST Expert Partitioner. This partitioning tool enables you to edit and delete existing partitions and create new ones that should be used with LVM.

[Warning]

Using LVM might be associated with increased risk, such as data loss. Risks also include application crashes, power failures, and faulty commands. Save your data before implementing LVM or reconfiguring volumes. Never work without a backup.

4.1. Understanding the Logical Volume Manager

LVM enables flexible distribution of hard disk space over several file systems. It was developed because the need to change the segmentation of hard disk space might arise only after the initial partitioning has already been done during installation. Because it is difficult to modify partitions on a running system, LVM provides a virtual pool (volume group or VG) of memory space from which logical volumes (LVs) can be created as needed. The operating system accesses these LVs instead of the physical partitions. Volume groups can span more than one disk, so that several disks or parts of them can constitute one single VG. In this way, LVM provides a kind of abstraction from the physical disk space that allows its segmentation to be changed in a much easier and safer way than through physical repartitioning.

Figure 4.1, “Physical Partitioning versus LVM” compares physical partitioning (left) with LVM segmentation (right). On the left side, one single disk has been divided into three physical partitions (PART), each with a mount point (MP) assigned so that the operating system can access them. On the right side, two disks have been divided into two and three physical partitions each. Two LVM volume groups (VG 1 and VG 2) have been defined. VG 1 contains two partitions from DISK 1 and one from DISK 2. VG 2 contains the remaining two partitions from DISK 2.

Figure 4.1. Physical Partitioning versus LVM

Physical Partitioning versus LVM

In LVM, the physical disk partitions that are incorporated in a volume group are called physical volumes (PVs). Within the volume groups in Figure 4.1, “Physical Partitioning versus LVM”, four logical volumes (LV 1 through LV 4) have been defined, which can be used by the operating system via the associated mount points. The border between different logical volumes need not be aligned with any partition border. See the border between LV 1 and LV 2 in this example.

LVM features:

  • Several hard disks or partitions can be combined in a large logical volume.

  • Provided the configuration is suitable, an LV (such as /usr) can be enlarged when the free space is exhausted.

  • Using LVM, it is possible to add hard disks or LVs in a running system. However, this requires hot-swappable hardware that is capable of such actions.

  • It is possible to activate a striping mode that distributes the data stream of a logical volume over several physical volumes. If these physical volumes reside on different disks, this can improve the reading and writing performance just like RAID 0.

  • The snapshot feature enables consistent backups (especially for servers) in the running system.

With these features, using LVM already makes sense for heavily used home PCs or small servers. If you have a growing data stock, as in the case of databases, music archives, or user directories, LVM is especially useful. It allows file systems that are larger than the physical hard disk. Another advantage of LVM is that up to 256 LVs can be added. However, keep in mind that working with LVM is different from working with conventional partitions.

Starting from kernel version 2.6, LVM version 2 is available, which is downward-compatible with the previous LVM and enables the continued management of old volume groups. When creating new volume groups, decide whether to use the new format or the downward-compatible version. LVM 2 does not require any kernel patches. It makes use of the device mapper integrated in kernel 2.6. This kernel only supports LVM version 2. Therefore, when talking about LVM, this section always refers to LVM version 2.

You can manage new or existing LVM storage objects by using the YaST Partitioner. Instructions and further information about configuring LVM is available in the official LVM HOWTO.

4.2. Creating LVM Partitions

For each disk, partition the free space that you want to use for LVM as 0x8E Linux LVM. You can create one or multiple LVM partitions on a single device. It is not necessary for all of the partitions on a device to be LVM partitions.

You can use the Volume Group function to group one or more LVM partitions into a logical pool of space called a volume group, then carve out one or more logical volumes from the space in the volume group.

In the YaST Partitioner, only the free space on the disk is made available to you as you are creating LVM partitions. If you want to use the entire disk for a single LVM partition and other partitions already exists on the disk, you must first remove all of the existing partitions to free the space before you can use that space in an LVM partition.

[Warning]

Deleting a partition destroys all of the data in the partition.

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. (Optional) Remove one or more existing partitions to free that space and make it available for the LVM partition you want to create.

    For information, see Section 4.10, “Deleting an LVM Partition (Physical Volume)”.

  4. On the Partitions page, click Add.

  5. Under New Partition Type, select Primary Partition or Extended Partition, then click Next.

  6. Specify the New Partition Size, then click Next.

    • Maximum Size: Use all of the free available space on the disk.

    • Custom Size: Specify a size up the amount of free available space on the disk.

    • Custom Region: Specify the start and end cylinder of the free available space on the disk.

  7. Configure the partition format:

    1. Under Formatting Options, select Do not format.

    2. From the File System ID drop-down list, select 0x8E Linux LVM as the partition identifier.

    3. Under Mounting Options, select Do not mount partition.

  8. Click Finish.

    The partitions are not actually created until you click Next and Finish to exit the partitioner.

  9. Repeat Step 4 through Step 8 for each Linux LVM partition you want to add.

  10. Click Next, verify that the new Linux LVM partitions are listed, then click Finish to exit the partitioner.

  11. (Optional) Continue with the Volume Group configuration as described in Section 4.3, “Creating Volume Groups”.

4.3. Creating Volume Groups

An LVM volume group organizes the Linux LVM partitions into a logical pool of space. You can carve out logical volumes from the available space in the group. The Linux LVM partitions in a group can be on the same or different disks. You can add LVM partitions from the same or different disks to expand the size of the group. Assign all partitions reserved for LVM to a volume group. Otherwise, the space on the partition remains unused.

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. In the left panel, click Volume Management.

    A list of existing Volume Groups are listed in the right panel.

  4. At the lower left of the Volume Management page, click Add Volume Group.

  5. Specify the Volume Group Name.

    If you are creating a volume group at install time, the name system is suggested for a volume group that will contain the SUSE Linux Enterprise Server system files.

  6. Specify the Physical Extent Size.

    The Physical Extent Size defines the size of a physical block in the volume group. All the disk space in a volume group is handled in chunks of this size. Values can be from 1 KB to 16 GB in powers of 2. This value is normally set to 4 MB.

    In LVM1, a 4 MB physical extent allowed a maximum LV size of 256 GB because it supports only up to 65534 extents per LV. VM2 does not restrict the number of physical extents. Having a large number of extents has no impact on I/O performance to the logical volume, but it slows down the LVM tools.

    [Important]

    Different physical extent sizes should not be mixed in a single VG. The extent should not be modified after the initial setup.

  7. In the Available Physical Volumes list, select the Linux LVM partitions that you want to make part of this volume group, then click Add to move them to the Selected Physical Volumes list.

  8. Click Finish.

    The new group appears in the Volume Groups list.

  9. On the Volume Management page, click Next, verify that the new volume group is listed, then click Finish.

4.4. Configuring Physical Volumes

When the Linux LVM partitions are assigned to a volume group, the partitions are then referred to as a physical volumes.

Figure 4.2. Physical Volumes in the Volume Group Named Home

Physical Volumes in the Volume Group Named Home

To add more physical volumes to an existing volume group:

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. In the left panel, select Volume Management and expand the list of groups.

  4. Under Volume Management, select the volume group, then click the Overview tab.

  5. At the bottom of the page, click Resize.

  6. Select a physical volume (LVM partitions) from the Available Physical Volumes list then click Add to move it to the Selected Physical Volumes list.

  7. Click Finish.

  8. Click Next, verify that the changes are listed, then click Finish.

4.5. Configuring Logical Volumes

After a volume group has been filled with physical volumes, use the Logical Volumes dialog (see Figure 4.3, “Logical Volume Management”) to define and manage the logical volumes that the operating system should use. This dialog lists all of the logical volumes in that volume group. You can use Add, Edit, and Remove options to manage the logical volumes. Assign at least one logical volume to each volume group. You can create new logical volumes as needed until all free space in the volume group has been exhausted.

Figure 4.3. Logical Volume Management

Logical Volume Management

It is possible to distribute the data stream in the logical volume among several physical volumes (striping). If these physical volumes reside on different hard disks, this generally results in a better reading and writing performance (like RAID 0). However, a striping LV with n stripes can only be created correctly if the hard disk space required by the LV can be distributed evenly to n physical volumes. For example, if only two physical volumes are available, a logical volume with three stripes is impossible.

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. In the left panel, select Volume Management and expand it to see the list of volume groups.

  4. Under Volume Management, select the volume group, then click the Logical Volumes tab.

  5. In the lower left, click Add to open the Add Logical Volume dialog.

  6. Specify the Name for the logical volume, then click Next.

  7. Specify the size of the volume and whether to use multiple stripes.

    1. Specify the size of the logical volume, up to the maximum size available.

      The amount of free space in the current volume group is shown next to the Maximum Size option.

    2. Specify the number of stripes.

      [Warning]

      YaST has no chance at this point to verify the correctness of your entries concerning striping. Any mistake made here is apparent only later when the LVM is implemented on disk.

  8. Specify the formatting options for the logical volume:

    1. Under Formatting Options, select Format partition, then select the format type from the File system drop-down list, such as Ext3.

    2. Under Mounting Options, select Mount partition, then select the mount point.

      The files stored on this logical volume can be found at this mount point on the installed system.

    3. Click Fstab Options to add special mounting options for the volume.

  9. Click Finish.

  10. Click Next, verify that the changes are listed, then click Finish.

4.6. Resizing a Volume Group

You can add and remove Linux LVM partitions from a volume group to expand or reduce its size.

[Warning]

Removing a partition can result in data loss if the partition is in use by a logical volume.

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. In the left panel, select Volume Management and expand it to see the list of volume groups.

  4. Under Volume Management, select the volume group, then click the Overview tab.

  5. At the bottom of the page, click Resize.

  6. Do one of the following:

    • Add: Expand the size of the volume group by moving one or more physical volumes (LVM partitions) from the Available Physical Volumes list to the Selected Physical Volumes list.

    • Remove: Reduce the size of the volume group by moving Lone or more physical volumes (LVM partitions) from the Selected Physical Volumes list to the Available Physical Volumes list.

  7. Click Finish.

  8. Click Next, verify that the changes are listed, then click Finish.

4.7. Resizing a Logical Volume with YaST

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. In the left panel, select Volume Management and expand it to see the list of volume groups.

  4. Under Volume Management, select the volume group, then click the Logical Volumes tab.

  5. At the bottom of the page, click Resize to open the Resize Logical Volume dialog.

  6. Use the slider to expand or reduce the size of the logical volume.

    [Warning]

    Reducing the size of a logical volume that contains data can cause data corruption.

  7. Click OK.

  8. Click Next, verify that the change is listed, then click Finish.

4.8. Resizing a Logical Volume with Commands

The lvresize, lvextend, and lvreduce commands are used to resize logical volumes. See the man pages for each of these commands for syntax and options information.

You can also increase the size of a logical volume by using the YaST Partitioner. YaST uses parted(8) to grow the partition.

To extend an LV there must be enough unallocated space available on the VG.

LVs can be extended or shrunk while they are being used, but this may not be true for a file system on them. Extending or shrinking the LV does not automatically modify the size of file systems in the volume. You must use a different command to grow the file system afterwards. For information about resizing file systems, see Chapter 5, Resizing File Systems.

Make sure you use the right sequence:

  • If you extend an LV, you must extend the LV before you attempt to grow the file system.

  • If you shrink an LV, you must shrink the file system before you attempt to shrink the LV.

To extend the size of a logical volume:

  1. Open a terminal console, log in as the root user.

  2. If the logical volume contains file systems that are hosted for a virtual machine (such as a Xen VM), shut down the VM.

  3. Dismount the file systems on the logical volume.

  4. At the terminal console prompt, enter the following command to grow the size of the logical volume:

    lvextend -L +size /dev/vgname/lvname
    

    For size, specify the amount of space you want to add to the logical volume, such as 10GB. Replace /dev/vgname/lvname with the Linux path to the logical volume, such as /dev/vg1/v1. For example:

    lvextend -L +10GB /dev/vg1/v1
    

For example, to extend an LV with a (mounted and active) ReiserFS on it by 10GB:

lvextend −L +10G /dev/vgname/lvname
resize_reiserfs −s +10GB −f /dev/vg−name/lv−name

For example, to shrink an LV with a ReiserFS on it by 5GB:

umount /mountpoint−of−LV
resize_reiserfs −s −5GB /dev/vgname/lvname
lvreduce /dev/vgname/lvname
mount /dev/vgname/lvname /mountpoint−of−LV

4.9. Deleting a Volume Group

[Warning]

Deleting a volume group destroys all of the data in each of its member partitions.

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. In the left panel, select Volume Management and expand the list of groups.

  4. Under Volume Management, select the volume group, then click the Overview tab.

  5. At the bottom of the page, click Delete, then click Yes to confirm the deletion.

  6. Click Next, verify that the deleted volume group is listed (deletion is indicated by a red colored font), then click Finish.

4.10. Deleting an LVM Partition (Physical Volume)

[Warning]

Deleting a partition destroys all of the data in the partition.

  1. Log in as the root user, then open YaST.

  2. In YaST, open the Partitioner.

  3. If the Linux LVM partition is in use as a member of a volume group, remove the partition from the volume group, or delete the volume group.

  4. In the YaST Partitioner under Hard Disks, select the device (such as sdc).

  5. On the Partitions page, select a partition that you want to remove, click Delete, then click Yes to confirm the deletion.

  6. Click Next, verify that the deleted partition is listed (deletion is indicated by a red colored font), then click Finish.