Create a new Swap File
OK. I’ve written this procedure for you to follow; simple copy/paste instructions. This should create the new swap file needed.
Note: Some of these commands may take a while to complete, so try not to cancel them prematurely.
- Remove the existing swap file:
sudo swapoff /swapfile
sudo rm -f /swapfile
- Create and initialize a new 16 GiB swap file:
- The formula to calculate the
count=
value is 1024 x RAM;
Example:1024 x 16 = 16384
.
sudo dd if=/dev/zero of=/swapfile bs=1M count=16384 status=progress
- OR a 20 GiB swap file, instead:
sudo dd if=/dev/zero of=/swapfile bs=1M count=20480 status=progress
- Set permissions and format the swap file:
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
- Add a reference to the swap file in
/etc/fstab
:
- First check if the swap file line exists;
- If it does, then skip to Step 5:
cat /etc/fstab
- If it’s not there, add it with:
sudo bash -c "echo /swapfile none swap defaults 0 0 >> /etc/fstab"
- Reboot
Done.
I hope this helps. Cheers.