Intro
Have you ever wondered how to create a Linux Swap File? Well here is how to do it quickly.
I generally set the swapfile to at least 2GB+ more space then the memory (ram) size.
Machine Memory (RAM) Specifications | Swap File Size |
4GB | 8GB |
8GB | 10GB |
16GB | 18GB |
Create the swap-file
- Create the swap-file size you want (8GB demonstrated)
- sudo fallocate -l 8G /swapfile
- Set the permissions of the swap-file
- sudo chmod 600 /swapfile
- Formats the swap-file directory
- sudo mkswap /swapfile
- Enables the swap-file
- sudo swapon /swapfile
- Configures the swap-file to be used on startup
- sudo sh -c ‘echo “/swapfile none swap sw 0 0” >> /etc/fstab’
- Verify your swap file configuration is correct
- cat /etc/fstab
- If you see the following “/swapfile none swap sw 0 0” on the last line you completed the steps correctly.
Leave a Reply