16

I could not find any information on this anywhere (and I don't want to set up a new 17.04 installation just for that), what is the default location of the swap file in 17.04?

  • 2
    The default location seems to be /swapfile. I am not sure what you mean by "...recreate ... after upgrade...". It would use the inherited swap partition happily. – mikewhatever Apr 14 '17 at 9:25
  • @mikewhatever I meant how I can switch from using a swap partition to 17.04's default setup in that regard. But I see that I probably should not have combined two questions into one. – phk Apr 14 '17 at 9:29
  • The answer is about finding, removing and creating swap in 17.04. You can follow any 16.04 method of re-creating the partition. – Rinzwind Apr 14 '17 at 9:33
27

2 commands:

~$ cat /proc/swaps
Filename                Type        Size    Used    Priority
/swapfile                               file        2097148 0   -1

and

$ grep swap /etc/fstab
/swapfile                                 none            swap    sw              0       0

So both point to:

$ cd / && ls -l swapfile
-rw------- 1 root root 2147483648 apr  2 18:56 swapfile

Disable and remove:

sudo swapoff /swapfile
sudo rm /swapfile

Create a 2Gb swapfile, set permissions, format it as swap and enable it:

sudo fallocate -l 2g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
  • 1
    Thank you, this is pretty much what I was looking for. Also thank you for the commands on how to somewhat recreate 17.04's state. I read somewhere that the size dynamic but I guess this only refers to install-time, right? – phk Apr 14 '17 at 9:34
  • yes. it does. Did not examine the effect on hibernation (but I would assume the file gets larger the more it needs). – Rinzwind Apr 14 '17 at 9:35
  • I tried to test the commands in the last part you mentioned (which are also mentioned at help.ubuntu.com/community/SwapFaq#How_do_I_add_a_swap_file.3F) but I'm getting swapon: /swapfile: swapon failed: Invalid argument for the last command. I guess I might have to disable the swap partition first but I can't ATM because swapoff: /dev/sdd8: swapoff failed: Cannot allocate memory… guess, I have to free some memory. – phk Apr 14 '17 at 9:40
  • hmmm how about using this from the live session? – Rinzwind Apr 14 '17 at 9:40
  • Figured out that the problem had to do with / being btrfs, I missed that the FAQ mentions this fact. – phk Apr 14 '17 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.