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?
mount -a
will remount swap. You might have to usesqapon -a
or similar, Swap should remount after reboot though. – Soren A Jul 28 '22 at 19:00swapon -a
. Please note however, that thefallocate
command may produce a swapfile with holes in it and be invalid. It is preferred to usedd
to create the swapfile - seeman swapon
– Charles Green Jul 28 '22 at 19:49