Quantcast
Channel: Łukasz Gozda Gandecki
Viewing all articles
Browse latest Browse all 10

Quick snippet for adding swap on Linux

$
0
0

Just quick copy & paste. Explanations below.

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
free -m
echo "/swapfile none swap sw 0 0" >> /etc/fstab

Steps:

Allocate 4gb for swap. Quick way. Forget about dd. :)
sudo fallocate -l 4G /swapfile

Set it so no one but root can read and write to the swap.
sudo chmod 600 /swapfile

Changes the /swapfile from an empty file to a swap compatible one.
sudo mkswap /swapfile

Activates swap
sudo swapon /swapfile

Check if everything is ok. You should see Swap: and total of 4095 in the printed out table.
free -m

Add it to the fstab file so the swap activates after restart.
echo "/swapfile none swap sw 0 0" >> /etc/fstab

That’s it! Enjoy your swap!


Viewing all articles
Browse latest Browse all 10

Trending Articles