Ubuntu Linux: Create swap file

Written by Guillermo Garron .
Date: 2013-01-22 19:40:13 -0400

Memory in Linux is can be increased by create swap space, it can be a special partition, or a file which will work as a swap file. We will cover now, how to create a swap file.

Create a swap file

sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k


  • bs=1024: Says that each block is made of 1024 bytes
  • count=512K: Says that there will be 512K blocks, so, 512 Megabytes of swapfile.

You can change count to 1024K if you want 1 Gigabyte of swap, more than that is not really recommended.

Format the file as swap

sudo mkswap /swapfile

Enable the swap

sudo swapon /swapfile

Make it permanent

To make the swap space available after every boot, edit the /etc/fstab file and add this line.

/swapfile       none    swap    sw      0       0 

Set the permissions to the swap file

sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile

If you enjoyed the article, please share it

twitter | facebook | google+ | linkedin | email | reddit

comments powered by Disqus



My name is Guillermo Garron. I am telecommunications engineer from Bolivia

I like technology a lot, and this site is mainly dedicated to that

Social feeds

rss | twitter | email | google+

Posts via email

If you use the letter icon above and subscribe to my tinyletter newsletter, you will get one to two emails, related to this site, or not. If what you want is to get the posts of this site via email, use the form below

Enter your email address:

Delivered by FeedBurner