How to create, remove and mount swap file on Ubuntu 17.04

Today we will learn how to create swap file on Ubuntu 17.04. Also we will learn how we can remove swap file and mount it on a Ubuntu 17.04. This tutorial can be used on any other Linux distribution as well. As you might know, the new Ubuntu 17.04 supports swap file which mean it does not require a dedicated swap partition for Ubuntu to work.

Check the current swap size

First, lets check the current swap size with the following command:

As you can see, my current system still uses /dev/sda5 partition as the swap. It is fine but next, we will create swap file and use it.

Create Swap file

I am going to create a new swap file 2048 MB in size. You may change it freely.

The command above will create a new swap file with 2048 megabytes in size and save if as “swapfile” under “/” directory.

Now continue with these commands to make it active and usable. Make sure you run these as root or sudoer.

Now check the swapfile status

As you can see my new 2 GB swapfile has been activated.

How to remove Swapfile

In case you want to remove or delete existing swapfile, do the following:

Remove or comment the swapfile entry on /etc/fstab

Next execute these command as root, not sudo.

Now check with swapon –show command. Now it should not returned anything since the swapfile has been removed and deactivated.


Leave a Reply

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