Linux LVM, RAID, and Encryption Cheat Sheet

LVM volume management, mdadm RAID, and LUKS encryption workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

LVM Basics

Create and inspect physical volumes, volume groups, and logical volumes.

Initialize a physical volume

Prepare a partition or whole device for LVM use.

bashANYlvmpvcreatephysical-volume
bash
sudo pvcreate /dev/sdb1

Prepare a partition or whole device for LVM use.

List physical volumes

Compact overview of LVM physical volumes.

bashANYlvmpvsinventory
bash
sudo pvs

Compact overview of LVM physical volumes.

Display physical volume details

Verbose physical volume information including UUID and extents.

bashANYlvmpvdisplayinventory
bash
sudo pvdisplay

Verbose physical volume information including UUID and extents.

Create a volume group

Create a VG from one or more initialized PVs.

bashANYlvmvgcreatevolume-group
bash
sudo vgcreate vgdata /dev/sdb1

Create a VG from one or more initialized PVs.

List volume groups

Compact view of VGs, free extents, and sizes.

bashANYlvmvgsinventory
bash
sudo vgs

Compact view of VGs, free extents, and sizes.

Display volume group details

Verbose VG information including free space and metadata.

bashANYlvmvgdisplayvolume-group
bash
sudo vgdisplay vgdata

Verbose VG information including free space and metadata.

Create a logical volume by size

Allocate a fixed-size LV from a volume group.

bashANYlvmlvcreatelogical-volume
bash
sudo lvcreate -L 100G -n lvdata vgdata

Allocate a fixed-size LV from a volume group.

Create a logical volume with remaining free space

Use all remaining free extents in the VG.

bashANYlvmlvcreatefree-space
bash
sudo lvcreate -l 100%FREE -n lvdata vgdata

Use all remaining free extents in the VG.

List logical volumes

Preferred compact overview of logical volumes and attributes.

bashANYlvmlvsinventory
bash
sudo lvs

Preferred compact overview of logical volumes and attributes.

Display logical volume details

Verbose LV information including path and size.

bashANYlvmlvdisplayinventory
bash
sudo lvdisplay /dev/vgdata/lvdata

Verbose LV information including path and size.

Create a filesystem on an LV

Format a new logical volume for use.

bashANYlvmmkfslogical-volume
bash
sudo mkfs.ext4 /dev/vgdata/lvdata

Format a new logical volume for use.

Mount a logical volume

Mount an LV like any other block device.

bashANYlvmmountlogical-volume
bash
sudo mount /dev/vgdata/lvdata /mnt/data

Mount an LV like any other block device.

LVM Growth and Snapshots

Extend, reduce, snapshot, and move LVM storage.

Add a PV to an existing VG

Increase free capacity in a volume group.

bashANYlvmvgextendcapacity
bash
sudo vgextend vgdata /dev/sdc1

Increase free capacity in a volume group.

Extend an LV by fixed size

Grow the logical volume size.

bashANYlvmlvextendresize
bash
sudo lvextend -L +50G /dev/vgdata/lvdata

Grow the logical volume size.

Extend an LV and filesystem together

Grow both the LV and the contained filesystem when supported.

bashANYlvmlvextendfilesystem
bash
sudo lvextend -r -L +50G /dev/vgdata/lvdata

Grow both the LV and the contained filesystem when supported.

Grow an ext filesystem after LV extension

Expand an ext filesystem to fill the larger LV.

bashANYresize2fsext4grow
bash
sudo resize2fs /dev/vgdata/lvdata

Expand an ext filesystem to fill the larger LV.

Grow XFS online

Expand an XFS filesystem using the mounted path.

bashANYxfs_growfsxfsgrow
bash
sudo xfs_growfs /mnt/data

Expand an XFS filesystem using the mounted path.

Reduce an LV size

Dangerous if done without shrinking the filesystem first.

bashANYlvmlvreduceshrink
bash
sudo lvreduce -L 50G /dev/vgdata/lvdata

