Chapter 17: Storage and file systems

Linux storage cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Create

CommandDoes
lsblk -f, blkidDevices, file systems, UUIDs
parted -s /dev/sdb mklabel gptNew GPT table
parted -s /dev/sdb mkpart NAME xfs 1MiB 1025MiBNew partition
mkfs.xfs DEV · mkfs.ext4 -L NAME DEV · mkswap DEVFile systems and swap
mount DEV DIR · umount DIRAttach / detach
swapon DEV · swapoff DEV · swapon --showSwap

Permanent

ItemDetail
LineUUID=… /mnt/point xfs defaults 0 0 · swap: UUID=… none swap defaults 0 0
Optionsnoexec nodev nosuid ro nofail
Safe routinecp /etc/fstab /root/fstab.bak → edit → systemctl daemon-reload → findmnt --verify → mount -a → swapon -a → reboot
UUIDblkid -s UUID -o value DEV

Diagnose

CommandDoes
df -h · df -hT · df -iBlocks, types, inodes
du -xh --max-depth=1 DIR | sort -rh | headBiggest directories
lsof +L1Deleted but open files
fuser -vm DIR · lsof DIRWho keeps a mount busy
xfs_repair -n DEV · e2fsck -n DEVCheck (unmounted)
xfs_admin -L NAME DEV · e2label DEV NAMELabels
xfs_info DIR · tune2fs -l DEVDetails

Flashcards

Four steps for a new disk?
Partition (parted) → file system (mkfs / mkswap) → mount → /etc/fstab.
See disks, partitions, file systems?
lsblk · lsblk -f · blkid · parted -s DISK print
GPT label and a partition?
parted -s /dev/sdb mklabel gpt · parted -s /dev/sdb mkpart NAME xfs 1MiB 1025MiB
Create file systems?
mkfs.xfs DEV · mkfs.ext4 -L LABEL DEV · mkswap DEV
Mount, unmount, show?
mount DEV DIR · umount DIR · findmnt · df -hT
Permanent mount?
UUID=… /dir xfs defaults 0 0 in /etc/fstab; daemon-reload; findmnt --verify; mount -a
Swap?
mkswap DEV · swapon DEV · swapon --show · fstab line with type swap and mount point none
Why UUID?
Device names such as /dev/sdb1 can change; UUIDs do not.
Out of space?
df -h · df -i · du -xh --max-depth=1 DIR | sort -rh · lsof +L1
Busy mount?
fuser -vm DIR · lsof DIR; leave the directory, stop the process
Check a file system?
xfs_repair -n DEV (XFS) · e2fsck -f DEV (ext4), both unmounted
Labels and details?
xfs_admin -L · e2label · xfs_info · tune2fs -l