I have a computer running Debian 10 Buster (testing), kernel version:

Linux (none) 4.14.0-3-amd64 #1 SMP Debian 4.14.13-1 (2018-01-14) x86_64 GNU/Linux

The root filesystem is Btrfs with a single device.

Recently, I encountered the issue where the filesystem became mis-balanced, and I followed the steps on Mark's Blog to rebalance things. My system was so full, I had to follow the steps under "Balance cannot run because the filesystem is full", including creating a 3GB file with dd and adding it to the btrfs filesystem as a loop device. This allowed it to be balanced successfully.

However, I forgot to remove the loop device before rebooting. Upon reboot, I am thrown into an initramfs prompt with the errors:

BTRFS error: failed to read chunk tree: -5
BTRFS error: open_ctree failed 

Here's btrfs filesystem show:

bytenr mismatch, want=167954300928
Label: none uuid: <uuid>
             Total devices 2 FS bytes used 91.58GiB
             devid      1 size 151.03GiB used 111.04GiB path /path/to/device
             *** Some devices missing

btrfs check returns:

bytenr mismatch, want=167954300928, have=0

Trying to partially mount the filesystem in order to remove the missing loopback device, mount -o degraded,ro /path/to/device /mnt returns:

BTRFS error: failed to read block groups: -5
BTRFS error: open_ctree failed

The only other info in dmesg is it complaining about the missing device with id 2.

Running btrfs rescue chunk-recover returns:

Scanning: DONE in dev0
open with broken chunk error
Chunk tree recovery failed

Trying to restore from the filesystem btrfs restore /path/to/device /mnt results in:

bytenr mismatch, want=167954300928, have 0
Could not open root, trying backup super
bytenr mismatch, want=167954300928, have 0
Could not open root, trying backup super
ERROR: superblock bytenr 274877906944 is larger than device size 162164375552
Could not open root, trying backup super

The situation seems similar to this forum post, where a new device was added briefly and then remove, but it is not exactly the same scenario.

My question is:

  1. What steps can I take to recover the system in its current state (perhaps by removing the missing loopback device), or
  2. If not possible, how can I recover some of the files?

Most of the system is backed up, but some important files were created between daily backup cycles and will be lost if they cannot be restored here.

  • do you still have the 3GB file? if so, you could try mounting the fs it's on and then either try mounting your btrfs volume; or using btrfs-replace to replace the 3GB file with it's current full path (i.e. replace it with itself, in case the path is different). If either of those work, you should then be able to remove it with btrfs device remove. NOTE: if you no longer have the 3GB file then some of your data AND btrfs metadata will have been re-balanced onto it and is now lost forever. I don't think that's a recoverable situation. I hope you have a recent backup. – cas Feb 14 '18 at 0:12
  • No, I was dumb and put the file in /dev/shm instead of one of my other drives... – multithr3at3d Feb 14 '18 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.