Dangerous if done without shrinking the filesystem first.

Shrink an ext filesystem before LV reduction

For ext filesystems, shrink the filesystem before shrinking the LV.

bashANYresize2fsext4shrink
bash
sudo resize2fs /dev/vgdata/lvdata 45G

For ext filesystems, shrink the filesystem before shrinking the LV.

Create an LVM snapshot

Create a snapshot LV for backup or rollback workflows.

bashANYlvmsnapshotlvcreate
bash
sudo lvcreate -L 10G -s -n lvdata_snap /dev/vgdata/lvdata

Create a snapshot LV for backup or rollback workflows.

Remove a snapshot

Delete an unneeded LVM snapshot.

bashANYlvmsnapshotlvremove
bash
sudo lvremove /dev/vgdata/lvdata_snap

Delete an unneeded LVM snapshot.

Move extents off a PV

Relocate data to other PVs before removing a disk.

bashANYlvmpvmovemigration
bash
sudo pvmove /dev/sdb1

Relocate data to other PVs before removing a disk.

Remove a PV from a VG

Detach an empty or evacuated PV from a VG.

bashANYlvmvgreducevolume-group
bash
sudo vgreduce vgdata /dev/sdb1

Detach an empty or evacuated PV from a VG.

Delete a logical volume

Remove an LV and return space to the VG.

bashANYlvmlvremovelogical-volume
bash
sudo lvremove /dev/vgdata/lvdata

Remove an LV and return space to the VG.

RAID and Encryption

Software RAID and common encrypted volume workflows.

Create a RAID1 array

Create a mirrored software RAID device.

bashANYmdadmraid1create
bash
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

Create a mirrored software RAID device.

Create a RAID5 array

Create a RAID5 array with striping and parity.

bashANYmdadmraid5create
bash
sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

Create a RAID5 array with striping and parity.

Show active MD arrays

Quick view of RAID sync, rebuild, and degraded state.

bashANYmdadmmdstatraid
bash
cat /proc/mdstat

Quick view of RAID sync, rebuild, and degraded state.

Show array details

Inspect RAID level, members, and rebuild progress.

bashANYmdadmdetailraid
bash
sudo mdadm --detail /dev/md0

Inspect RAID level, members, and rebuild progress.

Examine RAID metadata on members

Inspect md superblock metadata directly on a member device.

bashANYmdadmexamineraid
bash
sudo mdadm --examine /dev/sdb1

Inspect md superblock metadata directly on a member device.

Stop an array

Stop a software RAID device before disassembly or recovery work.

bashANYmdadmstopraid
bash
sudo mdadm --stop /dev/md0

Stop a software RAID device before disassembly or recovery work.

Assemble an existing array

Discover and assemble arrays based on metadata or config.

bashANYmdadmassembleraid
bash
sudo mdadm --assemble --scan

Discover and assemble arrays based on metadata or config.

Generate mdadm.conf array entries

Persist discovered arrays into mdadm configuration.

bashANYmdadmmdadm.confraid
bash
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

Persist discovered arrays into mdadm configuration.

Initialize a LUKS container

Create a LUKS-encrypted block device.

bashANYcryptsetupluksencrypt
bash
sudo cryptsetup luksFormat /dev/sdb1

Create a LUKS-encrypted block device.

Open a LUKS device

Map an encrypted device to /dev/mapper/cryptdata.

bashANYcryptsetupluksopen
bash
sudo cryptsetup open /dev/sdb1 cryptdata

Map an encrypted device to /dev/mapper/cryptdata.

Close a LUKS device

Lock and remove the decrypted device mapping.

bashANYcryptsetupluksclose
bash
sudo cryptsetup close cryptdata

Lock and remove the decrypted device mapping.

Show decrypted mapper devices

Verify decrypted mapper devices and mountpoints.

bashANYcryptsetupmapperlsblk
bash
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS

Verify decrypted mapper devices and mountpoints.

Recommended next

No recommendations yet.