Script To Create A Swapfile On Linux

  • 0

Script To Create A Swapfile On Linux

Category : How-to

Get Social!

This 5 line script will quickly create a 512MB SWAP file that will be automatically mounted on each machine reboot. It assumes you don’t already have a swap file enabled.

The script creates a 512MB file called .swapfile on your root partition, makes it SWAP format and enables it as available system SWAP. An fstab entry is also added so that it’s mounted after a machine reboot.

You can find more detailed instructions and explanations on this blog post. With some file systems, fallocate may not work – again, take a look at  this for a work around.