Help Center> Elastic Volume Service> Best Practices> Using LVM to Manage EVS Disks> Implementation Procedure> Extending the Logical Volume Using the Unallocated Space
Updated on 2024-05-30 GMT+08:00

Extending the Logical Volume Using the Unallocated Space

Scenarios

If the logical volume space becomes insufficient, you can extend the logical volume. This section shows how to add 4 GB space to a 15 GB logical volume, which no longer meets requirements.

During the extension, ensure that the volume group has sufficient available space to extend the logical volume. If the volume group's available space is also insufficient, extend the volume group according to Extending the Logical Volume by Expanding Capacity of an EVS Disk or Extending the Volume Group by Adding an EVS Disk.

Procedure

  1. Log in to the ECS as user root.
  2. Run the following command to extend the logical volume:

    lvextend -L +Additional capacity Logical volume path

    Parameter description:

    • Additional capacity: Specify a value smaller than the volume group's available space, either in MB or GB.
    • Logical volume path: Specify the path of the to-be-extended logical volume.

    In this example, run the following command:

    lvextend -L +4GB /dev/vgdata/lvdata1

    Information similar to the following is displayed:

    [root@ecs-lvmtest ~]# lvextend -L +4GB /dev/vgdata/lvdata1
      Size of logical volume vgdata/lvdata1 changed from 15.00 GiB (3840 extents) to 19.00 GiB (4864 extents).
      Logical volume vgdata/lvdata1 successfully resized.

    This step only extends the logical volume. You also need to extend the size of the file system on this volume.

  3. Run the following command to extend the size of the file system:

    resize2fs Logical volume path

    In this example, run the following command:

    resize2fs /dev/vgdata/lvdata1

    Information similar to the following is displayed:

    [root@ecs-lvmtest ~]# resize2fs /dev/vgdata/lvdata1
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/vgdata/lvdata1 is mounted on /Data1; on-line resizing required
    old_desc_blocks = 4, new_desc_blocks = 28
    The filesystem on /dev/vgdata/lvdata1 is now 3657728 blocks long.

  4. Run the following command to check whether the file system size increases:

    df -h

    Information similar to the following is displayed:

    [root@ecs-lvmtest ~]# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/vda2                    39G  1.5G   35G   5% /
    devtmpfs                    487M     0  487M   0% /dev
    tmpfs                       496M     0  496M   0% /dev/shm
    tmpfs                       496M  6.7M  490M   2% /run
    tmpfs                       496M     0  496M   0% /sys/fs/cgroup
    /dev/vda1                   976M  131M  779M  15% /boot
    tmpfs                       100M     0  100M   0% /run/user/0
    /dev/mapper/vgdata-lvdata1   19G   44M   18G   1% /Data1

    In the command output, the size of file system /dev/mapper/vgdata-lvdata1 increases by 4 GB.