Script To Create A Swapfile On Linux
Category : How-to
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.
fallocate -l 512M /.swapfile chmod 600 /.swapfile mkswap /.swapfile swapon /.swapfile echo "/.swapfile none swap defaults 0 0" >> /etc/fstab