Swapfile instead of partition

By | 24 Aug 2009

If you don’t want to create a designated swap partition (e.g. if you plan to downsize it later) and don’t want to play around with GPartEd, you can create a swapfile instead.

To create a 512 MiB swapfile, do the following:

dd if=/dev/zero of=/swapfile bs=1024K count=512
mkswap /swapfile
swapon /swapfile

To automatically add the swapfile upon boot, add this line to the /etc/fstab:

/swapfile     swap     swap     defaults     0    0

You can later easily change the size of the swapfile by re-creating a smaller or larger one.

You only have to make sure the file is contiguous or swapon might give an error.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your post must include a link to this post.

How does this work?
Write a response on your own website and include a link to this post. Then submit your response’s URL here. Your response may appear here after moderation. To update or remove it, edit or delete your original post and submit the same URL again. Learn more about Webmentions.