LVM

LVM Cheatsheet #

LVM (Logical Volume Manager) allows for flexible disk management by creating logical volumes that can be resized dynamically.

Basic Commands #

Command/OptionExampleDescription
pvcreatepvcreate /dev/sdX1Initialize a physical volume
vgcreatevgcreate my_vg /dev/sdX1Create a volume group
lvcreatelvcreate -n my_lv -L 10G my_vgCreate a logical volume
pvdisplaypvdisplayDisplay information about physical volumes
vgdisplayvgdisplayDisplay information about volume groups
lvdisplaylvdisplayDisplay information about logical volumes

Volume Management #

Command/OptionExampleDescription
lvextendlvextend -L +5G /dev/my_vg/my_lvExtend the size of a logical volume
lvreducelvreduce -L -5G /dev/my_vg/my_lvReduce the size of a logical volume
lvremovelvremove /dev/my_vg/my_lvRemove a logical volume
vgremovevgremove my_vgRemove a volume group
pvremovepvremove /dev/sdX1Remove a physical volume

Snapshot Management #

Command/OptionExampleDescription
lvcreate --snapshotlvcreate --snapshot --name my_snapshot --size 1G /dev/my_vg/my_lvCreate a snapshot of a logical volume
lvremovelvremove /dev/my_vg/my_snapshotRemove a logical volume snapshot

File System and Mounting #

Command/OptionExampleDescription
mkfs.ext4mkfs.ext4 /dev/my_vg/my_lvCreate a file system on a logical volume
mountmount /dev/my_vg/my_lv /mntMount a logical volume to a directory
umountumount /mntUnmount a logical volume

Commands for Managing Physical Volumes #

Command/OptionExampleDescription
pvcreatepvcreate /dev/sdX1Initialize a physical volume
pvscanpvscanScan all disks for physical volumes
pvspvsDisplay physical volume information

Commands for Managing Volume Groups #

Command/OptionExampleDescription
vgcreatevgcreate my_vg /dev/sdX1Create a new volume group
vgextendvgextend my_vg /dev/sdX2Add a new physical volume to a volume group
vgremovevgremove my_vgRemove a volume group
vgsvgsDisplay volume group information

Commands for Managing Logical Volumes #

Command/OptionExampleDescription
lvcreatelvcreate -n my_lv -L 10G my_vgCreate a new logical volume
lvextendlvextend -L +5G /dev/my_vg/my_lvExtend the size of a logical volume
lvreducelvreduce -L -5G /dev/my_vg/my_lvReduce the size of a logical volume
lvremovelvremove /dev/my_vg/my_lvRemove a logical volume
lvslvsDisplay 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.

Cheatsheet Website

Discover our extensive collection of cheatsheets covering various tools and technologies to streamline your workflow.