Swapfile got removed after restoring a snapshot on btrfs

I have created a swapfile after installation by following a guide on Arch Wiki https://wiki.archlinux.org/title/Btrfs#Swap_file
It worked until I have restored a snapshot after a failed driver install and I get a error on each boot until I commented out the fstab entry

[FAILED] Failed to activate /swapfile
[DEPEND] Dependency failed for Swap

Here is the chain of commands I was following and the fstab entry:

sudo btrfs subvolume create /swap
sudo btrfs filesystem mkswapfile --size 8g --uuid clear /swap/swapfile
sudo swapon /swap/swapfile

/swap/swapfile none swap defaults 0 0

Now the /swap directory is just empty and doesn’t have the swapfile

I just don’t know how to proceed further. Do I just create another swapfile? How do I prevent it from breaking again? Do I need to swapoff somehow, because it doesn’t let me if the file isn’t there

How did you restore the snapshot

timeshift --restore then chose the one before I updated.
And just in case, before you ask, I have created swapfile like a month before this happened, so no, I didn’t restore before it’s creation

We can tell for sure if you share sudo btrfs sub list / but I would guess that timeshift can’t handle nested subvolumes properly.

In general, timeshift has very limited support for btrfs.

If that is the case, the best workaround is probably to move /swap to be a flat subvolume instead of nested.

ID 256 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-03_01-42-15/@
ID 257 gen 205091 top level 5 path @home
ID 258 gen 205006 top level 5 path @cache
ID 259 gen 205091 top level 5 path @log
ID 260 gen 25 top level 256 path timeshift-btrfs/snapshots/2023-11-03_01-42-15/@/var/lib/portables
ID 261 gen 26 top level 256 path timeshift-btrfs/snapshots/2023-11-03_01-42-15/@/var/lib/machines
ID 262 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-08-07_20-37-55/@
ID 305 gen 205022 top level 256 path timeshift-btrfs/snapshots/2023-11-03_01-42-15/@/swap
ID 343 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-10-31_19-00-01/@
ID 344 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-01_19-00-02/@
ID 345 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-02_19-00-01/@
ID 346 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-03_01-56-56/@
ID 347 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-03_17-34-11/@
ID 348 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-03_17-20-54/@
ID 349 gen 205091 top level 5 path @
ID 350 gen 205022 top level 5 path timeshift-btrfs/snapshots/2023-11-03_17-44-39/@

This is the output.

Probably related to this, but the root folder in Dolphin “endeavouros” opens a weird folder with that contains @ @cache @home @log timeshift-btrfs Pretty sure it opened “/” before

Any way to restore a snapshot properly, or it’s already bad if created with timeshift?

So your swap subvol is now here.

If you want to use timeshift, you can move this to the root of the partition and then mount it in /etc/fstab. After that it should work fine going forward.

So do I just move timeshift-btrfs/snapshots/2023-11-03_01-42-15/@/swap to /run/timeshift/3830/backup? That’s where everything else is stored. How do I refer to it in fstab? seems weird

Edit: nvm, it only does that when timeshift is open

You need to mount the root of the btrfs partition. Then you can move it from there. You can mount the true root by passing -o subvolid=5 to the mount command.

In fstab, you should have several btrfs mounts already. Copy one of them and replace the subvol name with subvol=swap.

Some progress. I was able to mount btrfs, create @swap subvolume and move swapfile there.
Added fstab entry:

UUID=xxx /swap        swap      subvol=/@swap,defaults,noatime,compress=zstd 0 0

But after rebooting it doesn’t mount, /swap is still empty

Did you create /swap so it has somewhere to mount it?

Did you run sudo dracut-rebuild after changing fstab?

You can test to see what the issue is by running sudo mount /swap

Of course, I wouldn’t be saying it was empty. It’s in the / directory

Didn’t know you have to do that, but it didn’t help

sudo mount /swap returns

mount: /swap: unknown filesystem type 'swap'.

It should be btrfs, not swap. That is just a subvolume that holds your swap file.

Now I try to sudo swapon /swap/swapfile and it throws

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

Perhaps it broken when you moved it? If you moved it across filesystems instead of within the filesystem you probably need to delete the swapfile and recreate it.

So I should also have /swap/swapfile none swap defaults 0 0 in fstab, right?

I think I got it working. No more errors during boot, htop shows swap. I hope it doesn’t break during next restore. :sweat_smile:

Massive thanks for your help, sorry for bothering you so much

1 Like

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