How To: Enable a Swapfile

Yeah, yeah… I have a modern, large SSD. I have more RAM than I’ll ever possibly use. I still want/enable swap, in this case a swapfile. Imagine my dismay when I installed Lubuntu 20.04 and found there’s no swap available during the basic installation? (It’s there in 21.04.)

no swapfile
See? There’s nothing there!

Sure, I could have made a swap partition during the installation, but that didn’t seem like something I wanted to do – besides, I can always add it later. Which, of course, I did.

There are all sorts of views about whether swap is required in my situation, or in any situation, but I’m of the mind that disk space is cheap and my computer is faster than I am. So, if it has any chance of helping, it’s all good. It should also be mentioned that swap is far more complicated than ‘a place where the kernel sticks stuff when there’s no more RAM left’. In fact, it’s a lot more complicated than that. It’s where the kernel pages content that’s seldom used, and it’ll happily use swap even when there’s plenty of RAM available.

Since it’s lacking, let’s learn how to add a swapfile to Ubuntu (and official flavors) 20.04 and presumably other similarly aged variants. It’s a pretty painless process. 

Like normal, let’s crack open your terminal emulator with CTRL + ALT + T.

Now, let’s check to see if you’ve already got some swap going on.

If it shows nothing but a new line, you have no swap. If it says anything else, you’ve got swap enabled already and probably don’t need this article.

Just so you know, I personally just did this a couple of days ago, after upgrading to Lubuntu 20.04. So, I’m pulling this data from .bash_history.

Let’s make a swapfile.

Why 8 gigabytes when I have ample RAM and an SSD? Because I never, ever want to worry about it again. I want to be able to open up every app I have and leave them open for a month. You do you and decide how big you want it to be!

Now, we need to set some permissions. We don’t want anyone writing to swap, we only want root writing to swap.

Next, we need to let the OS know that’s swap space.

And turn it on with:

And you now have swap in the form of a swapfile and it’s turned on. I suppose we should make this permanent. To do this, we need to edit fstab and nano is a good tool for this.

And add this at the bottom of that document:

Those are the 0 digit, in case the font here makes it confusing. (I think I’ll try messing with the fonts.)

Either way, you should now have a swapfile that gets loaded on reboot and is currently loaded and working. You can next edit the swappiness value. In Ubuntu, it is a default of 60. If you want to edit it, you’ll have to wait for another article.

Like always, thanks for reading. It’s missing at the moment, or not working, or I’d say subscribe and get notifications of new articles. However, I’ll have to work on that. I just haven’t made the time to do so.

Smash a Button
[Total: 0 Average: 0]
About Me: I'm just some retired dude with a little bit more free time on my hands. If you want to support the site, why not help yourself out too by ordering some inexpensive web hosting so that you can start your own site?


Linux Tips

This work is licensed under a Creative Commons Attribution 4.0 International License.
SITEMAP
Exit mobile version