Interview Prep/Linux/Storage, disks and filesystems

A developer asks for a 4 GB swap on a server with no free partitions. How do you add it?

BeginnerScenarioStorage, disks and filesystems
Answer

Situation read → Use a swap file.

What I'd do →

sudo fallocate -l 4G /swapfile        # on XFS/ext4; use dd on btrfs or if fallocate fails
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab
swapon --show; free -h

Why → chmod 600 stops users reading memory pages written to swap.

Interview tip → Mention vm.swappiness and that some workloads (Kubernetes nodes historically, latency-sensitive DBs) avoid swap on purpose.

All Linux questions Roadmap: Linux

More on Storage, disks and filesystems