Bug 1882996

Summary: Unable to disable swap from /etc/fstab if swap is directly hosted on a GPT partition
Product: Red Hat Enterprise Linux 8 Reporter: Flos Qi Guo <qguo>
Component: systemdAssignee: systemd maint <systemd-maint>
Status: NEW --- QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.2CC: dtardon, systemd-maint-list
Target Milestone: rc   
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Flos Qi Guo 2020-09-27 09:49:24 UTC
> Description of problem:
If a swap is directly created on a GPT partition, when comment out the mount entry of the swap, the swap will still be activated in the next boot.

> Version-Release number of selected component (if applicable):
systemd-239-31.el8_2.2.x86_64 (also tested other versions on RHEL8)

>How reproducible:
Always.

> Steps to Reproduce:
1. Fresh install a RHEL8.2 on a UEFI machine, create a single partitoin on the GPT disk to make it a swap partition.
2. After installation, comment out the mount entry from /etc/fstab.
3. Reboot

> Actual results:
The swap will be activated during boot despite the mount swap entry being disabled.

> Expected results:
The swap should obey the settings in /etc/fstab.

> Additional info:
This issue does not affect the swap on a LVM logical volume.

Comment 1 Flos Qi Guo 2020-09-27 09:57:10 UTC
Hello,

Testing data in my VM as follows:

------------------8<------------------8<------------------8<------------------
# uname -a
Linux rhel8u2-swap.example.com 4.18.0-193.el8.x86_64 #1 SMP Fri Mar 27 14:35:58 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.2 (Ootpa)

# cat /proc/cmdline 
BOOT_IMAGE=(hd1,gpt2)/vmlinuz-4.18.0-193.el8.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=UUID=1486bdad-4af9-425e-9747-56d51a106c06 rd.lvm.lv=rhel/root systemd.log_level=debug systemd.log_target=kmsg log_buf_len=15M

# rpm -qa | grep ^systemd
systemd-udev-239-31.el8_2.2.x86_64
systemd-libs-239-31.el8_2.2.x86_64
systemd-239-31.el8_2.2.x86_64
systemd-pam-239-31.el8_2.2.x86_64

# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Sun Sep 27 04:14:43 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=1adad4d6-152e-4ea1-bec2-501be71bda81 /boot                   xfs     defaults        0 0
UUID=9EAE-E85A          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
#UUID=1486bdad-4af9-425e-9747-56d51a106c06 swap                    swap    defaults        0 0

# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda3                              	partition	1048572	0	-2

# journalctl --no-pager --boot | less
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-fstab-generator[579]: Parsing /etc/fstab
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-fstab-generator[579]: Found entry what=/dev/mapper/rhel-root where=/ type=xfs makefs=no nofail=no noauto=no
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-fstab-generator[579]: Found entry what=/dev/disk/by-uuid/1adad4d6-152e-4ea1-bec2-501be71bda81 where=/boot type=xfs makefs=no no
fail=no noauto=no
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-fstab-generator[579]: Found entry what=/dev/disk/by-uuid/9EAE-E85A where=/boot/efi type=vfat makefs=no nofail=no noauto=no
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-gpt-auto-generator[581]: /dev/sda4: root device /dev/sda.
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-gpt-auto-generator[581]: Adding swap: /dev/sda3 <<<<------- HERE
Sep 27 17:24:13 rhel8u2-swap.example.com systemd-gpt-auto-generator[581]: /boot specified in fstab, ignoring.

# cat /run/systemd/generator.late/swap.target.wants/dev-sda3.swap 
# Automatically generated by systemd-gpt-auto-generator

[Unit]
Description=Swap Partition
Documentation=man:systemd-gpt-auto-generator(8)

[Swap]
What=/dev/sda3
------------------8<------------------8<------------------8<------------------

According to:
 - https://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/

~~~
The Discoverable Partitions Specification

TL;DR: Let's automatically discover, mount and enable the root partition, /home, /srv and the swap partitions based on GUID Partition Tables (GPT)! 
~~~

This seems a feature for the 'systemd-gpt-auto-generator', but could we disable it by default? So that we can just focus on the /etc/fstab. Thanks.

Best regards,
Flos

Comment 3 David Tardon 2020-10-05 08:41:58 UTC
(In reply to Qi Guo [Flos] from comment #1)
> This seems a feature for the 'systemd-gpt-auto-generator', but could we
> disable it by default? So that we can just focus on the /etc/fstab. Thanks.

Note that /etc/fstab is no longer the single and only source for mount/swap configuration (and it hasn't been since RHEL-7). It's just one source from which mount and swap units are generated. So an absence of a swap definition in /etc/fstab is no guarantee there is no active swap unit on the system...

That said, I tend to agree that the gpt-auto-generator should be off by default.

Comment 4 Lukáš Nykrýn 2020-10-06 14:15:42 UTC
We have agreed that we need to do some changes in documentation
1) fix the fstab manpage
2) put a comment to /etc/fstab stating that people should look at the output of systemctl list-unit-files --type mount

Comment 5 David Tardon 2020-10-06 16:17:39 UTC
(In reply to Lukáš Nykrýn from comment #4)
> systemctl list-unit-files --type mount

systemctl list-unit-files --type mount --type swap

Comment 6 David Tardon 2023-05-31 08:05:02 UTC
Some notes related to this:

1. systemd-gpt-auto-generator can be disabled by passing [rd.]systemd.gpt-auto=no on kernel command line.
2. Auto-detected (by systemd-gpt-auto-generator) swaps are ignored if there's any swap specified in fstab. Hence, adding noauto option to a swap def. in fstab instead of commenting out the line should effectively disable the swap.

Of course, what I said in comment 3 still holds.