Swap partition not automatically mounted

I have 2 ssds in my laptop and put root on one and swap on the other.

$ sudo blkid
/dev/nvme0n1p1: UUID=“CDAB-2347” TYPE=“vfat” PARTLABEL=“CLR_BOOT” PARTUUID=“d027da17-27f5-46ea-a50f-bc5d1a1caa0a”
/dev/nvme0n1p2: LABEL=“root” UUID=“73e338de-47d6-4a9a-b7cf-37b013a5cd41” TYPE=“xfs” PARTLABEL=“CLR_ROOT” PARTUUID=“07cead23-c2a3-485e-981b-d6d6cb1a2c35”
/dev/nvme1n1p1: LABEL=“swap” UUID=“80cdbbf0-057e-4487-9688-536b9733f625” TYPE=“swap” PARTLABEL=“CLR_SWAP” PARTUUID=“60cbf5ff-05e4-4421-ba5f-b650060f4f66”

However, it seems there is no swap mounted:

free -m

          total        used        free      shared  buff/cache   available

Mem: 7694 2769 1237 531 3687 4086
Swap: 0 0 0

and cat /proc/swaps also shows nothing.

It does not seem to be much of a problem running the OS but I still wonder how to fix this properly.

It does not seem to be much of a problem running the OS but I still wonder how to fix this properly.

You need to create /etc/fstab and add your swap partition there.

Usually systemd mounts swap automatically when it is in the same
drive as the root partition.

1 Like

As swapon is part of linux and relies on the existence of the /etc/fstab file,
As Clear Linux is stateless and provides no /etc/fstab file
Then we have a problem :frowning:
I just broke my swap and do not want to rebuild a full /etc/fstab by myself.
Two actions possible :

But we need something, don’t we ?

2 Likes

systemd is not consistent with its documentation “All swap partitions on the disk containing the root partition are automatically enabled.” (systemd)

In my case, systemd automounts only the first swap partition. Even after creating another swap partition with mkswap, swapon, and reboot. If you don’t want to use the first swap partition (say /dev/sda5) you can stop the automounting with
systemctl mask dev-sda5.swap

however systemd will continue to ignore other swap partitions on the root drive, even one labelled CLR_SWAP and with the correct swap PART_ENTRY_TYPE, and fstab or equivalent is required to make the swap mount persistent.

There is some caveat about a no-auto partition flag, but I have not set it and can find no linux tool that exposes it; GParted shows other flags but not no-auto.

It seems to me systemd is not clear but opaque, varying from its documentation in this mounting process, just as it does in its boot sequence points. Is there something I am missing in the documentation?

EDIT: Whilst I’m very attached to my theory, it’s wrong :grinning:
See Tidda’s comment in the next post.

This bit is validish though:

The noauto @philip1 mentions is a related to file system mounting. As such, you wont see it show up in a partitioning tool, since it’s actually not a partition flag or label etc (it basically lives at least one level higher in the heirarchy, as it’s associated with the file system that sits on top of a partition). You can see these options listed against the mount points here:
grep '/dev' /proc/mounts

Incorrect stuff below


My understanding at present (and I could be wrong here), but I think Clear only looks at the partition labels (for instance CLR_SWAP) as part of the installation process of clr-installer (or it’s GUI equivalent).

Those labels just serve as a way of identifying to Clear which partitions the user wants to assign for different purposes. As part of the install script for OS config, I guess it probably ceases to use the labels and likely correlates each known label, to it’s specific UUID or PARTUUID and uses that from there on out. UUID and PARTUUID is consistent across reboots, and much less likely to suffer name/identity collisions…at least; less likely than user applied and editable partition labels.

So, that’s my reasoning as to why they would probably do it, but I don’t know, it’s a bit beyond my knowledge to hunt through the source of the install scripts at this stage.

So to spell out my theory, I guess if you label a partition as CLR_SWAP, during the install script the UUID or PARTUUID specific to that label is probably used to build native systemd unit files (thus avoiding /etc/fstab) to mount that resource (such as swap). The corollary then would be (based on my limited understanding), that this is a one shot deal during the install process, it probably does not implement boot time scripts for successive boots in order to look for user partitions that get added at a later date, instead assuming you will take care of that in /etc/fstab, with your own systemd unit files, or (as per @miguelinux’s comment) by relying on systemd implementations that work for more common topologies:

Usually systemd mounts swap automatically when it is in the same
drive as the root partition.

Anyway, if one of the dev team are bored, they could probably clarify all this, but I suspect they are busy with other things.

2 Likes

It’s not the UUID or the PARTUUID, it’s the Partition Type UUID (PARTTYPE).

Run “lsblk -o +PARTTYPE” to show them.
Swap should have a value of 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f to be recognized.

Have a look at the man page of systemd-gpt-auto-generator for the systemd magic behind it all.

3 Likes

Thanks Tidda!
Linky: systemd-gpt-auto-generator

1 Like