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:

# This command will list the partition sued for Swap

swapon --show

> NAME         TYPE     SIZE     USED     PRIO
> /dev/sda5  partition  1.5G     3.9M      -1

# alternatively, you could use the next command to view the same info

free -h
>         total     used     free 
-           -        -        -
> Swap:   1.5G      3.8M     1.5G  

# 

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:

# Create a Swap file
# /swapfile is the name I used here, but you can call it anything
# I assigned it 2 GB of disk space, but you can change that too

sudo fallocate -l 2G /swapfile

# 

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:

# Listing and changing the permissions of the Swap file
# > Indicates output

ls -lh / | grep swapfile
> -rw-r--r--   1 root root 2G May 12 18:30 /swapfile

# Then change the permissions to 600

sudo chmod 600 /swapfile

# 

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:

# Mark file as Swap space

sudo mkswap /swapfile

# Then enable it

sudo swapon /swapfile

# 

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

# > indicates output

swapon --show

> NAME         TYPE     SIZE     USED     PRIO
> /dev/sda5  partition  1.5G     3.9M      -1
> /swapfile    file      2G       0B       -2

# 

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:

# swap was on /dev/sda5 during installation
UUID=9792b062-e77c-4db9-8c11-4e87bbf65b87 none            swap    sw     0         0

# 

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:

# swap now in /swapfile
/swapfile         none      swap     sw              0       0

# 

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:

# > indicates output

swapon --show

> NAME         TYPE     SIZE     USED     PRIO
> /swapfile    file      2G       8.9M       -1

# alternatively, you could use the next command to view the same info

free -h
>         total     used     free 
-           -        -        -
> Swap:   2.0G      8.8M     2.0G 

# 

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).

Related Post:  The state of manual LVM and full disk encryption configuration in Ubuntu's Ubiquity

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.

19 Responses

  1. I am using windows 8 OS and i also installed Ubuntu 12.10 in other drive, but at booting process only windows 8 are shown. How i boot Ubuntu.

  2. Hi, I put my 2nd hard drive on my laptop where CD Reader was located before, and I dont think it is possible to boot the second drive first. any ideas?

  3. An extremely well written and illustrated guide to dual booting. The linked articles regarding partitioning and dual booting advice were good too (but the swap partition advice link was dead).

    I’d stick with the EasyBCD step as it’s beginner and Windows friendly. The aptly named grub is ugly and not easy to tinker with or repair.

    Thanks for your help.

  4. I have just installed Ubuntu 11.10 in the 2nd HDD (first has Win 7)
    according to your instructions and everything worked fine, thank you for the excellent article

  5. Hello,
    I did all the steps but after booting into Ubuntu i get a screen with ubuntu wallpaper in it and it is totally blank and there is nothing .Finally i have to shut down the computer from the cpu button.

    1. Also i can login using my password..but after login i get this blank screen with nothing on it but the default ubuntu wallpaper

  6. hi,

    i followed all your steps, and everything went well.

    but when i get the options screen on whether to load windows 7 or ubuntu 11.10 and when i select ubuntu 11.10, nothing happens but just a blank screen with some GRUB syntax appears, thats it!!!

    please help me out on this issue

    1. This tutorial will soon be modified to show that the EasyBCD step is not required. Here’s what you could do.

      After installing Ubuntu, reboot the PC, get into the BIOS and make the second drive the default boot disk. so, when you reboot, you will see GRUB’s menu, with an entry for Windows and Ubuntu. That should be all you need. Ignore the EasyBCD part. It just adds an unnecessary complexity to the process.

  7. There is a better way for even Triple Boot possible with Win XP, Win7 and Ubuntu 11.10 on the same hard disk. It is as simple as follows.

    First install WinXP on one primary partition.

    Second install Win7 on another primamry partition.

    Now we have WinXP and Win7 dual boot on same hard disk on two separate partitions.

    Running on WinXP, download and run “wubi.exe” to install Ubuntu 11.10 as a “big” file on hard disk. The file may locate on any Windows partition.

    Reboot computer you will see Ubuntu as one of the boot options. To start it correctly, choose “Previous System” first, then choose Ubuntu.

    Now we have Triple Boot WinXP/Win7/Ubuntu ; )

    Try yourselves and have fun !

  8. I have 2 internal 1TB hard drives, and I dual-boot Windows 7 (strictly for games) and a Ubuntu spinoff. My second drive is mounted as /home whenever I make a new installation, and my boot drive has a 650GB Windows partition (for lots of games) and the rest for the Linux system drive, which is an embarrassingly large amount for Linux with 5 GUIs installed.

    That’s what *I* do…

  9. The easybcd step is completely useless, it is not needed to change your win hd at all. grub2 is all you need and you have it already. Just set 2nd hd as default in your bios. If you are slow you can set the grub timeout in /etc/default/grub and in the case you want win first you rename /etc/grub.d/30_os-prober to /etc/grub.d/09_os-prober. after that change run update-grub (also needed for timeout changes).

    In the case that your linux and win install is using efi bootloader (which you do not describe, but it is also possible) you can add a boot entry for win to boot from another hd (basically another efi boot setting not hd) by default. To do so create a new /boot/grub/custom.cfg – the file is sourced on boot, no need for update-grub. Btw. it does not matter which distro you install, it just needs a recent grub2 bootloader. maybe os-prober/grub2 will find those files automatically at one point so that this step is not needed anymore.

    if search -nf /EFI/Microsoft/Boot/BOOTMGR.EFI ; then
    menuentry ‘Microsoft Bootmgr’ {
    search -sf /EFI/Microsoft/Boot/BOOTMGR.EFI
    chainloader /EFI/Boot/BOOTX64.EFI
    }
    fi

    1. The method you described is one method. The EasyBCD step is another. Choices. Use the one that you feel most comfy with.

      And a new user will feel a lot more comfy using the method from this article than messing with GRUB files.

      1. They are already correct if you don’t use efi. os-prober finds other os incl. windows systems and those are automatically added to the grub menu. Just W7/8 in efi mode is not automatically found, but those installs are rare. It even finds recovery win partitions which you might not like to have in your menu, then you would need to hack it a little bit. By default the bios changes the bootflag to the recovery when you press a special function key at boot, otherwise it is hidden, but os-prober lists em for direct boot too. What you should not forget, if you only want to boot Linux from time to time you could use als quick boot selection and select the other hd, otherwise Linux would be completely hidden.

    2. I think a possible advantage to have Windows manage the booting is that if you remove the second disk, Windows can/will still boot.

      If you boot to disk 2, and later want/need to remove it, then you can tell bios to boot from disk 1. But if you are booting from disk 2 then you can NOT just remove disk 1 and keep going as with only a single disk in the system it will become disk1 and GRUB may get “confused”.

Leave a Reply

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

Get the latest

On social media
Via my newsletter
Mailchimp Signup Form

Partner links

1. Attend Algorithm Conference, a top AI and ML event for 2021.
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.