Home > English, GNU/Linux, OSS Solutions, Tech Crunch > HOWTO Enable temporary swap file on GNU/Linux

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.

  1. NoBody
    November 18, 2012 at 9:56 pm

    Thanks for sharing this, very helpful :-)

  1. No trackbacks yet.

Leave a comment