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.

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

    Thanks for sharing this, very helpful :-)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: