Can't set ./swapfile on btrfs compression to none

I just struggled with this myself. Turns out, you don’t need to run that command anymore.
This was bit of a pain to research, and I haven’t found anywhere with the full process for this situation yet. So, here’s what I’ve found and got working.

Assumptions: You did a standard install of Galileo Neo on a single disk using btrfs and encryption using default settings (systemd-boot and dracut) and want to install the swapfile on a subvolume.

First, create the swap file using the instructions from arch wiki for btrfs.

# sudo btrfs subvolume create /swap
# sudo btrfs filesystem mkswapfile --size 4g --uuid clear /swap/swapfile

Next, set the No_COW attribute with chattr. Note, this is the step where you found a problem. The last command in the EndeavourOS Discovery article is not needed. Setting the attribute disables compression.

# sudo truncate -s 0 /swap/swapfile
# sudo chattr +C /swap/swapfile

Now you can set the file to be used as swap with swapon:

# swapon /swap/swapfile

Finally, add the mount to /etc/fstab:

/swap/swapfile none swap defaults 0 0

Now we get to another part that isn’t clearly documented. Archwiki says the next step is to configure the resume module in initramfs, but describes how to do it with mkinitcpio. Instead, we need to do it with dracut. After some digging, I found the instructions on a post here by jsimin0. To add a module to initramfs using dracut, you need to create a conf file to load it (See Dracut Configuration File section here). Using his instructions, create the file /etc/dracut.conf.d/resume.conf and add the following:

add_dracutmodules+=" resume "
install_items+=" /usr/lib/systemd/system/systemd-hibernate-resume.service "

Now, all that’s left is to rebuild the initramfs (Note: this will rebuild for all existing kernels):

# sudo dracut --regenerate-all --force

Reboot, and hibernate should be working. Good luck!

1 Like