Logical Volume Manager (LVM) creates a logical layer over your disks or partitions to divide them into physical extent (PE) units with the same size. This categorizes disks or partitions into a volume group (VG), on which you can create a logical volume (LV), and then create file systems on the LV.
Different from direct disk partitioning, LVM allows elastic scaling of file system.
Note:The following example uses three elastic cloud disks to create a dynamically resizable file system through LVM.
pvcreate <disk path 1> ... <disk path N>
Taking /dev/vdc
, /dev/vdd
and /dev/vde
disks as an example, run the following command.pvcreate /dev/vdc /dev/vdd /dev/vde
The result of a successful creation is shown below:lvmdiskscan | grep LVM
vgcreate [-s <specified PE size>] <VG name> <PV path>.
Take creating a VG named lvm_demo0
as an example, run the following command:vgcreate lvm_demo0 /dev/vdc /dev/vdd
The result of a successful creation is shown below:vgextend [VG name] [Path of the new PV]
The result of a successful addition is shown below:vgs
, vgdisplay
or other commands to query information about VGs of the system, as shown below:lvcreate [-L <LV size>][-n <LV name>] <VG name>.
Take creating an 8 GB logical volume named lv_0
as an example, run the following command:lvcreate -L 8G -n lv_0 lvm_demo0
The result of a successful creation is shown below:Note:Run the
pvs
command. You can see that only the capacity of the/dev/vdc
disk is reduced by 8 GB, as shown below:
Run the following command to create a file system on an existing LV.
mkfs.ext3 /dev/lvm_demo0/lv_0
Run the following command to create the mount point /vg0
.
mkdir /vg0
Run the following command to mount the file system.
mount /dev/lvm_demo0/lv_0 /vg0
The result of a successful mount is shown below:
Note:LVs can be extended dynamically only when the VG capacity is not used up. After increasing the LV capacity, you need to extend the file system created on this LV.
lvextend [-L +/- <scale capacity>] <LV path>
Take extending the LV named lv_0
by 4 GB as an example, run the following command:lvextend -L +4G /dev/lvm_demo0/lv_0
The result of a successful extension is shown below:Note:Run the
pvs
command. You can find that the/dev/vdc
disk capacity has been fully used, and the/dev/vdd
disk capacity has been used by 2 GB, as shown below:
resize2fs /dev/lvm_demo0/lv_0
The result of a successful extension is shown below:df -h
Was this page helpful?