Disk and storage commands cheat sheet

Disk work splits into two instincts that must never blur: reading capacity (df, du, lsblk) and writing to block devices (mount, dd, LVM creation). Every writing row here carries its guardrail — most importantly the dd row, where a swapped argument erases a disk without prompting.

Order of operations when a volume fills up: df -h finds which filesystem, du -h --max-depth=1 drills to which directory, and df -i catches the sneaky case where inodes rather than bytes ran out. The FAQ covers the third possibility — space that frees only after a process restarts.

Space and usage

Capacity reads. None require root, though du over system paths is quieter with sudo
TaskCommandNotes
Free space per filesystemdf -h-h human units; add -T to show filesystem type, -x tmpfs -x devtmpfs to declutter
Inode usagedf -i'No space left on device' with df -h showing free space = inode exhaustion (millions of tiny files)
One directory's total sizedu -sh /var/log-s summarize, -h human units
Biggest directories under a pathsudo du -h --max-depth=1 /var 2>/dev/null | sort -rh | head -n 15permission noise silenced; sort -h understands K/M/G suffixes
Memory and swap at a glancefree -havailable is the realistic number — buff/cache reclaims itself under pressure
Active swap devicesswapon --showSIZE, USED and PRIO per swap device; free -h shows the total only

Devices, mounts and fstab

util-linux toolkit. Mounting and checking require root; inspection rows do not
TaskCommandNotes
Block device layout with filesystemslsblk -fadds filesystem type, UUID and mountpoint to the tree
UUIDs for fstab entriessudo blkidcopy UUID= values from here — never rely on /dev/sdX letters
Tree of everything mountedfindmntincludes bind mounts; narrow with findmnt /mnt/data
Mount a filesystemsudo mount /dev/sdb1 /mnt/backupmount point must already exist; lsblk confirms the device first
Unmount a filesystemsudo umount /mnt/backupbusy target: fuser -vm /mnt/backup names the holders; umount -l detaches lazily as last resort
Check and repair a filesystemsudo fsck.ext4 -f /dev/sdb1unmounted only; the root filesystem is checked via boot or a recovery image
Validate fstab before rebootingsudo findmnt --verifyparses /etc/fstab and reports bad UUIDs and options — cheap boot insurance
fstab: six whitespace-separated fields — device, mount point, type, options, dump (legacy, keep 0), fsck pass (root 1, other local 2, network 0)
UUID=123e4567-e89b-12d3-a456-426614174000  /         ext4   errors=remount-ro                     0 1
UUID=550e8400-e29b-41d4-a716-446655440000  /home     ext4   defaults,nofail                       0 2
//nas.example/share                        /mnt/nas  cifs   credentials=/etc/nas.cred,uid=1000,_netdev  0 0
web01:/srv/export                          /mnt/nfs  nfs4   defaults,_netdev                      0 0
Mount by UUID, never by kernel device letter — /dev/sdb1 can become /dev/sdc1 after a reboot or a replug. nofail lets the machine boot when a secondary disk is missing, and _netdev postpones network mounts until the network is up, preventing boot hangs. Keep credentials files (the cifs row) at chmod 600.

Health and maintenance

smartmontools provides smartctl (install via apt/dnf). The dd row destroys its target device — read the warning below first
TaskCommandNotes
SMART overall verdictsudo smartctl -H /dev/sdaprints PASSED or FAILED — the ten-second drive health check
SMART attribute detailsudo smartctl -a /dev/sdawatch Reallocated_Sector_Cnt and Current_Pending_Sector — rising values precede failure
TRIM all SSDs nowsudo fstrim -avweekly fstrim.timer normally handles this; -a all mounted SSDs, -v reports bytes trimmed
Force pending writes to disksyncblocks until dirty buffers are written; cheap insurance before snapshots or cable pulls
Write an image to a device — DANGEROUSsudo dd if=image.iso of=/dev/sdX bs=4M status=progress conv=fsyncDESTROYS everything on the target with no confirmation; verify the letter with lsblk -o NAME,SIZE,MODEL first
dd has no undo and no prompt: of=/dev/sda instead of /dev/sdb quietly overwrites an operating system. Identify the target by size AND model via lsblk -o NAME,SIZE,MODEL, never by letter alone, and prefer status=progress so a hung write is visible. For writing ISOs to USB, a GUI tool such as GNOME Disks or Etcher wraps the same operation with a picker and confirmation.

LVM quick reference

The three-layer model: physical volumes pool into volume groups, logical volumes carve out of groups. Rows labeled LVM throughout
TaskCommandNotes
Mark a disk as a physical volume (LVM)sudo pvcreate /dev/sdb1partition type 8e is cosmetic — LVM works regardless; whole disks work too
Pool PVs into a volume group (LVM)sudo vgcreate vg_data /dev/sdb1the VG is the storage pool you carve volumes from; vgextend adds more later
Carve a logical volume (LVM)sudo lvcreate -n lv_data -L 50G vg_datastill raw space: follow with mkfs.ext4 /dev/vg_data/lv_data and mount
Use all remaining space (LVM)sudo lvcreate -n lv_data -l 100%FREE vg_data-l (lowercase L) takes extents — percentages of free VG space
List every layer (LVM)sudo pvs; sudo vgs; sudo lvsone summary table per layer — sizes and free extents at a glance
Grow a volume and its filesystem online (LVM)sudo lvextend -r -L +10G /dev/vg_data/lv_data-r invokes the right grower: resize2fs for ext4, xfs_growfs for xfs (xfs must be mounted)

FAQ

How do I check disk usage on Linux?

Two complementary tools: df -h shows free space per mounted filesystem (the capacity view), while du -sh /path measures how much a directory tree occupies (the consumer view). The drill-down for a full disk: df -h to find the full filesystem, then sudo du -h --max-depth=1 /var | sort -rh | head -n 15 repeated level by level until the culprit appears. Always confirm suspected deletions with lsof before assuming.

Disk is full but df -h shows free space — why?

Two classic causes. First, deleted-but-open files: a process still holds a removed log, so its blocks are not released until the process exits. Find them with sudo lsof +L1 (large sizes, names marked deleted), then restart or reload the holding service — journald and long-running app servers are frequent offenders. Second, inode exhaustion: df -i shows IUse% near 100%, meaning millions of tiny files consumed metadata rather than bytes; clearing session/cache trees releases them.

What does du -sh mean?

du estimates disk usage; the flags shape it. -s summarizes — one total for the argument instead of a line per file — and -h renders human-readable units (K, M, G) instead of raw kilobyte blocks. So du -sh /var/log prints a single readable total for that tree. Combine with --max-depth=1 to get one line per immediate child when hunting space hogs.

Can I extend a disk or LVM volume without downtime?

Yes, routinely. With LVM: lvextend -r -L +10G /dev/vg_data/lv_data grows the volume and the filesystem in one step, online — ext4 grows mounted via resize2fs, xfs grows mounted via xfs_growfs (it cannot shrink at all). On cloud VMs without LVM: extend the volume at the provider, grow the partition (growpart from cloud-guest-utils), then grow the filesystem. Snapshot or back up first; growth is low-risk, but it is not zero-risk.

How do I write an ISO to a USB stick safely?

Identify the stick by size and model with lsblk -o NAME,SIZE,MODEL — never trust the device letter alone — then sudo dd if=image.iso of=/dev/sdX bs=4M status=progress conv=fsync. The dangerous part is of=: pointing it at your system disk destroys it instantly, without confirmation. If the stakes feel high, GNOME Disks' Restore Disk Image or Etcher perform the identical write behind a device picker and a confirmation dialog.