Storage, Disks and Filesystems
What is using space?
df -h # per filesystem
sudo du -xh / --max-depth=1 | sort -h # biggest top-level folders
sudo du -sh /var/log/* | sort -h | tail
sudo find / -xdev -type f -size +500M -exec ls -lh {} \;
Usual culprits: logs, old releases, Docker images (docker system df), database files, package caches (sudo apt clean).
A file deleted while a process still has it open keeps using space. Find it with sudo lsof +L1, then restart that process.
Inodes
df -i shows inodes, the slots that track files. Millions of tiny files (sessions, caches) can exhaust inodes while df -h still shows free space, and writes fail with "No space left on device".
Adding a disk
lsblk # find the new disk, e.g. /dev/sdb
sudo mkfs.ext4 /dev/sdb # format it (destroys data on it!)
sudo mkdir -p /mnt/data
sudo blkid /dev/sdb # get its UUID
Add it to /etc/fstab so it mounts at boot, by UUID (device names can change):
UUID=3f1c... /mnt/data ext4 defaults,nofail 0 2
sudo mount -a # mount everything in fstab: test BEFORE rebooting
df -h /mnt/data
nofail lets the server boot even if the disk is missing. A broken fstab line without it can leave a cloud server unbootable.
Swap
Swap is disk used as overflow memory. On small servers (512 MB to 2 GB) a little swap prevents out-of-memory crashes during spikes:
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
Swap is a safety net, not extra RAM. If a server constantly swaps, it needs more memory or fewer workers.
Check yourself
df -hshows free space but writes fail. What do you check?- Why mount by UUID?
- What does
nofailprotect against?
Seu progresso fica salvo apenas neste navegador.
Enviar para revisão (10 pontos)