I decided to switch from using a swap partition, to using a /swapfile.

But there's a problem. The system is still using the swap partition /dev/sda8, and not the /swapfile.

  • I created the /swapfile using the appropriate dd command, etc.
  • I changed /etc/fstab to use /swapfile instead of the old swap partition
  • I changed /etc/initramfs-tools/conf.d/resume to reflect resume=/swapfile
  • I checked that /etc/default/grub has no reference to resume or swap

Yet, when I do swapon -s or free -h, it's still showing /dev/sda8, instead of /swapfile.

Do I need to delete the /dev/sda8 swap partition for this to work?

Does 20.04.1 use any swap partition that it finds, even if it's not in /etc/fstab?

Update #1:

Just to document my /swapfile creation process...

Note: Incorrect use of the dd command can cause data loss. Suggest copy/paste.

In the terminal...

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm 16G RAM and 4G swap

Confirm this /swapfile line at the end of /etc/fstab... and confirm no other “swap” lines...

To edit, use sudo -H gedit /etc/fstab or sudo pico /etc/fstab

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation

Here's my /proc/swaps (and it's fresh from this morning)...

Filename                Type        Size    Used    Priority
/dev/sda8                               partition   9081852 0   -2

Here's the appropriate portion of my /etc/fstab:

# swap was on /dev/sda8 during installation
# UUID=071f8b0e-8e16-4f4d-90ff-a4ae9cc56e2b  none  swap       sw       0       0
/swapfile    none    swap    sw      0   0

Here's my /etc/initramfs-tools/conf.d/resume:

# RESUME=UUID=071f8b0e-8e16-4f4d-90ff-a4ae9cc56e2b

sudo update-initramfs -c -k $(uname -r) didn't help.

  • Did you clean out /proc/swaps?
    – ubfan1
    Sep 28 '20 at 23:40
  • Sometimes yes they system DOES seem to use a swap that's not in /etc/fstab. We've seen a couple questions here about that -- usually the key symptom is a slow boot; slightly over a minute to mount disks (instead of around two seconds) as the system can't find the (old) swap UUID and times out. The solution for that...which may or not be related to your problem...is to double-check the UUID in /etc/fstab. A typo could do it.
    – user535733
    Sep 28 '20 at 23:41
  • @ubfan1 Indeed, /proc/swaps shows the old /dev/sda8, and not /swapfile. Interesting enough, the file was created this morning, so it's fresh, and I assume, getting its data from somewhere else? Should I consider deleting this file, and hope it gets recreated?
    – heynnema
    Sep 28 '20 at 23:48
  • @user535733 The /swapfile line in /etc/fstab does not use a UUID. The older, commented out line for /dev/sda8, did contain the proper UUID.
    – heynnema
    Sep 28 '20 at 23:50
  • your "/etc/initramfs-tools/conf.d/resume" ???? That file hasn't been on my LTS systems for a long time. See askubuntu.com/questions/1060917/… Maybe you've run into a upgrade problem with too many old config files hanging around.
    – ubfan1
    Sep 29 '20 at 0:23

Well, it's fixed.

When I tried to do a sudo swapoff -a, it gave me a parse error on the following line in my /etc/fstab...

/swapfile    none    swap    sw      0   0

I retyped the line, and made sure to use spaces...

/swapfile  none  swap  sw  0  0

Do you see any difference?

And now it all works!

Thanks for all of the good feedback here!

  • 1
    +1 Nice find! Strange though that in 20.04 that makes a difference now. I have tabs all over my fstab file in 18.04 and it doesn't make any difference. Does that make a difference to the mount points of the regular partitions as well?
    – Terrance
    Sep 29 '20 at 0:39
  • 2
    @Terrance Funny enough, when I looked at the line using gedit, it didn't show any tabs in that line! But I just deleted all of the white space between the text, replaced it with spaces, and viola! I don't think I have any tabs, or other special characters, anywhere else in /etc/fstab.
    – heynnema
    Sep 29 '20 at 0:43
  • Good to know. So when I finally go back to 20.04 there hopefully won't be any issues with mine, but if I get parsing errors I will know where to look! =)
    – Terrance
    Sep 29 '20 at 0:45
  • 1
    @Terrance Nowhere did it tell me about any parsing problems, until I did sudo swapoff -a!!
    – heynnema
    Sep 29 '20 at 0:48

Did you remove /dev/sda8 from the fstab? You can use sudo swapoff -a and then turn on the swap for the file by typing sudo swapon /swapfile. After that, you can delete/format the partition if all works well.

  • 1
    Thanks for the suggestion. When I do sudo swapon /swapfile, free -h or swapon -s, /swapfile shows up, but after a reboot, it's gone again.
    – heynnema
    Sep 28 '20 at 23:45
  • Then please update your original question with the cotent of /etc/fstab.
    – Soren A
    Sep 28 '20 at 23:57
  • @SorenA Question updated.
    – heynnema
    Sep 28 '20 at 23:59
  • why is /dev/sda8 still in /proc/swaps? Sep 29 '20 at 0:14
  • @NinePlusTenEqualsTwentyOne Well that's the $64,000 question. See my answer, above.
    – heynnema
    Sep 29 '20 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.