Disk + filesystem cheatsheet.

List disks

lsblk
lsblk -f                         # with FS info
fdisk -l                         # detailed
blkid                            # UUIDs
df -hT                           # mounted, human, with type
df -i                            # inodes
du -sh /var/*

Mount

mount                            # show mounts
mount /dev/sdb1 /mnt
mount -t ext4 /dev/sdb1 /mnt
mount -o remount,rw /
mount -o ro,noexec /dev/sdb1 /mnt
umount /mnt
umount -l /mnt                   # lazy
findmnt

/etc/fstab

# device        mount  type   options                  dump pass
UUID=...        /      ext4   defaults                 0    1
UUID=...        /home  ext4   defaults,nodev,nosuid    0    2
UUID=...        swap   swap   defaults                 0    0
tmpfs           /tmp   tmpfs  defaults,size=1G,nodev   0    0
mount -a                         # apply fstab without reboot
systemctl daemon-reload          # if using systemd-mount

Create filesystem

mkfs.ext4 /dev/sdb1
mkfs.xfs /dev/sdb1
mkfs.btrfs /dev/sdb1
mkfs.f2fs /dev/sdb1              # for SSD
mkswap /dev/sdb2

Resize

resize2fs /dev/sdb1              # ext
xfs_growfs /mnt                  # XFS (online; can't shrink)
btrfs filesystem resize +1G /mnt

fsck

fsck /dev/sdb1                   # only when unmounted
fsck -y /dev/sdb1                # auto yes

Partition

fdisk /dev/sdb                   # MBR
parted /dev/sdb                  # GPT, scriptable
gdisk /dev/sdb                   # GPT

parted /dev/sdb mklabel gpt
parted /dev/sdb mkpart primary ext4 1MiB 100%

LVM

pvcreate /dev/sdb /dev/sdc
vgcreate vg0 /dev/sdb /dev/sdc
lvcreate -L 10G -n data vg0
mkfs.ext4 /dev/vg0/data
mount /dev/vg0/data /data

# Extend
lvextend -L +5G /dev/vg0/data
resize2fs /dev/vg0/data
# OR
lvextend -L +5G -r /dev/vg0/data  # auto-resize FS

# Reduce (CAREFUL)
resize2fs /dev/vg0/data 5G
lvreduce -L 5G /dev/vg0/data

# Snapshot
lvcreate -L 1G -s -n snap /dev/vg0/data

btrfs

btrfs subvolume create /mnt/sv
btrfs subvolume snapshot /mnt/sv /mnt/sv.snap
btrfs subvolume list /mnt
btrfs filesystem df /mnt
btrfs balance /mnt
btrfs scrub start /mnt

ZFS

zpool create tank /dev/sdb /dev/sdc
zpool status
zpool list

zfs create tank/home
zfs snapshot tank/home@2026-01-15
zfs rollback tank/home@2026-01-15
zfs list -t snapshot

zfs set compression=zstd tank/home
zfs send tank/home@snap | ssh other zfs recv backup/home

Swap

swapon
free -h
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab

/tmp on tmpfs

mount -t tmpfs -o size=1G tmpfs /tmp

I/O monitoring

iostat -xz 1
iotop
sar -d 1                         # historical

Smart (disk health)

smartctl -a /dev/sda
smartctl -t short /dev/sda       # quick test
smartctl -t long /dev/sda        # full
smartctl -l selftest /dev/sda

ncdu (disk usage)

ncdu /                           # interactive du

Bandwidth-limited copy

rsync --bwlimit=10M src/ dst/
pv file > copy                   # show progress

dd

dd if=/dev/zero of=file bs=1M count=100      # 100MB file
dd if=/dev/sda of=/dev/sdb bs=4M status=progress
# CAREFUL: dd overwrites without prompt

Better: cp --reflink=auto on COW filesystems.

Mount options

  • noatime: don’t update access time (perf).
  • nodiratime.
  • nodev: no device files.
  • nosuid: no setuid.
  • noexec: no execution.
  • ro: read-only.
  • relatime: lazy atime (default modern).
  • discard: TRIM on delete (SSD).

Encrypt disk (LUKS)

cryptsetup luksFormat /dev/sdb
cryptsetup open /dev/sdb mydisk
mkfs.ext4 /dev/mapper/mydisk
mount /dev/mapper/mydisk /mnt

# Close
umount /mnt
cryptsetup close mydisk

Common mistakes

  • dd to wrong disk → data loss.
  • umount while busy → use lsof +D /mnt, then unmount.
  • Snapshot used as backup (it’s not).
  • mkfs on mounted disk.
  • LVM reduce without prior FS shrink → data loss.

Read this next

If you want my disk + LVM setup, it’s at rajpoot.dev .


Building something AI-, backend-, or data-heavy and want a second pair of eyes? I do consulting and freelance work — see my projects and ways to reach me at rajpoot.dev .