lvm
Introduction
This cheat sheet provides a quick reference for some common LVM (Logical Volume Manager) commands and concepts. LVM is a command-line utility used for managing logical volumes and volume groups on Linux systems.
LVM Concepts
Physical Volumes (PV)
Physical volumes are physical storage devices (e.g., hard drives or partitions) used to create logical volumes.
Display a list of physical volumes:
pvdisplayCreate a physical volume:
pvcreate /dev/sdX
Volume Groups (VG)
Volume groups are logical containers that can consist of one or more physical volumes.
Display a list of volume groups:
vgdisplayCreate a volume group:
vgcreate myvg /dev/sdX
Logical Volumes (LV)
Logical volumes are partitions created within volume groups.
Display a list of logical volumes:
lvdisplayCreate a logical volume:
lvcreate -L 10G -n mylv myvg
Resize Operations
You can resize physical volumes, volume groups, and logical volumes.
Resize a physical volume:
pvresize /dev/sdXResize a volume group:
vgextend myvg /dev/sdYResize a logical volume:
lvresize -L +2G /dev/myvg/mylv
Mounting and Filesystems
After creating a logical volume, you can format it with a filesystem and mount it.
Format a logical volume with ext4:
mkfs.ext4 /dev/myvg/mylvMount a logical volume:
mount /dev/myvg/mylv /mnt/mylv
LVM Command-Line
Display a list of physical volumes:
pvdisplayCreate a physical volume:
pvcreate /dev/sdXDisplay a list of volume groups:
vgdisplayCreate a volume group:
vgcreate myvg /dev/sdXDisplay a list of logical volumes:
lvdisplayCreate a logical volume:
lvcreate -L 10G -n mylv myvgResize a physical volume:
pvresize /dev/sdXResize a volume group:
vgextend myvg /dev/sdYResize a logical volume:
lvresize -L +2G /dev/myvg/mylvFormat a logical volume with ext4:
mkfs.ext4 /dev/myvg/mylvMount a logical volume:
mount /dev/myvg/mylv /mnt/mylv
Conclusion
This cheat sheet covers some common LVM (Logical Volume Manager) commands and concepts. LVM is a powerful tool for managing logical volumes and volume groups on Linux systems, making it useful for storage management and partitioning tasks; refer to the official LVM documentation for more in-depth information and advanced usage.