The article is copied from ubuntu community as it is .
In case you don't want or you're not sure how to create a swap partition, you can create a swap file which will work in the same way as partition. Here are the steps (using terminal):
In case you don't want or you're not sure how to create a swap partition, you can create a swap file which will work in the same way as partition. Here are the steps (using terminal):
- Create an empty file (1K * 4M = 4 GiB).
sudo mkdir -v /var/cache/swap cd /var/cache/swap sudo dd if=/dev/zero of=swapfile bs=1K count=4M sudo chmod 600 swapfile - Convert newly created file into a swap space file.
sudo mkswap swapfile - Enable file for paging and swapping.
Verify by:sudo swapon swapfileswapon -sortop:
Should display line like:top -bn1 | grep -i swapKiB Swap: 4194300 total, 4194300 free
To disable, usesudo swapoff swapfilecommand. - Add it into
fstabfile to make it persistent on the next system boot.
echo "/var/cache/swap/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab - Re-test swap file on startup by:
Note: Above commands re-checks the syntax ofsudo swapoff swapfile sudo swapon -vafstabfile, otherwise your Linux could not boot up properly.