Introduction
Linux Volume Management (LVM) is a device mapper framework provided by the Linux kernel. It allows you to manage disk drives and similar mass-storage devices, in particular large ones. The term “volume” refers to a disk drive or partition thereof.
Why Use LVM?
LVM provides a layer of abstraction between your operating system and the physical disks. This abstraction makes it easier to manage disk space. If a file system needs more space, it can be added to its logical volume from the free spaces in its volume group and the file system can be re-sized as we wish.
Key Concepts
- Physical Volume (PV): These are your actual disks.
- Volume Group (VG): This is a pool of disk space that consists of one or more PVs.
- Logical Volume (LV): This is a portion of a VG that has been allocated for a particular purpose. You can think of an LV as a partition.
LVM Workflow
- Create Physical Volumes: The first step in creating an LVM is to create a physical volume. This can be done using the
pvcreate
command.
sudo pvcreate /dev/sdb1
- Create Volume Group: The next step is to create a volume group. This can be done using the
vgcreate
command.
sudo vgcreate my_vg /dev/sdb1
- Create Logical Volumes: The final step is to create a logical volume within the volume group. This can be done using the
lvcreate
command.
sudo lvcreate -n my_lv -L 10G my_vg
- Create File System: After creating the logical volume, you need to create a file system before you can use it.
sudo mkfs.ext4 /dev/my_vg/my_lv
- Mount the File System: Finally, you can mount the file system to a directory and start using it.
sudo mount /dev/my_vg/my_lv /mnt/my_mount_point
Conclusion
LVM is a powerful tool that gives you more flexibility in managing disk space. It’s particularly useful in environments where storage requirements change over time. With LVM, you can easily resize volumes, replace disks, and even move data between multiple systems.