One of the new features that shipped with Ubuntu 17.04 is support for a Swap file. So instead of the traditional Swap partition, a new installation of Ubuntu 17.04 will be configured with a Swap file, just as in a Microsoft Windows operating system.

If you’re upgrading from an older Ubuntu installation, like Ubuntu 16.10, the existing Swap partition will be retained, and a Swap file will not be created. But there’s nothing stopping you from deleting the Swap partition and setting up a Swap file in its place. I had such a system running as VirtualBox guest, so after the system was upgrade, I configured a Swap file and deleted the Swap partition. Everything seems to work fine afterwards, including putting the system in and out of suspend mode.

The rest of this article will show you how it was done. The process involves creating the Swap file first, make it a permanent feature of the system, reboot the system, then delete the existing Swap partition once you’re satisfied that it works.

Please note that this was done on a system that was not installed on an encrypted Swap partition or on an LVM partitioning scheme, so keep that in mind if you decide to use this guide.

Where’s Your Swap Partition?

Before starting, use the following commands to view the amount of disk space assigned to the Swap partition:

Make That Swap And Verify It

Now that we know what we have, let’s get to work by creating the Swap file using the following commands:

If you do a long listing of the root directory and filter for the swap file you just created, you would see that it has permissions of 644. However, on a new installation of Ubuntu 17.04, the permissions are set to 600. So we need to further restrict the permissions to match what a Ubuntu 17.04 system expects it to be. Setting the permission to 600 ensures that only the root user can read and write to it. Use the following commands to perform the tasks given in this paragraph:

Related Post:  Provision Dockerized hosts on Vultr with Docker Machine from Linux Mint 18.1, Ubuntu 16.04

After that, we’ll use the next couple of commands to mark the file as Swap space, then enable it to make it usable by the system:

Now verify that the file system can see the new Swap space using the following command:

Make The Swap File Stick

So you now have two sources of Swap space, which is really not necessary. The old Swap space needs to be deleted. However, before doing that, let’s make our new Swap file permanent, so that it will remain after the next reboot. To accomplish that, we’ll have to edit the /etc/fstab file. So open it with your favorite text editor (nano is recommended for new users). Within that file, the last, uncommented entry should be for Swap, and the last two lines should read like the following:

Related Post:  Ubuntu 11.10 review

What you need to do to replace the Swap partition with the Swap file in that file, is delete the UUID=9792b062-e77c-4db9-8c11-4e87bbf65b87 part (the UUID will be different in yours), and type in /swapfile or the name you used for it. When completed, the entry for Swap will read like the following. Save and close the file:

Now you may reboot the computer. Afterwards, use the following commands to verify that the system is using the Swap file, instead of the Swap partition:

Delete The Old Swap Partition

So that’s good! The system is now using the Swap file, instead of the Swap partition, so the latter may be deleted. To delete it, launch the Disks utility from the launcher (typing “disks” will bring it up).

Three partitions will be represented – root (/dev/sda1), an extended partition (/dev/sda2), and the Swap partition (/dev/sda5). Don’t touch the root partition. Only the extended and Swap partitions will be deleted. Start by deleting the Swap partition by selecting it and clicking on the button.

Disks in Ubuntu 17.10
Figure 1: Using Disks to view the Swap partition in Ubuntu 17.04

You now have some extra space.

Delete Swap partition in Ubuntu 17.04
Figure 2: Deleting the Swap partition in Ubuntu 17.04

Next, delete the extended partition using the same method as above.

Deleting the Swap partition in Ubuntu 17.04
Figure 3: Deleting extra partition in Ubuntu 17.04

Now you’ve completely reclaimed the disk space once allocated to Swap. Was it worth it? Does it work? I’ll probably answer nyet for the first question, but it obviously works. Even putting the system in and out of suspend mode works.

Ubuntu 17.04 root partition
Figure 4: The root partition in Ubuntu 17.04

Share:

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn

Hola! Did you notice that LinuxBSDos.com no longer runs network ads?  Yep, no more ads from the usual suspects that track you across the Internet.  But since  I still need to pay to keep the site running, feel free to make a small donation by PayPal.

Subscribe for updates. Trust me, no spam!

Mailchimp Signup Form

Sponsored links

1. Attend Algorithm Conference, a top AI and ML event for 2020.
2. Reasons to use control panel for your server.
3. DHgate Computers Electronics, Cell Phones & more.

One Response

Leave a Reply to Andrew Cancel reply

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

Get the latest

On social media
Via my newsletter
Mailchimp Signup Form

Sponsored links

1. Attend Algorithm Conference, a top AI and ML event for 2020.
2. Reasons to use control panel for your server.
3. DHgate Computers Electronics, Cell Phones & more.
Hacking, pentesting distributions

Linux Distributions for Hacking

Experts use these Linux distributions for hacking, digital forensics, and pentesting.

Categories
Archives

The authors of these books are confirmed to speak during

Algorithm Conference

T-minus AI

Author was the first chairperson of AI for the U.S. Air Force.

The case for killer robots

Author is the Director of the Center for Natural and Artificial Intelligence.

Why greatness cannot be planned

Author works on AI safety as a Senior Research Scientist at Uber AI Labs.

Anastasia Marchenkova

An invitation from Anastasia Marchenkova

Hya, after stints as a quantum researcher at Georgia Tech Quantum Optics & Quantum Telecom Lab, and the University of Maryland Joint Quantum Institute, I’m now working on superconducting qubit quantum processors at Bleximo. I’ll be speaking during Algorithm Conference in Austin, Texas, July 16 – 18, 2020. Meet me there and let’s chat about progress and hype in quantum computing.