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?
Asked
Active
Viewed 3.1k times
23
-
3The 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 09: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 09: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 09:33
1 Answers
43
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
Rinzwind
- 293,910
- 41
- 570
- 710
-
2Thank 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 09: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 09:35
-
I tried to test the commands in the last part you mentioned (which are also mentioned at https://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 09: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
-
Excellent answer, very helpfull form me and ubuntu 17.04. Thank you! – Sergio Belevskij Aug 02 '17 at 16:19
-
Can we add swapfile somewhere else like - `/datadrive/swapfile` ? Will that be a problem? – pg2455 Apr 12 '19 at 12:33
-
yes. Mind though that the file MUST be accessible during boot. If datadrive is a 2nd disk that is not mounted during boot it can be a problem. `/swapfile` just means at the root. The `/` can be any existing directory – Rinzwind Apr 12 '19 at 14:29
-
Why need `cd` and not ls it directly instead? ie `$ cd / && ls -l swapfile` could be shorter as `$ ls -l /swapfile` – Nam G VU Dec 26 '22 at 05:10