Enabling swap on Ubuntu Core


#1

Ubuntu Core images come with everything needed to enable swap, but it’s disabled by default. To enable it:

  1. edit /etc/default/swapfile and set SIZE to a non-zero value.
  2. sudo systemctl enable --now swapfile.service

That’s all that’s needed.

Now some more details:

  • /etc/default/swapfile is writable, but some editors might be confused by its directory being readonly. The provided vi is fine with it though.
  • If SIZE is zero, even if the service is enabled and started, no swapfile is created (see the /usr/bin/mkswapfile shell script for details).
  • If you set FILE to something on a different partition, you should add an appropriate After= to the service file.
  • To add that After=, edit /etc/systemd/system/swapfile.service, and systemctl daemon-reload before you enable and start the service.

That’s it.


Swap on core
Enabling swap with swap-partition on Ubuntu Core
#2
  • It’s not clear what a “core image” is. Is it Ubuntu Core, or something else?
  • Why is swap disabled by default? (In other words, are there any drawbacks to enabling it?)

#3

Yes, the “image” refers to Ubuntu Core (nothing of the above would work on a classic setup anyway).

Typical Ubuntu Core installs run from block devices that are not particulary safe from wearing out through writing to (and deleting) the same block on disk all the time (SD cards, EMMC flash disks, SSDs) … which is what swap usage induces.

So enabling swap is an optional task (but would surely be nicer to handle if there was just a core config option you can set).


#4

In that case, this should be in Ubuntu Core docs, not Snapcraft docs.


#5

These aren’t the snapcraft docs, but, yes this would probably be better in Ubuntu Core docs. I don’t know if those exist, if they are current, how “findable” those are, nor how to edit or otherwise update them.

I’ll update this to explicitly say Ubuntu Core though (you could’ve done it as well, as it’s a wiki).


#6

The “docs” category in ths forum is a wiki for all of snaps, snapcraft, snapd and Ubuntu Core, so unless we start fragmenting the docs category into little pieces, i dont think the post is wrong in this place…

Also, since the described procedure isnt really a core option you can set but requires to edit files on a running system i dont think it qualifies for the official documentation either (something like “snap set core swapsize=50M” that performs the steps above in the backend would qualify IMHO, but that is not implemented atm.)


#7

I first encountered this article on the docs prototype site and it seemed out of place, hence my first question.

Most people building snaps are not using Ubuntu Core. There are separate sites for the snap platform docs and the Ubuntu Core docs. A few documents may belong on both sites, such as the assertions reference. But most, like this post, would not.

So, if one forum will be used to write material for both, there needs to be a way to distinguish the two. That’s all. Sorry for the noise.


#8

but all people using Ubuntu Core need to build/use snaps :wink:

we could simply start using tags to distinguish if this is really required (i dont think it is, but you seem to feel the other way)