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
Initialize a physical volume
sudo pvcreate /dev/sdb1

# Prepare a partition or whole device for LVM use.

List physical volumes
sudo pvs

# Compact overview of LVM physical volumes.

Display physical volume details
sudo pvdisplay

# Verbose physical volume information including UUID and extents.

Create a volume group
sudo vgcreate vgdata /dev/sdb1

# Create a VG from one or more initialized PVs.

List volume groups
sudo vgs

# Compact view of VGs, free extents, and sizes.

Display volume group details
sudo vgdisplay vgdata

# Verbose VG information including free space and metadata.

Create a logical volume by size
sudo lvcreate -L 100G -n lvdata vgdata

# Allocate a fixed-size LV from a volume group.

Create a logical volume with remaining free space
sudo lvcreate -l 100%FREE -n lvdata vgdata

# Use all remaining free extents in the VG.

List logical volumes
sudo lvs

# Preferred compact overview of logical volumes and attributes.

Display logical volume details
sudo lvdisplay /dev/vgdata/lvdata

# Verbose LV information including path and size.

Create a filesystem on an LV
sudo mkfs.ext4 /dev/vgdata/lvdata

# Format a new logical volume for use.

Mount a logical volume
sudo mount /dev/vgdata/lvdata /mnt/data

# Mount an LV like any other block device.

## LVM Growth and Snapshots
Add a PV to an existing VG
sudo vgextend vgdata /dev/sdc1

# Increase free capacity in a volume group.

Extend an LV by fixed size
sudo lvextend -L +50G /dev/vgdata/lvdata

# Grow the logical volume size.

Extend an LV and filesystem together
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
sudo resize2fs /dev/vgdata/lvdata

# Expand an ext filesystem to fill the larger LV.

Grow XFS online
sudo xfs_growfs /mnt/data

# Expand an XFS filesystem using the mounted path.

Reduce an LV size
sudo lvreduce -L 50G /dev/vgdata/lvdata

# Dangerous if done without shrinking the filesystem first.

Shrink an ext filesystem before LV reduction
sudo resize2fs /dev/vgdata/lvdata 45G

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

Create an LVM snapshot
sudo lvcreate -L 10G -s -n lvdata_snap /dev/vgdata/lvdata

# Create a snapshot LV for backup or rollback workflows.

Remove a snapshot
sudo lvremove /dev/vgdata/lvdata_snap

# Delete an unneeded LVM snapshot.

Move extents off a PV
sudo pvmove /dev/sdb1

# Relocate data to other PVs before removing a disk.

Remove a PV from a VG
sudo vgreduce vgdata /dev/sdb1

# Detach an empty or evacuated PV from a VG.

Delete a logical volume
sudo lvremove /dev/vgdata/lvdata

# Remove an LV and return space to the VG.

## RAID and Encryption
Create a RAID1 array
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

# Create a mirrored software RAID device.

Create a RAID5 array
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
cat /proc/mdstat

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

Show array details
sudo mdadm --detail /dev/md0

# Inspect RAID level, members, and rebuild progress.

Examine RAID metadata on members
sudo mdadm --examine /dev/sdb1

# Inspect md superblock metadata directly on a member device.

Stop an array
sudo mdadm --stop /dev/md0

# Stop a software RAID device before disassembly or recovery work.

Assemble an existing array
sudo mdadm --assemble --scan

# Discover and assemble arrays based on metadata or config.

Generate mdadm.conf array entries
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

# Persist discovered arrays into mdadm configuration.

Initialize a LUKS container
sudo cryptsetup luksFormat /dev/sdb1

# Create a LUKS-encrypted block device.

Open a LUKS device
sudo cryptsetup open /dev/sdb1 cryptdata

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

Close a LUKS device
sudo cryptsetup close cryptdata

# Lock and remove the decrypted device mapping.

Show decrypted mapper devices
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS

# Verify decrypted mapper devices and mountpoints.

Recommended next

No recommendations yet.