HOWTO Enable temporary swap file on GNU/Linux

GNU/Linux supports swapping to a file on any filesystem, with reasonable performance impact since kernel 2.4. This might be useful whenever needing a temporary increase in available memory, I'm writing this article with that goal in mind. Create a zero-filled regular file (following example would create a 1024x1M=1G swap size): dd if=/dev/zero of=/.swapfile bs=1024 count=1M Setup a swap area in it:
mkswap /.swapfile
Activate swap to this file (would not survive a reboot):
swapon /.swapfile
To check it did it:
swapon -s
Disable swap to this file:
swapoff /.swapfile
Of course, the file is not deleted on reboot, and you might reuse it several times.

Comments