Create a new swap file on Linux
Creating a new swap file on Linux requires a non-sparse file. The usual way is to use dd to copy bytes from /dev/zero to initialize the file, but you can also use hdparm --fallocate.
The first option is as follows:
#dd if=/dev/zero of=/var/newswap bs=8192 count=1048576
This usually takes a while, so I use hdparm
#hdparm --fallocate 8388608 /var/newswap
Once your file is created, set it up as swap
#mkswap -L myswap /var/newswap
Turn it on using swapon
#swapon /var/newswap
To view active swap space, take a look at /proc/swaps
#cat /proc/swaps
Filename Type Size Used Priority
/dev/sda5 partition 4192252 0 -1
/var/newswap file 8388604 0 -2
Written by Russ Lankenau
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Linux
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#