2025-07-13•Abyan Dimas
Linux Disk Management: The Power of LVM
In the old days, disk partitions (like /dev/sda1) were rigid. If /var filled up and /home was empty, you had to reformat. LVM (Logical Volume Manager) adds a layer of abstraction.
The Hierarchy
- Physical Volume (PV): The actual disk or partition (
/dev/sdb). - Volume Group (VG): A pool of storage created by combining PVs.
- Logical Volume (LV): The virtual partition you actually format and mount (
/dev/mapper/vg-lv_root).
Scenario: Expanding Storage
You add a new 100GB hard drive (/dev/sdc) and want to add it to your root filesystem.
- Initialize PV:
pvcreate /dev/sdc - Extend VG:
vgextend ubuntu-vg /dev/sdc(Adds disk to the pool). - Extend LV:
lvextend -l +100%FREE /dev/ubuntu-vg/root(Give space to partition). - Resize FS:
resize2fs /dev/ubuntu-vg/root(Tell Linux filesystem to use new space).
Done. Online. No reboot required.
Snapshots
LVM allows you to take a "frozen" snapshot of a volume. Ideal for backups: Take snapshot -> Backup snapshot -> Delete snapshot. This ensures the backup is consistent even if the live data changes during the copy process.