1

I have installed a Ubuntu 18.04 with manual disk partitioning as simple as it gets (one primary partition with ext4 filesystem, mount point "/", reserved blocks 0%, bootable flag on, no swap!).

I have noticed now that there is active swap space anyway:

:~$ free -m|awk 'NR==1{print} /Swap/ {print}'
          total        used        free      shared  buff/cache   available
Swap:     397          0           397

And it's created as a file:

:~$ grep swap /etc/fstab
/swapfile    none    swap    sw    0    0

I could go ahead a simply turn off the swap space and delete the file as well as the fstab entry. But I would like to understand how to properly remove it from systemd as well. I can see a target defined for swap and I was wondering how to deactivate it and remove it from the list of targets before I eventually kill the swap file:

:~$ systemctl -t target |grep swap
swap.target            loaded active active Swap

Any ideas?

UPDATE

If the service is masked, it won't appear in the target list anymore and the fstab entry is ignored:

:~$ systemctl mask swap.target
Created symlink /etc/systemd/system/swap.target → /dev/null.
sre
  • 11
  • 1
  • 4
  • https://www.freedesktop.org/software/systemd/man/systemd.swap.html has all you need to know. and https://askubuntu.com/questions/816285/what-is-the-difference-between-systemctl-mask-and-systemctl-disable on how to mask or disable services – Rinzwind Aug 15 '18 at 07:56
  • Thanks! mask is indeed the right way (systemctl mask swap.target) – sre Aug 15 '18 at 08:16
  • Please note that [swap.target](https://www.freedesktop.org/software/systemd/man/systemd.special.html#swap.target) is a special target that is only there for ordering, so other units can use `After=swap.target` to ensure they run after swap has been setup (if there is any swap to set up.) In other words, you should probably **not** mask swap.target, instead just remove any swap configuration from fstab. See [documentation for swap units](https://www.freedesktop.org/software/systemd/man/systemd.swap.html) for more details. – filbranden Aug 16 '18 at 04:30
  • @filbranden Removing entries in fstab for swap are ignored, Ubuntu / Debian loads the swap anyway through systemctl. So fstab isn't the right suggestion. – Owl Jul 05 '22 at 01:14

0 Answers0