LVM Cheatsheet
#
LVM (Logical Volume Manager) allows for flexible disk management by creating logical volumes that can be resized dynamically.
Basic Commands
#
Command/Option | Example | Description |
---|
pvcreate | pvcreate /dev/sdX1 | Initialize a physical volume |
vgcreate | vgcreate my_vg /dev/sdX1 | Create a volume group |
lvcreate | lvcreate -n my_lv -L 10G my_vg | Create a logical volume |
pvdisplay | pvdisplay | Display information about physical volumes |
vgdisplay | vgdisplay | Display information about volume groups |
lvdisplay | lvdisplay | Display information about logical volumes |
Volume Management
#
Command/Option | Example | Description |
---|
lvextend | lvextend -L +5G /dev/my_vg/my_lv | Extend the size of a logical volume |
lvreduce | lvreduce -L -5G /dev/my_vg/my_lv | Reduce the size of a logical volume |
lvremove | lvremove /dev/my_vg/my_lv | Remove a logical volume |
vgremove | vgremove my_vg | Remove a volume group |
pvremove | pvremove /dev/sdX1 | Remove a physical volume |
Snapshot Management
#
Command/Option | Example | Description |
---|
lvcreate --snapshot | lvcreate --snapshot --name my_snapshot --size 1G /dev/my_vg/my_lv | Create a snapshot of a logical volume |
lvremove | lvremove /dev/my_vg/my_snapshot | Remove a logical volume snapshot |
File System and Mounting
#
Command/Option | Example | Description |
---|
mkfs.ext4 | mkfs.ext4 /dev/my_vg/my_lv | Create a file system on a logical volume |
mount | mount /dev/my_vg/my_lv /mnt | Mount a logical volume to a directory |
umount | umount /mnt | Unmount a logical volume |
Commands for Managing Physical Volumes
#
Command/Option | Example | Description |
---|
pvcreate | pvcreate /dev/sdX1 | Initialize a physical volume |
pvscan | pvscan | Scan all disks for physical volumes |
pvs | pvs | Display physical volume information |
Commands for Managing Volume Groups
#
Command/Option | Example | Description |
---|
vgcreate | vgcreate my_vg /dev/sdX1 | Create a new volume group |
vgextend | vgextend my_vg /dev/sdX2 | Add a new physical volume to a volume group |
vgremove | vgremove my_vg | Remove a volume group |
vgs | vgs | Display volume group information |
Commands for Managing Logical Volumes
#
Command/Option | Example | Description |
---|
lvcreate | lvcreate -n my_lv -L 10G my_vg | Create a new logical volume |
lvextend | lvextend -L +5G /dev/my_vg/my_lv | Extend the size of a logical volume |
lvreduce | lvreduce -L -5G /dev/my_vg/my_lv | Reduce the size of a logical volume |
lvremove | lvremove /dev/my_vg/my_lv | Remove a logical volume |
lvs | lvs | Display logical volume information |
This cheatsheet covers essential LVM commands and options to help you manage and maintain logical volumes, volume groups, and physical volumes effectively.