Make Swapfile work on BTRFS with Luks after instalation

Hi, I have just installed EOS (KDE) on a new laptop with BTRFS, Luks encryption and Swapfile.
I can see the Swapfile in fstab:

My Fstab

UUID=82FD-BBF2 /boot/efi vfat defaults,noatime 0 2
/dev/mapper/luks-75eee996-927b-4ad7-ac2b-a27b9801daef / btrfs subvol=/@,defaults,noatime,compress=zstd 0 0
/dev/mapper/luks-75eee996-927b-4ad7-ac2b-a27b9801daef /home btrfs subvol=/@home,defaults,noatime,compress=zstd 0 0
/dev/mapper/luks-75eee996-927b-4ad7-ac2b-a27b9801daef /var/cache btrfs subvol=/@cache,defaults,noatime,compress=zstd 0 0
/dev/mapper/luks-75eee996-927b-4ad7-ac2b-a27b9801daef /var/log btrfs subvol=/@log,defaults,noatime,compress=zstd 0 0
/dev/mapper/luks-75eee996-927b-4ad7-ac2b-a27b9801daef /swap btrfs subvol=/@swap,defaults,noatime 0 0
/swap/swapfile swap swap defaults 0 0

Now what I understand is that I just have to follow the guide from @joekamprad from the Wiki here: https://discovery.endeavouros.com/storage-and-partitions/adding-swap-after-installation/2021/03/

As the Swap already appears in the FSTAB, I believe I don’t need to edit the FSTAB.
But do I need to follow those first steps :

sudo truncate -s 0 /swapfile
sudo chattr +C /swapfile
sudo btrfs property set /swapfile compression none

Or is it enough to just create the file with `dd and follow from there the instructions of the Wiki ?

Thanks in advance, I just don’t want to mess with this !
If useful : I don’t need hibernation, only more extra memory.

If I am reading the relevant ArchWiki articles correctly, there has been some recent changes to the instructions.

See:

https://wiki.archlinux.org/title/Btrfs#Swap_file

So assuming that

# chattr +C */path/to/swapsubvolume*

is already set on /swap, I think you could just remove the “old” swapfile and create a new one with desired size:

sudo swapoff /swap/swapfile
sudo rm /swap/swapfile
sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=512 status=progress
(change the count= to the size you wish)
sudo chmod 0600 /swap/swapfile
sudo  mkswap -U clear /swap/swapfile
sudo swapon /swap/swapfile

And check:

sudo swapon -s

Please see also: https://wiki.archlinux.org/title/Swap_file#Swap_file_creation

Hi @pebcak , thanks for the infos.
I followed your suggestion and all went OK until the last command

sudo swapon /swap/swapfile

which returned this:

swapon: /swap/swapfile: swapon failed: Invalid argument
1 Like

I am sorry for the inconvenience!
I tried to replicate the steps above and, even though they follow the wiki, to my surprise, it resulted in the same error.

However I tried with the following steps and it works on my end:

1. sudo -s

2. rm /swap/swapfile

3. chattr +C /swap

4. dd if=/dev/zero of=/swap/swapfile bs=1M count=512 status=progress
   (change the count= to the size you wish)

5. chmod 0600 /swap/swapfile

7. mkswap /swap/swapfile

8. swapon /swap/swapfile

And finally check with:
# swapon -s

I hope it will work out this time.

3 Likes

YES! it works. So there is need to be in “root” and not to sudo each command… OK, strange but indeed it works. Good intuition… or experience.
And @pebcak , don’t be “sorry for the inconvenience”. You are helping, and as they say in India (and other places) the “Path matters more than the result”. So the fact that you take the time to answer is already a great help !
All the best.

3 Likes

That’s great! I am glad it worked!

Not really, it was just for saving on typing sudo each time.

I take it as a complement! Hopefully both!
I had to try it somewhat differently than what we did before and it just worked!

That’s a great lesson! Thank you for that!

I am so grateful and so indebted towards this community so the little I can do to contribute is to help around the forum. I am mutually benefited by doing so as well. It makes me to do some research, reading wiki articles and little by little enlarging my Linux experience.

Have a nice weekend @pierrep56!
And all the best for you as well!

3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.