Try this, in your preferred search engine : run swapoff in a systemd service
Thanks to everyone. It was fun. In the end, I did it with minimal intervention. In short.
-
In the file /usr/lib/systemd/system/var-swapfile.swap, add the nofail option to the line Options=
-
sudo swapoff -a
-
sudo rm /var/swapfile
-
restart
Voila!
I will wait for your lecture on saving nature in another topic.
Next time, save our (and your) time if you donât want advice and prefer do it on your own
Actually, your and inmanturbo advice was helpful. I investigated systemd more deeply.
Glad to hear it has helped
This might not persist across repairs and os updates on a stateless system.
I see that you read something, but did not understand anything. fstab is not in the system by default. It can be created to add additional swap files or partitions. And I need to disable the existing one, the entry about which is absent in the nonexistent fstab file.
Yes, I thought about that too. Letâs see what happens after the update.
Updates are done incrementally. It will likely persist until there is a systemd update. Or there is a change in the file itself. Iâm not sure if checks are run against files that are unchanged upstream. I doubt it â I would be resource intensive and (presumably) unnecessary --unless you run a diagnose or repair operation.
Maybe. However, if he always overwrites the configuration files, then why are they needed? It turns out the system can not be configured for the user. In other Linux distributions, when updating packages, the system, upon detecting changes in standard configs, offers to choose to leave the old configuration, rewrite it with a new one and even combine the old with the new one. So I hope this is supported here too.
Iâm no expert in stateless operating systems, but you might want to explore using
systemctl edit var-swapfile.swap
This will create the file /etc/systemd/system/var-swapfile.swap.d/override.conf which will survive OS updates from what I understand.
I did not have a swap file, only the swap partition that was created on installation early 2019, so I created on by creating an appropriately sized file /var/swaplfile, set the permission to 600 and ran mkswap /var/swapfile. After a reboot I now also had a swapfile.
In my /usr/lib/systemd/system/var-swapfile.swap it says âConditionPathExists=/var/swapfileâ so I disabled the swapfile and removed /varswapfile and the /etc/systemd/system/var-swapfile.swap.d/ directory. Rebooted and was left with only my swap partition again.
TL;DR
sudo swapoff /var/swapfile
sudo rm /var/swapffile
no need to change the options in /usr/lib/systemd/system/var-swapfile.swap
Other options include
sudo chmod 0444 /var/swapfile
Indeed!
âŚpaddingâŚ
Thanks!!! I tried this and it works as well. I return back old config file and made a restart. Since the swap file has already been deleted, nothing more was needed. Earlier I thought that the system will create swap file again. I think we can close the topic. Thanks to everyone for your help.