1 min read #devops
On this page

Disk Operations Manual

Viewing

# Block device tree (including size, type, mount points, UUID)
lsblk -f
# NAME   FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
# sda
# ├─sda1 ext4   1.0         abc123-def456                        50G     30%    /
# └─sda2 swap   1           fed987                                                       [SWAP]

df -h                                   # Filesystem usage
df -i                                   # Inode usage (inode exhaustion = cannot create files)
du -sh /path                            # Directory/file size
du -sh * | sort -rh | head -10          # Largest items in the current directory

# Modern alternatives
duf                                    # Colored df, automatically filters loop/tmpfs
dust                                   # Tree-style du, automatically sorted
dust -d 2                              # Depth limit of 2 levels
ncdu /                                 # Interactive du (navigate with arrow keys, d to delete)

# File search and navigation
fd pattern                             # Alternative to find: search by filename (regex by default, respects .gitignore)
fd -e rs                               # Search by extension
rg pattern                             # Alternative to grep -r: search file contents
rg -t py pattern                       # Search by file type (py, js, md...)
rg -l pattern                          # List only filenames
bat file                               # Alternative to cat: syntax highlighting + line numbers + Git diff markers
z dirname                              # zoxide: jump to recently accessed matching directory (alternative to cd)
fzf                                    # Fuzzy finder: Ctrl+T to search files, Ctrl+R to search history

fdisk -l                                # MBR partition table
gdisk -l                                # GPT partition table
blkid                                   # UUIDs and filesystem types for all devices

# SMART health (drive self-test)
smartctl -a /dev/nvme0n1                # NVMe: Percentage Used, Data Units Written
smartctl -a /dev/sda                    # SATA: Reallocated_Sector_Ct, Pending_Sector
smartctl -t short /dev/sda              # Trigger short test (2-5 minutes)
smartctl -l selftest /dev/sda           # View test results

Partitioning and Formatting

# GPT partitioning (recommended, supports >2TB)
gdisk /dev/sda
  n  → Create new partition
  t  → Change partition type (8300 = Linux filesystem, 8200 = swap)
  w  → Write changes

mkfs.ext4 /dev/sda1                     # Format as ext4
mkfs.ext4 -L mylabel /dev/sda1          # With label (label can be used for mounting instead of UUID)
mkswap /dev/sda2
swapon /dev/sda2

Mounting

mount /dev/sda1 /mnt/data
umount /mnt/data
umount -l /mnt/data                     # Lazy unmount (unmounts automatically after all processes release references)

# fstab persistence (use UUID instead of /dev/sdX, as device names may drift)
lsblk -f                                # Get UUID
# /etc/fstab:
UUID=abc123-def456 /mnt/data ext4 defaults,noatime 0 2
# noatime: Do not update access time when reading files (reduces writes on SSDs)
# 0: dump backup (disabled by default)
# 2: fsck priority (0=do not check, 1=root, 2=others)

# Test fstab (without rebooting)
mount -a                                # Mount all entries in fstab
systemctl daemon-reload

LVM

pvcreate /dev/sda4                      # Physical volume
vgcreate vg0 /dev/sda4                  # Volume group
lvcreate -L 10G -n lv0 vg0              # Logical volume (10G)
lvcreate -l +100%FREE -n lv0 vg0        # Use all remaining space

lvextend -L +5G /dev/vg0/lv0            # Extend LV
resize2fs /dev/vg0/lv0                  # Extend filesystem (ext4)

pvs / vgs / lvs                         # View status
lvremove /dev/vg0/lv0                   # Remove LV (data loss!)

fstrim (Periodic SSD discard)

fstrim -v /                             # Manual trim (reclaim deleted blocks)
systemctl enable fstrim.timer           # Enable automatic weekly trim
systemctl status fstrim.timer

Troubleshooting

# IO errors
dmesg | grep -i "I/O error"
# → Disk may have bad sectors → Check with smartctl -a

# Real-time IO monitoring
iostat -x 1                             # await (latency), %util (utilization)
cat /proc/diskstats                      # Cumulative IO counts

# Filesystem remounted read-only
# → Usually FS detected inconsistency → Requires fsck
dmesg | grep -i "remounted.*read-only"
fsck -n /dev/sda1                       # Check only, do not fix (requires unmount)
fsck /dev/sda1                          # Check and fix (must be unmounted!)