Ask Your Question

Set up use of swap partition with systemd

asked 2013-11-14 18:49:43 -0500

pgueckel gravatar image

updated 2013-11-15 11:43:22 -0500

I just installed Fedora 20ß. I have a swap partition, but I forgot to tell the installer that I want to use it. Fedora 20 booted without the swap, so I ran:

swapon -L SWAP-sda2

to get it started.

I want to have it used automatically every time I boot the system. The old way it to put a line into fstab; the new way is to do some stuff with systemd files.

Just tell me how to do it in plain English. Read the manual is not an answer. Eg., link this file here, or create a file with exactly these contents, or edit such and such a file with these new contents, or run these commands, etc.

edit retag flag offensive close merge delete


man systemd.swap ?

skytux gravatar imageskytux ( 2013-11-14 21:11:47 -0500 )edit

Somewhere in the manual, it also says that systemd will automatically create an fstab entry when none is present. This is partly true, in that an entry is created, but the entry that is created is false. The entry was: UUID=<alphanumericstring> swap. This is incomplete and when I rebooted, an error occurred: findmnt: fstab parse error line X. There was no swap after rebooting. I corrected the erroneous line by appending 'swap defaults 0 0' to the line in fstab and rebooted and now there is swap being used. But this does not answer my question: How can I get systemd to use swap automatically?

pgueckel gravatar imagepgueckel ( 2013-11-15 11:35:07 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2013-11-19 11:50:13 -0500

pgueckel gravatar image

Unfortunately, there have been no correct answers yet.

The one answer given by Ahmad Samir is incorrect. There was NO swap line in fstab, or rather, the automatically generated line in fstab was incomplete, containing only UUID= and one swap, but missing the second swap, defaults and the two 0s. This resulted in a findmnt parse error with the result that swap was NOT used automatically at boot. I had to manually enable it to have it used by running swapon -L <swaplabel>; and I had to manually complete the erroneous swap line in fstab to get swap enabled automatically at boot. On the laptop computer, the situation was similar, with the difference being that there was no swap line in fstab at all. Again, I had to manually enable swap and had to append the swap line to fstab.

A partial solution to the problem is to manually append to fstab:

UUID=<alphanumericpartitionkey> swap swap defaults 0 0

As stated in the systemd manual and as can be confirmed with swapon -s, this works, but it is NOT what I asked to know in my original question. Systemd will convert this to a unit file, but that is not the same as creating a correct unit file directly and without having recourse to the old fstab system that systemd appears to aim to obsolete eventually. I had clearly asked for the systemd method using unit files.

edit flag offensive delete link more

answered 2013-11-15 03:26:15 -0500

Ahmad Samir gravatar image

updated 2013-11-15 03:26:40 -0500

I think you don't need to do anything; I have a swap partition, and I didn't have anything in /etc/fstab about it (I have enough RAM and don't need swap), and systemd still enabled it automatically at boot. To actually disable it I had to mask it manually (in my case 'systemctl mask dev-sda7.swap').

Try rebooting and see if systemd enables it on its own..

edit flag offensive delete link more

Question Tools


Asked: 2013-11-14 18:49:43 -0500

Seen: 3,997 times

Last updated: Nov 19 '13