Masking swap.target to disable swaps (on old systemd versions)
Andrei Borzenkov
arvidjaar at gmail.com
Tue Jan 2 18:56:44 UTC 2024
On 02.01.2024 18:47, Max Gautier wrote:
> Hi,
>
> Is masking `swap.target` a reliable/supported way to disable all swaps
> (partition, file, whatever) ?
>
> I used that approach in Kubespray[1] (a k8s installer) while refactoring
> our "disable swap" steps, but it looks likes it does not work on Centos
> 7 [2] (more specifically, systemd 219) ; and in fact while it seemed
> obvious to me at the time, I didn't find it documented in
> systemd.special for instance.
>
> It does work on more recent version on systemd, my problem is that I
> don't know how recent that is. 255 is fine, 219 is not.
>
> Apparently, the .swap unit generated by systemd-fstab-generator does
> shows as "inactive" in `systemctl status` (see [2] last comment), but
> the swap **is activated** regardless.
>
> I've searched issues, PRs and commits grepping for swap.target, but I
> have not found anything relevant (the only thing was
> https://github.com/systemd/systemd/commit/90060fa6605446bef7078867423b691e4effa575,
> but it's way before 219...)
>
>
> ● dev-mapper-centos\x2dswap.swap - /dev/mapper/centos-swap
> Loaded: loaded (/etc/fstab; bad; vendor preset: disabled)
> Active: inactive (dead) since Tue 2024-01-02 02:15:31 EST; 2h 6min ago
> What: /dev/mapper/centos-swap
>
> The `bad` part in the Loaded line makes me think maybe something else is
> creating/activating that swap than systemd-fstab-generator ? From the
> systemctl man page this conveys that "the unit file is invalid or some
> other error occurred", but the generated unit looks fine to me...
>
>
> If anyone has had some success trying similar things on old systemd
> versions, please let me know if you can.
>
>
> [1]: https://github.com/kubernetes-sigs/kubespray
> [2]: https://github.com/kubernetes-sigs/kubespray/issues/10741
>
As clearly visible in "systemctl show" output
WantedBy=dev-mapper-centos\x2dswap.device
So swap is activated when systemd gets notification that device appeared.
>
> Thanks a lot for your time
>
More information about the systemd-devel
mailing list