How to Add Swap Space in Linux
If the swap space is not enough, you can add a new swap file to your server. Login as root user and then run the following commands to add 10GB of swap space:
1 2 3 |
dd if=/dev/zero of=/path/newswap bs=1024 count=10000000 mkswap /path/newswap swapon /path/newswap |
You can verify if new swap space was added successfully:
1 |
swapon -s |
If you want to remove the swap file, run the following commands:
1 2 |
swapoff /path/newswap rm /path/newswap |
If you want to add this swap space permanently, you need to include it in your /etc/fstab file. Edit the fstab file and add an entry that looks like this:
1 |
/path/newswap none swap pri=5,defaults 0 0 |