Increase swap size via file

If you find you need to increase the swapsize on linux, simply run the below.

Create a swap file – example below creates 2GB file (1024 x 2072 = 2097152 blocksize) to change the size simply times the swap you need by 1024 and append the number to the count option.

dd if=/dev/zero of=/swapfile1 bs=1024 count=2097152
mkswap /swapfile1 ; chmod 600 /swapfile1

Then enable the swap by running the below

swapon /swapfile1

To confirm the swap has been added use free -m to check.

total used free shared buffers cached
Mem: 5963 4371 1592 0 23 2140
-/+ buffers/cache: 2207 3755
Swap: 3071 0 3071

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s