Logical Volume Manager (LVM) is a powerful storage management tool used in Linux. It provides flexibility and scalability in managing disk storage, allowing you to dynamically resize or extend storage without disrupting the system.
Key features of LVM include:
-
Dynamic Partitioning:
- Resize, extend, or reduce partitions (logical volumes) without requiring a reboot.
-
Disk Grouping:
- Combine multiple physical disks or partitions into a single logical pool (Volume Group), making storage easier to manage.
-
Snapshot Support:
- Create snapshots for backups or testing without affecting the original data.
-
Improved Storage Utilization:
- Allocate storage on-demand, avoiding unused space in fixed partitions.
-
Ease of Management:
- Simplifies disk management tasks like adding or replacing disks in a storage setup.
-
Physical Volumes (PV):
- Physical disks or partitions (e.g.,
/dev/sdb,/dev/sdc) used as building blocks.
- Physical disks or partitions (e.g.,
-
Volume Groups (VG):
- A pool of storage created by combining one or more physical volumes.
-
Logical Volumes (LV):
- Flexible partitions created from the Volume Group, where filesystems are applied (e.g., ext4).
- Scalability: Adjust storage needs as your system grows.
- Flexibility: Add, remove, or resize storage without major downtime.
- Snapshots: Create instant backups.
- Storage Pooling: Combine multiple disks into a single logical unit.
LVM is especially useful in environments requiring frequent storage changes, such as servers, virtual machines, and testing systems.
Before proceeding with the LVM configuration, ensure the following:
-
Linux Environment:
- A Linux distribution with
lvm2tools available.
- A Linux distribution with
-
Root Access:
- Administrative privileges to execute commands like
apt,pvcreate, and others.
- Administrative privileges to execute commands like
-
Disk Space:
- At least two unmounted and unused disks or partitions (e.g.,
/dev/sdb,/dev/sdc) for LVM configuration.
- At least two unmounted and unused disks or partitions (e.g.,
-
Basic Tools Installed:
- Update your package list:
sudo apt update
- Install LVM tools:
sudo apt install lvm2
- Update your package list:
-
Filesystem Knowledge:
- Familiarity with ext4 or other supported filesystems for formatting logical volumes.
-
Backup (Optional but Recommended):
- Backup critical data as disk operations may result in data loss if not handled properly.
sudo apt update This updates the package list to get information about the latest versions of packages available in the repositories.
sudo apt install lvm2 Installs the lvm2 package, which provides tools to manage disk volumes.
lsblk Lists block devices, showing all hard drives, partitions, and storage devices.
sudo pvcreate /dev/sdb Prepares /dev/sdb for inclusion in LVM by marking it as a physical volume (PV).
sudo pvdisplay Shows detailed information about physical volumes on the system.
sudo pvcreate /dev/sdc Marks /dev/sdc as a physical volume for use in LVM.
sudo vgcreate suraj_volume_group /dev/sdb /dev/sdc Combines /dev/sdb and /dev/sdc into a volume group (VG) named suraj_volume_group.
sudo vgdisplay Displays information about the volume group(s) on your system.
sudo lvcreate -L 10G -n suraj_logical_volume suraj_volume_group Creates a logical volume named suraj_logical_volume with a size of 10GB within suraj_volume_group.
sudo lvdisplay Shows details about the logical volume(s) in the volume group.
sudo mkfs.ext4 /dev/suraj_volume_group/suraj_logical_volume Formats the logical volume in the ext4 filesystem.
sudo blkid /dev/suraj_volume_group/suraj_logical_volume
Displays the UUID and filesystem type of the logical volume.
sudo mkdir /mnt/suraj_lvm Creates a directory to mount the logical volume.
sudo mount /dev/suraj_volume_group/suraj_logical_volume /mnt/suraj_lvm Mounts the logical volume at /mnt/suraj_lvm.
df -h Shows disk space usage and confirms the logical volume is mounted.
Alternatively, you can use:
mount | grep /mnt/suraj_lvm sudo nano /etc/fstab Add the following line to ensure the logical volume is automatically mounted after reboot:
/dev/suraj_volume_group/suraj_logical_volume /mnt/suraj_lvm ext4 defaults 0 0
cat /etc/fstab Ensures the logical volume is listed in the fstab file.
sudo lvextend -L 20G /dev/suraj_volume_group/suraj_logical_volume Increases the size of suraj_logical_volume to 20GB.
sudo lvextend -L 15G /dev/suraj_volume_group/suraj_logical_volume Adjusts the logical volume size to 15GB.
sudo resize2fs /dev/suraj_volume_group/suraj_logical_volume Resizes the filesystem to match the new logical volume size.
sudo lvdisplay /dev/suraj_volume_group/suraj_logical_volume Shows updated information for the resized logical volume.
df -h Confirms the updated disk space usage after resizing.
-
LVM is Flexible: Enables dynamic resizing and management of storage.
-
Efficient Storage Management: Combines multiple disks into logical units for better utilization.
-
Ideal for Growing Systems: Perfect for servers, VMs, and environments with changing storage needs.
-
Simplifies Operations: Easy to extend, reduce, or snapshot volumes without downtime.
-
Use with Caution: Proper planning is essential to avoid data loss.
-
Powerful Tool: Enhances the efficiency and scalability of Linux systems.
π¨βπ» Crafted by: Suraj Kumar Choudhary | π© Feel free to DM for any help: csuraj982@gmail.com