How to 'clean' Swapfiles?

Hello, in an older Manjaro installation, I use the command

sudo swapoff -av && sudo swapon -av

To disable and re-enable the swap, which effectivelly 'cleans' it

However in a recent Manjaro installation I chose to not create a swap, and instead decided to create a swapfile.

How can I clean my Swapfile if needed?

You can simply delete the swap file and recreate it with the same commands you used to create it originally. Alternately, you could write a service to automatically delete and recreate the swap file at shutdown.

Here is an example of a simimilar type shutdown service I wrote:

2 Likes

Hm, deleting it and re-creating it altogether feels a bit 'risky'. Isn't there a 'softer' method?

There probably is, but if you do it at shut down there's really little to worry about. Perhaps someone else can offer another suggestion.

Did you write the appropriate entry for the /swapfile in fstab?

What kind of commands are you showing here?

That makes no sense.

After creating swapfile, write proper fstab entries.

/swapfile none swap defaults 0 0

Then,

sudo swapoff -a && sudo swapon -a

OOps, replied to wrong person. Sorry @mbod.

Oops there was a mistake in my command, sorry ignore that output, i'll delete it from my main post

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by