LVM (Logical Volume Manager)
What is LVM?
LVM (Logical Volume Manager) is a logical volume manager for Linux systems that allows you to manage disk storage flexibly and dynamically.
With LVM, you can combine physical disks into logical volumes and easily resize or reorganize disk space as needed. This provides greater flexibility compared to traditional fixed disk partitioning and simplifies storage management.
———–
Key Components of LVM
VM consists of three main components:
Physical Volumes (PV): These are your physical disks or partitions (e.g., /dev/sda1) and serve as the building blocks for LVM.
Volume Groups (VG): Created by combining one or more PVs, a VG acts as a logical storage pool. This allows the system to manage multiple disks as a single unit.
Logical Volumes (LV): These are the flexible units created from a VG’s available space. LVs behave like normal partitions and can host filesystems. Their sizes can be easily adjusted as needed.
Unlike tools like cfdisk that create fixed partitions, LVM allows you to grow, shrink, or combine storage without the usual limitations of static partitioning.
Consider a scenario where your disk has three partitions: two independent ones and some unallocated free space.
If you want to resize the middle partition, you can do so using the free space.
But if you want to resize the first partition at the beginning, and there’s no free space beside it, you cannot do it directly. You’d have to shrink another partition first.

With LVM, when you want to grow a beginning LV, it can allocate free space dynamically and attach it to that LV. By combining multiple disks into a single logical volume, you can manage storage as if it were one large disk, offering unmatched flexibility.

For example, considering 5G of disks waiting to be attached to your system

Suppose we attach three 5GB virtual disks to our system.
LVM SETUP
Installing LVM Tools
sudo apt install lvm2
Scanning for Physical Volumes
sudo lvmdiskscan
/dev/sda2 [ 2.00 GiB]
/dev/sda3 [ <43.00 GiB]LVM physical volume
/dev/sdb1 [ 4.00 GiB]
/dev/sdb2 [ 4.00 GiB]
/dev/sdb3 [ <2.00 GiB]
/dev/sdc [ 5.00 GiB] >> yeni
/dev/sdd [ 5.00 GiB] >> yeni
/dev/sde [ 5.00 GiB] >> yeni
3 disks 4 partitions
1 LVM physical volume whole disk
Here, /dev/sda3 was automatically created as an LVM PV.
Creating Physical Volumes
Add the new disks as LVM physical volumes:
sudo pvcreate /dev/sdc /dev/sdd
Sample output:
sudo pvs
PV VG Fmt. Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- <43.00g. 21.50g
/dev/sdc lvm2 --- 5.00g 5.00g
/dev/sdd lvm2 --- 5.00g 5.00g
Combine multiple PVs into a VG:
sudo vgcreate my_volume /dev/sdc /dev/sdd
Volume group “my_volume” successfully created
You can later extend the VG with additional PVs using vgextend command:
sudo pvcreate /dev/sde
sudo vgextend my_volume /dev/sde
Volume Group “my_volume” successfully extended
Output confirms the VG now has ~15GB of space.
sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 5 0 wz--n- <43.00g 21.50g
my_volume 3 0 0 wz--n- 14.99g 14.99g
You can also use reduce command to remove your pvs from volume group
sudo vgreduce my_volume /dev/sde
If you want your pvs completely out of the lvm platform:
sudo pvremove /dev/sde
Create LVs from the VG:
sudo lvcreate —-size 2G —-name partition1 my_volume
Logical volume “partition1” created.
List your vg
sudo vgs
VG #PV #LV #SN. Attr VSize VFree
ubuntu-vg 2 1 0 wz--n- <43.00g 21.50g
my_volume 2 1 0 wz--n- 9.99g 7.99g
sudo lvcreate —-size 6G —-name partition2 my_volume
sudo vgs
VG #PV #LV #SN. Attr VSize VFree
ubuntu-vg 2 1 0 wz--n- <43.00g 21.50g
my_volume 2 2 0 wz--n- 9.99g 1.99g
sudo lvs
LV VG Attr LVM2_VERSION LVM2_FEATURES Size Pool Origin Data
partition1 my_volume -wi-ao---- 2 metadata,thinpool 2.00g
partition2 my_volume -wi-ao---- 2 metadata,thinpool 6.00g
ubuntu-lv ubuntu_vg -wi-ao---- 2 metadata,thinpool <21.50g
partition1 and partition2 now occupy a total of 8GB.
The remaining 1.99GB is free and can be added to any LV using:
sudo lvresize —-extents 100%VG my_volume/partition1
reducing 100%VG to remaining free space 3.99 GiB in VG.
Size of logical volume my_volume/partition1 changed from 2.00 Gib to 3.99 Gib
Logical volume my_volume/partition1 successfully resized.
sudo lvs
LV VG Attr LVM2_VERSION LVM2_FEATURES Size Pool Origin Data Segments
partition1 my_volume -wi-ao---- 2 metadata,thinpool 3.99g
partition2 my_volume -wi-ao---- 2 metadata,thinpool 6.00g
ubuntu-lv ubuntu_vg -wi-ao---- 2 metadata,thinpool <21.50g
To reduce LV size:
sudo lvresize —-size 2GB my_volume/partition1
WARNING: Reducing active logical volume to 2.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce my_volume/partition1? [y/n]: y Size of logical volume my_volume/partition1 changed from 3.99 GiB (1022 extents) to 2.00 GiB (512 extents). Logical volume my_volume/partition1 successfully resized.
To create a filesystem on an LV:
dev/name-of-volume-group/name-of-logical-volume considered as the syntax
sudo mkfs.ext4 /dev/my_volume/partition1
mke2fs 1.45.5 (03-Oct-2024) Creating filesystem with 524288 4k blocks and 131072 inodes Filesystem UUID: c0f5d6e9-09b6-4a2f-9b57-e7d536e1f7e2 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
Important Note: Since partition1 is now mounted with an ext4 filesystem, if you want to resize it, you need to use the –resizefs option along with –size.
This will resize the logical volume and automatically adjust the filesystem to the new size (e.g., 3GB) in a single step.
sudo lvresize —resizefs —size 3G my_volume/partition1
To remove an LV:
sudo lvremove my_volume/partition1
Summary: LVM Advantages
LVM makes disk management in Linux flexible and dynamic. By combining multiple physical disks into a single logical unit, you can:
- Easily grow or shrink storage.
- Manage multiple disks as one logical volume.
- Create multiple LVs within a VG for different use cases.
This flexibility is particularly useful for resizing partitions or expanding disk capacity without downtime or complicated procedures.