0

I am trying to add the swap memory and I've succeeded in doing it temporarily, but it fails when I try to do it permanently by using /etc/fstab. Could you explain, what I am doing wrong? Here are the steps, that I do on the clean Ubuntu 20.4 server installed:

fallocate -l 1G /swapfile2
chmod 600 /swapfile2
mkswap /swapfile2
swapon /swapfile2

And this works. When I go with

free -m 

I see, that the swap memory is allocated. But when add it to /etc/fstab by adding the string:

/swapfile2 none swap sw 0 0

And then disabling the swap and trying to mount it from fstab

swapoff -a
mount -a

I get no swap memory in the free -m output.

Any ideas, why can it work like that?

dice2011
  • 111
  • 1
  • 4
  • 1
    I am not sure that `mount -a` will remount swap. You might have to use `sqapon -a` or similar, Swap should remount after reboot though. – Soren A Jul 28 '22 at 19:00
  • The correct command would be `swapon -a`. Please note however, that the `fallocate` command may produce a swapfile with holes in it and be invalid. It is preferred to use `dd` to create the swapfile - see `man swapon` – Charles Green Jul 28 '22 at 19:49
  • 2
    Does this answer your question? [How do I increase the size of swapfile without removing it in the terminal?](https://askubuntu.com/questions/927854/how-do-i-increase-the-size-of-swapfile-without-removing-it-in-the-terminal) – Charles Green Jul 28 '22 at 19:53
  • @guiverc, yes, I've edited my question, thank you – dice2011 Jul 29 '22 at 04:55
  • @CharlesGreen no – dice2011 Jul 29 '22 at 05:19
  • @CharlesGreen thank you, this answeres my question – dice2011 Jul 29 '22 at 05:19

0 Answers0