2

Question

why is my swap partition being used after reboot?

Context

My system has two swap areas in Linux Ubuntu:

sudo swapon --show
NAME                 TYPE      SIZE USED PRIO
/dev/nvme0n1p7       partition 977M   0B   -2
/media/EXT4/swapfile file        4G   0B   -3

I disabled swap partition:

sudo swapon --show
NAME                 TYPE      SIZE USED PRIO
/media/EXT4/swapfile file        4G   0B   -3

and edited /etc/fstab:

UUID=8a098c42-9f6a-4f04-8dac-87298f1f460d /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/nvme0n1p2 during installation
UUID=CC3B-B509  /boot/efi       vfat    umask=0077      0       1
# swap was on /dev/nvme0n1p7 during installation
# UUID=0379c3e0-faa9-4bd8-a7ce-4bc1d2d1d9a2 none            swap    sw              0       0

# 4TB HDD, linux partition
UUID="847df9cc-ba11-469f-a36e-ac4228c005f8" /media/EXT4 ext4 user,errors=remount-ro,auto,exec,rw
# 4TB HDD, windows partition
UUID="2A2506563E8741C6" /media/NTFS ntfs user,errors=remount-ro,auto,exec,rw,uid=1000,gid=1000

/media/EXT4/swapfile none swap sw 0 0

Problem

after reboot the partition is used as swap area:

sudo swapon --show
NAME                 TYPE      SIZE USED PRIO
/dev/nvme0n1p7       partition 977M   0B   -2
/media/EXT4/swapfile file        4G   0B   -3

Further information

Here is the information of linux-swap:

linux-swap information

it shows the UUID in fstab is commented out for swap partition.

These are the flags for linux-swap: (none are used)

enter image description here

I do not have Autofs installed on my system.

  • Don't you have a second fstab-line regarding the swap-file? Please show us the complete output of cat /etc/fstab. – mook765 Mar 10 '19 at 13:54
  • yes, of course I have a couple of mounting points. I added the complete fstab, it shouldn't be relevant, though. There's also a /etc/fstab.bak which has the linux-swap. – linuxUser123 Mar 10 '19 at 14:07
  • Well... your fstab still has this definition in there: /media/EXT4/swapfile none swap sw 0 0 ... suggesting that you didn't actually disable it. – Thomas Ward Jul 28 '19 at 00:35
  • I had to delete the swap partition with fstab to disable swap after reboot. Just removing it from fstab didn't work on Ubuntu 16.04.6 – Alex G Jul 28 '19 at 00:25
  • @ThomasWard my system has two swap areas. The intention is to use the one on /media/ – linuxUser123 Jul 29 '19 at 06:35

3 Answers3

4

As well as @Raffa's suggestion, you may also need to disable the automatic activation at boot of detected swap space in systemd, to do this find out the responsible .swap unit by running:

sudo systemctl --type swap

This should then list out the current swap units in the following format (In my case the swap unit name was dev-sda7.swap):

  UNIT          LOAD   ACTIVE SUB    DESCRIPTION
  dev-sda7.swap loaded active active Swap Partition

LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

Disable this swap unit from starting at boot by masking it:

sudo systemctl mask dev-sda7.swap
2

It appears that you have indeed disabled that swap partition in your /etc/fstab file.

I would ,however, suggest one more step.

  1. Please, first turn all swap off swapoff -a. Then type in the terminal:

    sudo nano /etc/initramfs-tools/conf.d/resume

Check if the UUID for disabled swap is in the file.

If yes, please comment it out by adding # before that line. Save the file and exit.

  1. Recreate the boot images:

    sudo update-initramfs -u -k all

  2. Update GRUB:

    sudo update-grub

Then, please reboot and see if this works.

You might as well want to delete your swap partition and extend your system partition after that to utilize the unused space.

Raffa
  • 35,113
1

@PJConnol,

Thanks, you were perfect! This solve it for me.

First disable an entry for swap in /etc/fstab:

Execute

# Be careful, if possible reboot before then execute next steps
swapoff -a 

sudo systemctl --type swap

UNIT LOAD ACTIVE SUB DESCRIPTION dev-sda7.swap loaded active active Swap Partition

LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type.

then disable it:

sudo systemctl mask dev-sda7.swap

then reboot and verify

free -m
               total        used        free      shared  buff/cache   available
 Mem:           7933        1560        5011           3        1361        6130
 Swap:             0           0           0