Here we will see how we can increase the SwapSize in Ubuntu!
- Open Terminal
- Enter "sudo swapon --show"
- This is show you the details of current swap size
- Enter "df -h"
- This is to see how much disk space you have.
- Now Turn the swap off using "sudo swapoff -a"
- This will allow us to write to swap file without being interrupted by File in Use error
- This is the important part and requires some knowledge if you want to understand what is going on under the hood. But high level understanding here is as follows:
- If have xyz GB of ram, your swap file size will be XYZ GB + 2GB at the minimum. In my case, I had 16GB of Ram on Laptop, but current swap file was of 2GB only. When created automatically using the command that follows, it made 27GB in SwapFile.
- Enter "sudo dd if=/dev/zero of=/swapfile bs=5M count=5120 status=progress"
- Wait for the entire process to end.
- Now lets give this file root only permissions: "sudo chmod 600 /swapfile"
- Now mark this file as swap space file: "sudo mkswap /swapfile"
- Now make this file permanent so that restart of system doesn't revert it to previous state:
- "echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab"
- Now turn the swap back on using "sudo swapon /swapfile"
- Use HTOP to see change in swap size.