Logical Volume Management (LVM) Operations
LVM allows you to manage disk space efficiently by creating, resizing, and managing logical volumes dynamically.
1. Create LVM (Logical Volume Manager)
Step 1: Create Physical Volume (PV)
A Physical Volume (PV) is a raw storage device (disk or partition) that LVM can use.
Example:
Step 2: Create Volume Group (VG)
A Volume Group (VG) is a pool of storage made from one or more PVs.
To check available VGs:
Step 3: Create Logical Volume (LV)
A Logical Volume (LV) is created inside a VG and used like a normal partition.
Alternatively, create using the percentage of VG size:
To verify:
Step 4: Format the Logical Volume
Before using, format the LV with a filesystem (e.g., ext4):
Step 5: Mount the Logical Volume
Create a mount point and mount the LV:
To make the mount persistent across reboots, add an entry in /etc/fstab
:
2. Delete LVM
Step 1: Unmount the Logical Volume
Step 2: Remove the Logical Volume
Step 3: Remove the Volume Group
Step 4: Remove the Physical Volume
3. Resize (Extend & Reduce) LVM
A. Extend LVM (Increase Size)
-
Extend the Logical Volume:
or use all free space:
-
Resize the Filesystem:
-
If using ext4:
-
If using XFS:
-
B. Shrink LVM (Reduce Size)
⚠ Shrinking is risky! Backup data before proceeding.
-
Unmount the LV:
-
Resize Filesystem (for ext4):
-
Reduce Logical Volume:
-
Remount the LV:
4. Take LVM Snapshot
A snapshot is a read-only or read-write copy of an LV at a given point in time.
Create a Snapshot
To view snapshots:
Mount the Snapshot
Delete Snapshot
Summary of Commands
Operation | Command |
---|---|
Create PV | pvcreate /dev/sdX |
Create VG | vgcreate my_vg /dev/sdb |
Create LV | lvcreate -L 10G -n my_lv my_vg |
Format LV | mkfs.ext4 /dev/my_vg/my_lv |
Mount LV | mount /dev/my_vg/my_lv /mnt/mydata |
Extend LV | lvextend -L +5G /dev/my_vg/my_lv && resize2fs /dev/my_vg/my_lv |
Shrink LV | umount /mnt/mydata && resize2fs /dev/my_vg/my_lv 5G && lvreduce -L 5G /dev/my_vg/my_lv |
Create Snapshot | lvcreate -L 2G -s -n my_snap /dev/my_vg/my_lv |
Delete LV | lvremove /dev/my_vg/my_lv |
Comments
Post a Comment