How to add permanent swap partition and enable hibernate after installation

I would like to be able to hibernate EndlessOS. Reading through various posts, I added successfully (with gparted via booting Knoppix from USB) a 10G swap partition and can now do a sudo swapon /dev/sda5 on the commandline.

How can I make this permanent and get the chance to enable hibernation to disk? As far as I understand OStree, I should not modify /etc/fstab directly.

eos-diagnostic-200724_094900_UTC 0200.txt (1012.2 KB)

Hi,
yes your assumption is correct. /etc/fstab isn’t used on OSTree based systems. I would recommend you the following procedure:

Create the corresponding /etc/fstab entry

Add the swap you want to enable to /etc/fstab. In my case, i added some swapfile as a demonstrator:

/root/swapfile none swap sw 0 0 

Even if /etc/fstab isn’t used during boot by EOS, it’s used by some other commands like swapon

Allow to activate swap as a regular user

As root, ceate a file /etc/sudoers.d/swapon with the following content:

ALL    ALL = (root) NOPASSWD: /usr/sbin/swapon

This will allow you to run sudo swapon -a to activate swap without the need to enter a password

Run the command on login

Create a file ~/.config/autostart/mount.desktop with the following content:

[Desktop Entry]
Name=Activate Swap
Exec=sudo swapon -a
Type=Application

Now make it executable:

chmod +x ~/.config/autostart/mount.desktop
gio set  ~/.config/autostart/mount.desktop metadata::trusted yes