The Rigidity of Traditional Partitions
When provisioning a traditional Ubuntu server, administrators allocate specific chunks of the hard drive to different filesystems—for example, 20GB for the root / filesystem, and 100GB for a database in /var/lib/mysql.
If the database grows exponentially and fills the 100GB partition, you face a critical infrastructure crisis. With traditional partitions (standard fdisk or parted layouts), extending that partition often requires rebooting the server into a Live CD, completely unmounting the drive, and painstakingly moving partition boundaries. This requires significant downtime, which is unacceptable for production environments.
To completely eliminate this rigidity, modern Linux distributions utilize the Logical Volume Manager (LVM). LVM adds an abstraction layer between the physical hard drives and the filesystem. Instead of formatting a physical disk directly, LVM pools multiple physical disks into a single “Volume Group,” from which you carve out dynamic “Logical Volumes.” If you run out of space, you simply plug in a new hard drive, add it to the Volume Group, and expand the Logical Volume on the fly—without ever unmounting the filesystem or rebooting the server.
Step 1: Understanding the LVM Architecture
LVM operates on three distinct tiers:
- Physical Volumes (PV): The actual raw hard drives or standard partitions (e.g.,
/dev/sdb). - Volume Groups (VG): A massive pool of storage created by combining one or more Physical Volumes (e.g.,
vg_data). - Logical Volumes (LV): The virtual partitions carved out of the Volume Group (e.g.,
lv_mysql). These are what you actually format (with ext4 or xfs) and mount to the system.
Step 2: Adding a New Physical Hard Drive
Suppose your database Logical Volume is full. You have attached a brand new 50GB virtual hard drive (or physically inserted an SSD) to the server. The OS recognizes it as /dev/sdc.
First, you must convert this raw disk into an LVM Physical Volume:
sudo pvcreate /dev/sdc
The terminal will return: Physical volume "/dev/sdc" successfully created.
Step 3: Extending the Volume Group
Next, you must add this new Physical Volume to your existing Volume Group to increase the total available storage pool.
To view your current Volume Groups, run:
sudo vgdisplay
Assume your volume group is named ubuntu-vg. Extend it by adding the new disk:
sudo vgextend ubuntu-vg /dev/sdc
The total capacity of ubuntu-vg has now increased by 50GB. The storage is available, but it is not yet allocated to the database.
Step 4: Extending the Logical Volume
Now you must allocate that newly pooled free space to the specific Logical Volume that is running out of space.
To view your current Logical Volumes, run:
sudo lvdisplay
Assume the logical volume you want to expand is /dev/ubuntu-vg/lv_mysql. To extend it by exactly 20GB, run:
sudo lvextend -L +20G /dev/ubuntu-vg/lv_mysql
If you want to allocate all of the remaining free space in the Volume Group to this logical volume, use the extent (-l) flag instead:
sudo lvextend -l +100%FREE /dev/ubuntu-vg/lv_mysql
LVM will instantly resize the block device.
Step 5: Resizing the Filesystem (Zero Downtime)
This is the most critical step. Even though the underlying Logical Volume block device is now 20GB larger, the filesystem (ext4 or xfs) sitting on top of it doesn’t know about the new space yet. You must instruct the filesystem to stretch into the newly available blocks.
Crucially, you do not need to unmount the drive or stop the database. Both ext4 and xfs support online resizing.
If the filesystem is ext4, use the resize2fs command on the logical volume path:
sudo resize2fs /dev/ubuntu-vg/lv_mysql
If the filesystem is xfs, you do not use the logical volume path; instead, you run xfs_growfs against the directory where it is actively mounted:
sudo xfs_growfs /var/lib/mysql
Run df -h to verify the changes. You will see that your filesystem has instantly grown by 20GB, while the server and its applications continued running without a single dropped packet.
Conclusion
The Logical Volume Manager is an indispensable component of enterprise Linux engineering. By completely abstracting the filesystem from the physical hardware boundaries, LVM empowers Ubuntu administrators to dynamically react to storage crises, seamlessly pooling new drives and expanding critical databases with absolute zero downtime.