LVM (Logical Volume Manager) Cheat Sheet
1. Basic Terms
- Physical Volume (PV): The physical disk or partition.
- Volume Group (VG): A combination of multiple PVs into a storage pool.
- Logical Volume (LV): A virtual partition within a VG.
2. Create PV
pvcreate /dev/sdX # Create a PV on /dev/sdX
pvdisplay # Display PV information
3. Create VG
vgcreate vg_name /dev/sdX /dev/sdY # Create a VG from two PVs
vgdisplay # Display VG information
4. Create LV
lvcreate -L 10G -n lv_name vg_name # Create an LV with 10 GB in the VG
lvdisplay # Display LV information
5. Create filesystem on LV and mount
mkfs.ext4 /dev/vg_name/lv_name # Create an ext4 filesystem
mount /dev/vg_name/lv_name /mnt/point # Mount the LV
6. Extend LV
lvextend -L +5G /dev/vg_name/lv_name # Extend the LV by 5 GB
resize2fs /dev/vg_name/lv_name # Resize the filesystem (ext4)
7. Shrink LV
umount /dev/vg_name/lv_name # Unmount the LV first
resize2fs /dev/vg_name/lv_name 10G # Shrink the filesystem
lvreduce -L 10G /dev/vg_name/lv_name # Reduce the LV to 10 GB
mount /dev/vg_name/lv_name /mnt/point # Remount the LV
8. Remove LV
umount /dev/vg_name/lv_name # Unmount the LV
lvremove /dev/vg_name/lv_name # Remove the LV
9. Extend VG
vgextend vg_name /dev/sdZ # Add a new PV to a VG
10. Remove VG
vgremove vg_name # Remove the VG
11. Remove PV
pvremove /dev/sdX # Remove the PV