Use LVM to combine multiple data disks or partitions into a dynamically expandable storage pool and carve out logical volumes for use.
How it works
Creating a logical volume (LV) involves four steps:
-
Create a physical volume (pvcreate): Mark a data disk for LVM use.
-
Create a volume group (vgcreate): Combine PVs into a storage pool.
-
Create a LV (lvcreate): Carve out a logical partition from the volume group (VG).
-
Create and mount a file system (mkfs & mount): Format the LV and mount it to an access path.
In this example, two 40 GiB data disks (/dev/vdb and /dev/vdc) are initialized as PVs and added to a VG named vg_01, forming an 80 GiB storage pool. A 55 GiB LV named lv01 is carved from the pool.
Procedure
Step 1: Create a PV
Creating a PV erases all data on the disk. Back up data before proceeding.
-
Log on to the ECS instance.
-
Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.
-
On the instance details page, click Connect > Workbench and log on to the terminal.
-
-
Install the LVM tool.
Alibaba Cloud Linux and CentOS
sudo yum install -y lvm2Debian and Ubuntu
sudo apt-get install -y lvm2 -
Run
sudo lsblk -fto find the target device names.sudo lsblk -fNAME FSTYPE LABEL UUID MOUNTPOINT vda ├─vda1 ├─vda2 vfat 7938-FA03 /boot/efi └─vda3 ext4 root 33b46ac5-7482-4aa5-8de0-60ab4c3a4c78 / vdb vdc vdd └─vdd1-
If the
FSTYPEcolumn is not empty, the device is already initialized and cannot be used as a PV. -
If the
FSTYPEcolumn is empty:-
If the device has no partitions, use the device name directly. Example:
vdb→vdb,vdc→vdc. -
If the device has partitions, use the partition name. Example:
vdd→vdd1.
-
-
-
Create the PVs.
Replace
<target_device_name>with the device names from the previous step. Separate names with spaces.sudo pvcreate /dev/<target device name>.../dev/<target device name>Example: to use
vdbandvdc, runsudo pvcreate /dev/vdb /dev/vdc. This creates two 40 GiB PVs.Output containing
successfully createdconfirms success.
Step 2: Create a VG
-
Create the VG.
Replace
<vg_name>with a custom name and<target_device_name>with the device names from Step 1.sudo vgcreate <vg_name> /dev/<target device name>.../dev/<target device name>Example: to create VG
vg_01withvdbandvdc, run:sudo vgcreate vg_01 /dev/vdb /dev/vdc.Output containing
successfully createdconfirms success. -
Check the VG's free space.
Run
sudo vgs. Note theVFreecolumn, which shows the remaining capacity.sudo vgs
Step 3: Create a LV
-
Create the LV.
sudo lvcreate -L <lv_size> -n <lv_name> <vg_name>Example: to create LV
lv01(55 GiB) from VGvg_01, run:sudo lvcreate -L 55g -n lv01 vg_01.Parameter
Description
<lv_size>Must not exceed the VG free space.
<lv_name>A custom name for the new LV.
<vg_name>The name of the VG you created.
Output
Logical volume "<lv_name>" createdconfirms success. -
View the LV information.
Run
sudo lvdisplay. Note theLV Pathfor use in the next step.sudo lvdisplay--- Logical volume --- LV Path /dev/vg_01/lv01 LV Name lv01 VG Name vg_01 LV UUID NgcCdz-efSY-vCrm-E35b-Dg6p-LNYq-xxxxxx LV Write Access read/write LV Creation host, time iZbp13kehgn0kh64txxxxxx, 2025-09-15 16:57:21 +0800 LV Status available # open 0 LV Size 55.00 GiB Current LE 14080 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0In this example, the
LV Pathforlv01is/dev/vg_01/lv01.
Step 4: Create and mount a file system
-
Create a file system.
ext4 handles small files better than xfs.
ext4
-
Create an ext4 file system.
Replace
<lv_path>with the LV Path from Step 3.sudo mkfs -t ext4 <lv_path>Example: LV Path
/dev/vg_01/lv01→ runsudo mkfs -t ext4 /dev/vg_01/lv01. -
Verify the creation.
Run
sudo lsblk -f. IfFSTYPEshowsext4, the file system was created.
xfs
-
Install the xfsprogs tool.
-
For Alibaba Cloud Linux and CentOS:
sudo yum install -y xfsprogs -
For Debian and Ubuntu:
sudo apt-get install -y xfsprogs
-
-
Create an xfs file system.
Replace
<lv_path>with the LV Path from Step 3.sudo mkfs -t xfs <lv_path>Example: LV Path
/dev/vg_01/lv01→ runsudo mkfs -t xfs /dev/vg_01/lv01. -
Verify the creation.
Run
sudo lsblk -f. IfFSTYPEshowsxfs, the file system was created.
-
-
Create a mount point and mount the file system.
sudo mkdir <mount point> && sudo mount <lv_path> <mount point>Parameter
Description
<lv_path>The LV Path from Step 3.
<mount point>A custom, empty directory path that starts with
/. Mounting to a non-empty directory hides its original contents, which can disrupt services and make the original files inaccessible.Example: mount
/dev/vg_01/lv01to/mnt/lv01:sudo mkdir /mnt/lv01 && sudo mount /dev/vg_01/lv01 /mnt/lv01. -
Check if the file system is mounted successfully.
Run
sudo lsblk. If the target device shows a value in theMOUNTPOINTcolumn, the mount succeeded.ImportantThis mount is temporary and lost after a reboot. To persist the mount, configure automatic mounting at startup.
FAQ
-
How do I add a new PV to an existing VG?
-
Log on to the ECS instance.
-
Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target resource.
-
On the instance details page, click Connect > Workbench.
-
-
View PV and VG information.
-
View PVs.
Run
sudo pvdisplay. Record the PV name from thePV Namefield. -
View existing VGs.
Run
sudo vgs. Record the VG name from theVGfield.
-
-
Add other created PVs.
Replace
<vg_name>and<pv_name>with the values from the previous step.sudo vgextend <vg_name> <pv_name>...<pv_name>
-
-
Why do I get a "404 Not Found" error when installing tools?
Cause : This error occurs because CentOS 6 and Debian 9/10/11 have reached their End-of-Life (EOL), and their default package repositories are no longer active.
Solution : You must update your system's repository source to point to an official archive server. After updating the source, you can run the installation command again.
-
For CentOS 6, follow the guide to switch the CentOS repository source.
-
For Debian 9/10/11, follow the guide to switch the Debian repository source.
-
-
What does my LV mount information is missing after a reboot, and how do I fix it?
Cause: The volume was mounted manually without an entry in
/etc/fstab, which controls automatic mounts at boot.Solution:
-
Mount the file system manually if not already mounted. See Step 4.
-
Configure automatic mounting at startup by adding an entry to
/etc/fstab.
-
-
When running
lvcreate, why do I get the error "Volume group "vg01" has insufficient free space (23038 extents): 51200 required." when creating a LV?Cause: The specified LV size (
-L <lv_size>) exceeds the free space in VGvg_01.Solution:
-
Run
sudo vgsand note theVFreevalue. -
Re-run
lvcreatewith a size within the available free space.
-
References
If your LV runs out of space, use lvextend to extend the LV.