How do you add a swap file?
BeginnerConceptStorage & Memory
Answer
sudo fallocate -l 4G /swapfile # use dd on filesystems where fallocate swap is unsupported
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
swapon --show
More on Storage & Memory
How do you list disks, partitions and filesystems?IntermediateMBR vs GPT partition tables?IntermediateWalk through adding a new disk and mounting it permanently.IntermediateExplain the six fields of an /etc/fstab line.IntermediateWhy use UUIDs and `nofail` in fstab?IntermediateWhat does a bad fstab entry do, and how do you recover?Advanced