Swapfile resizing question

One (probably dumb) question, I chose swap file during install, how can I figure out the size of that file? I did not pay attention during install but is there an option to choose swap file size in calamares, I just selected the drop down menu but didn’t seem to give an option.

https://wiki.archlinux.org/title/swap#Manually

2 Likes

it is set to 500MB so you will need to resize it you need something else… what is also the main pro on using swapfile easy to resize :wink:

3 Likes

Ahh, I was looking at that page earlier today, must be Friday.

Easy peasy:

swapon --show

Edits: mine was 512 Mb

@joekamprad
Do you have to remove the swap file and create another one of a different size?

Am a bit new to swap files. I recall going through the arch wiki when I installed arch last week on one of my rigs. I think its great that EOS doesn’t make it too large per default so the user can change it later if necessary.

Right now I think of it as a safe space in case I use up too much ram or for computer sleep, similar to a overdraft account at the bank. Will need to figure out, probably not necessary with my 16 Gb ram…

So how to make it larger? Delete and create a new one?

Turn off swap. Resize (e.g. 8 Gb). Make swap usable, Activate swap

sudo swapoff -a

sudo dd if=/dev/zero of=/swapfile bs=1G count=8

edits: (thanks @joekamprad )

sudo chmod 600 /swapfile
sudo mkswap /swapfile

sudo swapon /swapfile

Edits: source of info I found
https://arcolinux.com/how-to-increase-the-size-of-your-swapfile/

Just tested, works like a charm.

2 Likes


:grinning_face_with_smiling_eyes: :stuck_out_tongue:

2 Likes

Set the right permissions (a world-readable swap file is a huge local vulnerability): // archwiki say ///
sudo chmod 600 /swapfile

2021-08-28_01-13_1
special in case you will use it for suspending system .


edit moved this out of the topic (offtopic)

2 Likes

is that a RTFM (read the fine manual) red arrow? :grin:

So basically you just turn swap off on the existing swap file. Then you change the size of the file? Make the file a swap file again then turn on swap. I’m not that familiar with the command to create a swap file. So is it different to make the swap file bigger or is the swap file actually gone because you turned swap off so you are creating a whole new larger file for swap and then turning swap back on. i.e. same command?

I think its that. with dd you create the file and overwrite the existing one to my understanding, then format into swap file.

I try to activate the swap file and it doesn’t work.

Just tried worked for me. Can you try again or check in your terminal history that you also followed each of the commands including mkswap?

Then check with

swapon --show
[ricklinux@eos-kde ~]$ sudo dd if=/dev/zero of=/swapfile bs=1G count=32
32+0 records in
32+0 records out
34359738368 bytes (34 GB, 32 GiB) copied, 15.094 s, 2.3 GB/s
[ricklinux@eos-kde ~]$ sudo chmod 600 /swapfile
[ricklinux@eos-kde ~]$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 32 GiB (34359734272 bytes)
no label, UUID=bfaebb22-b013-4ee2-9cde-24e67060f0c7
[ricklinux@eos-kde ~]$ sudo swapon /swapfile
swapon: /swapfile: swapon failed: Invalid argument
[ricklinux@eos-kde ~]$ 

Edit: What did i do wrong?

Can you try once more but start with

sudo swapoff -a

I am just guessing but swap needs to be turned off then resized.

No it say’s the same?

Strange, we have the exact same install with kde. Are you using btrfs or ext4?

Yes it’s btrfs