LVM is what lets you treat a pool of disks like one giant, flexible disk, and fdisk is the low-level tool that carves out the initial pieces of that pool.
Let’s see LVM in action. Imagine you have a server with two 1TB disks, /dev/sdb and /dev/sdc, and you want to create a single 2TB logical volume for your application data.
First, we partition the physical disks to make them usable by LVM. We’ll use fdisk for this.
sudo fdisk /dev/sdb
Inside fdisk:
- Type
nfor a new partition. - Type
pfor primary. - Press
Enterto accept the default partition number (1). - Press
Enterto accept the default first sector. - Press
Enterto accept the default last sector (using the whole disk). - Type
tto change the partition type. - Type
8eto set the type to "Linux LVM". - Type
wto write the changes and exit.
Repeat the exact same steps for /dev/sdc. After this, you’ll have /dev/sdb1 and /dev/sdc1, both marked as LVM partitions.
Now, we tell LVM about these partitions by creating physical volumes (PVs).
sudo pvcreate /dev/sdb1 /dev/sdc1
This command registers /dev/sdb1 and /dev/sdc1 as chunks of storage that LVM can manage. You can verify this:
sudo pvdisplay
You should see output showing /dev/sdb1 and /dev/sdc1 as PVs, each with a size of approximately 1TB.
Next, we group these physical volumes into a volume group (VG). Think of a VG as the pool of storage from which you’ll create your logical volumes.
sudo vgcreate my_app_vg /dev/sdb1 /dev/sdc1
Here, my_app_vg is the name we’re giving to our volume group, and it’s comprised of the two PVs we just created. Check it with:
sudo vgdisplay
You’ll see my_app_vg listed, with a total size close to 2TB.
Finally, we create logical volumes (LVs) from the volume group. These are the actual "disks" that your operating system will see and format.
sudo lvcreate -n app_data -l 100%FREE my_app_vg
This command creates a logical volume named app_data within my_app_vg. The -l 100%FREE flag tells LVM to use all available space in the my_app_vg for this logical volume. You can confirm its creation:
sudo lvdisplay
You should see /dev/my_app_vg/app_data (or similar, depending on your LVM setup, it might be /dev/mapper/my_app_vg-app_data). This is your new 2TB logical volume.
Now you can format this LV like any other disk:
sudo mkfs.ext4 /dev/my_app_vg/app_data
And mount it:
sudo mkdir /mnt/app_data
sudo mount /dev/my_app_vg/app_data /mnt/app_data
You now have a single, mountable filesystem at /mnt/app_data that spans both /dev/sdb and /dev/sdc.
The surprising thing about LVM is how it abstracts away the underlying physical disks entirely. You can resize logical volumes on the fly, move them between physical disks, and even take snapshots, all without unmounting the filesystem or interrupting service if done correctly. This flexibility is the core advantage LVM offers over traditional partitioning.
The next step is often learning how to resize these logical volumes or create snapshots.