Building LVM Logic Volumes with Multiple Elastic Cloud Disks

Last updated: 2020-05-12 15:28:37

    Introduction to LVM

    Logical Volume Manager (LVM) divides your disks or partitions into units of physical extents (PEs) with the same size by creating a logical layer over the disks and partitions. It works by combining different disks or partitions into the same volume group (VG), so that you can create logical volumes (LVs) within the VG, and file systems on the LVs.
    Compared with using disk partitions directly, LVM supports scaling your file systems elastically.

    • The file system is no longer limited by the size of physical disk. Instead, it can be distributed across multiple disks:
      For example, you can purchase 3 elastic cloud disks of 4 TB, and use LVM to create a massive file system up to 12 TB.
    • You can resize the LVs dynamically instead of repartitioning your disks.
      When the LVM VG capacity cannot meet your needs, you can purchase a separate elastic cloud disk to mount on your CVM instance, and scale your VG by adding the cloud disk to it.

    Building LVM

    The following example uses 3 elastic cloud disks to create a dynamically resizable file system through LVM:

    Step 1 Create physical volume (PV)

    1. log In to the Linux CVM as root user.
    2. Run the following command to create PVs:
      pvcreate <disk path 1> ... <disk path N>
      Take /dev/vdc, /dev/vdd and /dev/vde as an example, then run:
      pvcreate /dev/vdc /dev/vdd /dev/vde
      The following figure shows the command output when the creation is successful:
    3. View physical volumes in the current system with the
      lvmdiskscan | grep LVM

    Step 2 Create volume group (VG)

    1. Run the following command to create a volume group:
      vgcreate [-s <specified PE size>] <VG name> <PV path>.
      Assume you want to create a VG named “lvm_demo0”, then run
      vgcreate lvm_demo0 /dev/vdc /dev/vdd
      The following figure shows the command output when the creation is successful:

      When "Volume group" "successfully created" is displayed, your VG has been created successfully.
      • Once created, you can add a new PV to the VG with the
        vgextend VG name New PV path
        The following figure shows the command output when the operation is successful:
      • Once created, you can run vgs, vgdisplay or other commands to view the VG(s) in the current system, as shown below:

    Step 3 Create logical volume (LV)

    1. Run the following command to create a LV:
      lvcreate [-L <LV size>][-n <LV name>] <VG name>.
      Assume you want to create an 8 GB logical volume named "lv_0", then run
      lvcreate -L 8G -n lv_0 lvm_demo0.
      The following figure shows the command output when the creation is successful:

      Run pvs, and you can see that the 8 GB comes solely from the /dev/vdc as shown below:

    Step 4 Create and mount file system

    1. Create a file system on an existing LV using the command
      mkfs.ext3 /dev/lvm_demo0/lv_0.
    2. Mount the file system with the
      mount /dev/lvm_demo0/lv_0 vg0/.
      The following figure shows the command output when the mount is successful:

    Step 5 Perform dynamic scaling on your logical volume and file system

    LVs can be scaled dynamically only when the VG capacity is not fully occupied. When you scale a LV’s capacity, you also need to scale the file system created on this LV.

    1. Scale a LV by running this command
      lvextend [-L +/- <capacity amount>] <LV path>.
      Assume you want to scale up the capacity of LV named “lv_0” by 4 GB, then run
      lvextend -L +4G /dev/lvm_demo0/lv_0.
      The following figure shows the command output when the scaling is successful:

    Run pvs, and you can find that /dev/vdc has been fully used, and 2 G has been used from /dev/vdd as shown below:

    2. Scale the file system with the command

    resize2fs /dev/lvm_demo0/lv_0.

    The following figure shows the command output when the scaling is successful:

    Once completed, you can run the following command to see if the capacity of your LV has been changed to 12 GB:

    df -h

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help