Few days ago we have covered an article about swap file creation in Linux using three ways which is the common method but it requires manual human effort.
Today i have found a small shell script (Two shell script, one for swap file creation and another one for removing swap file) which was written by[Gary Stafford][3]that help us to create/remove & mount swap file automatically in Linux.
By default the script create and mount`512MB`swapfile. If you want more swap space and different file name you have to modify the script accordingly. It’s not a big deal to modify the script since it’s very handy and small script, even though i have colored the line where you want to modify the script.
**Suggested Read :**[3 Easy Ways To Create Or Extend Swap Space In Linux][4]
#### How to check current swap size
Lets first check the size of existing swap space partition using**[free][1]**&`swapon`command.
```
$ free -h
total used free shared buff/cache available
Mem: 2.0G 1.3G 139M 45M 483M 426M
Swap: 2.0G 655M 1.4G
$ swapon --show
NAME TYPE SIZE USED PRIO
/dev/sda5 partition 2G 655.2M -1
```
The above output clearly shows`2GB`is my current swap space.
#### Create Swap File
Create`create_swap.sh`file and add below script to automate the swap space creation and mounting.