Mkswap and recent update seem to corrupt btrfs partition

I am kind of new to arch (endeavour os particularly), but i am not sure that the problem is in the system. In short, my laptop won’t go to hibernation after it’s lid is closed because it didn’t have a swap file to save session to. I then proceed with creating by guide written on arch wiki, using command mkswap. After doing some stuff described on arch wiki, i tried to hibernate my laptop, but nothing happened. For some days, my system worked fine, but then i tried to update using yay and reboot. Laptop didn’t reboot but it has loaded that session from when i tried to hibernate it. And after rebooting from that session, it didn’t boot up. The problem was with the system partition, but fsck did fix it. Then it didn’t boot because it couldn’t mount that corrupted btrfs partition. For information, problematic btrfs partition is right before linux system partition, and contain important data without backups.

My hypothesis is that mkswap has tried to make up swap partition by squeezing system partition, but somehow it affected btrfs partition, and i believe, it didn’t recognize it.

This is the output from btrfs check:

Opening filesystem to check...
checksum verify failed on 246038528 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 246038528 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 246038528 wanted 0x00000000 found 0xb6bde3e4
bad tree block 246038528, bytenr mismatch, want=246038528, have=0
ERROR: could not setup csum tree
ERROR: cannot open file system

Important note that system partition is fully functional, and i am using my lap in dualboot, where w10 see that btrfs partition corrupted too.

Tried btrfs check --repair:

Starting repair.
Opening filesystem to check...
checksum verify failed on 246038528 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 246038528 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 246038528 wanted 0x00000000 found 0xb6bde3e4
bad tree block 246038528, bytenr mismatch, want=246038528, have=0
WARNING: could not setup csum tree, skipping it
parent transid verify failed on 71958528 wanted 45315 found 45751
parent transid verify failed on 71958528 wanted 45315 found 45751
parent transid verify failed on 71958528 wanted 45315 found 45751
Ignoring transid failure
parent transid verify failed on 201768960 wanted 45297 found 45330
parent transid verify failed on 201768960 wanted 45297 found 45330
parent transid verify failed on 201768960 wanted 45297 found 45330
Ignoring transid failure
checksum verify failed on 202014720 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 202014720 wanted 0x00000000 found 0xb6bde3e4
checksum verify failed on 202014720 wanted 0x00000000 found 0xb6bde3e4
bad tree block 202014720, bytenr mismatch, want=202014720, have=0
ERROR: failed to read block groups: Input/output error
ERROR: cannot open file system

Tried btrfs restore -v (skipping wall of repetitive text about items):

ERROR: root [5 0] level 0 does not match 2

Could not open root, trying backup super
ERROR: superblock bytenr 274877906944 is larger than device size 101518934016
Could not open root, trying backup super

I even tried resizing it in GParted, but it didn’t allow due to errors

It looks like your system partition has been overwritten or wiped by something.

How did you use mkswap?

I feel sorry for your data loss.

1 Like
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1G count=8
sudo mkswap /swapfile
free
sudo swapon /swapfile
grep SwapTotal /proc/meminfo

That was the whole process. Yeah, now i understand that i missed the part with adding entry to fstab, but i believe it is not the problem right now…

After that manipulations, i went with systemctl hibernate to check if it has worked, but i recollect that it didn’t go to sleep.

Thank you(
But somehow i managed to revive system partition, and i believe (hope) that with btrfs i can too

That is not correct for Btrfs, because you missed deactivating CoW for Swapfile. It sounds like dd killed CoW.

Use btrfs filesystem mkswapfile instead.

Arch Wiki:

Note: For Btrfs, follow the procedure described in Btrfs#Swap file instead of the steps below.


Edit:

If you want to get your data back, try btrfs restore [device] [path], it does not change the broken filesystem, but it will copy your data to another disk if it can read the metadata. It ignores/skips some broken parts of the metadata and some of your data.

See the doc:
https://man.archlinux.org/man/core/btrfs-progs/btrfs-restore.8.en
and
https://btrfs.readthedocs.io/en/latest/btrfs-restore.html

The thing is i wasn’t creating swap for btrfs but for ext4 partition for my system.

I tried, but it gives me list of items to restore, and then exits with:

ERROR: root [5 0] level 0 does not match 2

Could not open root, trying backup super
ERROR: superblock bytenr 274877906944 is larger than device size 101518934016
Could not open root, trying backup super

…and nothing more

Also, just creating a swapfile and adding it to fstab is not enough to enable hibernation.

Some extra steps are needed, different depending if you are using grub, mkinitcpio, systemd-boot, dracut etc. in order to enabling hibernation.

You haven’t mentioned any such steps in your posts so that is why hibernation failed on your system.

1 Like

Yeah, seems to be true, didn’t pay enough attention to it and will dive into it after at least trying to salvage data from partition
Thank you for pointing out

1 Like

And just to mention: Important data without backup is NOT important data - period.

2 Likes