Skip to contentSkip to conversation

Damaged super block / fs root

DISCUSSION Dennis Bergmann 4 participants 6 messages May 30, 2011 – May 31, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

I have accidently damaged the first block(s) of a btrfs partition and can't mount it anymore.

I can see that my data is still intact by running a command like:

cat /dev/sda5 | hexdump -C | more

Do any (experimental) tools exist which would allow me to recover the files?

Thank you

#1 lore raw
Quoted 8 lines · Dennis Bergmann

I have accidently damaged the first block(s) of a btrfs partition and can't mount it anymore.

I can see that my data is still intact by running a command like:

cat /dev/sda5 | hexdump -C | more

Do any (experimental) tools exist which would allow me to recover the files?

There's btrfs-select-super, which is in the git repo for btrfs
tools, in the next or tmp branches. That should allow you to select an alternative superblock to use, which (I think) will help you. If it is just your superblock that's damaged, that should help.

You can check whether it's likely to be of use by running "btrfsck
-s 1" on your filesystem. If it passes OK, then btrfs-select-super should be useful.

Hugo.

Signature · 4 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
  --- Attempted murder, now honestly, what is that?  Do they give a ---  
                  Nobel Prize for attempted chemistry?                   
#2 lore raw
Quoted 5 lines · Hugo Mills

You can check whether it's likely to be of use by running "btrfsck
-s 1" on your filesystem. If it passes OK, then btrfs-select-super should be useful.

Hugo.

Didn't work, unfortunately.

My btrfsck version is v0.19-35-g1b444cd-dirty and running "btrfsck -s 1 /dev/sda5" quits with the following message:

using SB copy 1, bytenr 67108864
No valid Btrfs found on /dev/sda5

#3 lore raw

Excerpts from Dennis Bergmann's message of 2011-05-30 12:47:01 -0400:

Quoted 7 lines · Hugo Mills
Quoted 5 lines

You can check whether it's likely to be of use by running "btrfsck
-s 1" on your filesystem. If it passes OK, then btrfs-select-super should be useful.

Hugo.

Quoted 8 lines

Didn't work, unfortunately.

My btrfsck version is v0.19-35-g1b444cd-dirty and running "btrfsck -s 1 /dev/sda5" quits with the following message:

using SB copy 1, bytenr 67108864
No valid Btrfs found on /dev/sda5

How big is the FS? What command did you use to overwrite the super block? Please try to tell us exactly which commands were run.

There are other ways we can try to pull things off, but you should try btrfsck -s 2 as well.

-chris

#4 lore raw

Hello Chris

Quoted 1 line · Chris Mason

How big is the FS?

About 100 G on a 500 G partition. I would only like to recover some plain text files from it (source code), I don't need the partition to be mountable again.

Quoted 2 lines

What command did you use to overwrite the super
block? Please try to tell us exactly which commands were run.

I had to install FreeBSD on that disk (with Linux, a btrfs partition, and several free partitions on it). When using the FreeBSD partition tool, I didn't create or delete any partitions. I only assigned a free partition to FreeBSD. When I booted later in Linux the Btrfs partition did not mount anymore.

Quoted 2 lines

There are other ways we can try to pull things off, but you should try btrfsck -s 2 as well.

btrfcsk -s 2 exits with:

using SB copy 2, bytenr 274877906944
No valid Btrfs found on /dev/sda10

#5 lore raw
In reply to Hugo Mills
Quoted 3 lines · Hugo Mills

You can check whether it's likely to be of use by running "btrfsck
-s 1" on your filesystem. If it passes OK, then btrfs-select-super should be useful.

Inspired by this I cloned latest btrfs-progs-unstable and tried it on my broken 60-something GB btrfs, but no luck:

$ btrfsck -s 0 /dev/sdb2
using SB copy 0, bytenr 65536
btrfsck: disk-io.c:739: open_ctree_fd: Assertion `!(!tree_root->node)' failed.
Aborted
$ btrfsck -s 1 /dev/sdb2
using SB copy 1, bytenr 67108864
btrfsck: disk-io.c:739: open_ctree_fd: Assertion `!(!tree_root->node)' failed.
Aborted
$ btrfsck -s 2 /dev/sdb2
using SB copy 2, bytenr 274877906944
No valid Btrfs found on /dev/sdb2
$ 

I created an empty 384 MB btrfs:

$ dd if=/dev/zero of=/tmp/test_fs bs=1024k count=384
$ mkfs.btrfs /tmp/test_fs
$ 

And then I compare output from btrfs-debug-tree between test_fs and my broken one:

$ strace -e pread64 btrfs-debug-tree /tmp/test_fs 2>&1 | sed 's-,"\(.\{5\}\).*"-, "\1"-'
pread64(3, "\351\"..., 2859, 65536) = 2859
pread64(3, "I\227"..., 2859, 67108864) = 2859
pread64(3, ""..., 2859, 274877906944)   = 0
pread64(5, "\351\"..., 2859, 65536) = 2859
pread64(5, "I\227"..., 2859, 67108864) = 2859
pread64(5, ""..., 2859, 274877906944)   = 0
pread64(5, "\37\2"..., 4096, 20971520) = 4096
pread64(5, "\311\"..., 4096, 37752832) = 4096
pread64(5, "\247C"..., 4096, 37756928) = 4096
pread64(5, "\225\"..., 4096, 37761024) = 4096
pread64(5, "\210z"..., 4096, 37765120) = 4096
pread64(5, "\3\34"..., 4096, 37748736) = 4096
root tree
leaf 29364224 items 9 free space 2349 generation 7 owner 1
fs uuid d29c2f7a-0a4e-4a1d-8458-2d241f6f29de
chunk uuid fb34ff75-1cb6-4974-af37-e0a464135216
        item 0 key (EXTENT_TREE ROOT_ITEM 0) itemoff 3756 itemsize 239
                root data bytenr 29368320 level 0 dirid 0 refs 1
        item 1 key (DEV_TREE ROOT_ITEM 0) itemoff 3517 itemsize 239
                root data bytenr 29372416 level 0 dirid 0 refs 1
...
$ strace -e pread64 btrfs-debug-tree /dev/sdb2 2>&1 | sed 's-, "\(.\{5\}\).*"-, "\1"-'
pread64(3, "p\23{"..., 2859, 65536) = 2859
pread64(3, "\320r"..., 2859, 67108864) = 2859
pread64(3, ""..., 2859, 274877906944)   = 0
pread64(5, "p\23{"..., 2859, 65536) = 2859
pread64(5, "\320r"..., 2859, 67108864) = 2859
pread64(5, ""..., 2859, 274877906944)   = 0
pread64(5, "\353$"..., 4096, 20971520) = 4096
pread64(5, "\275\"..., 4096, 20987904) = 4096
pread64(5, "\253\"..., 4096, 20983808) = 4096
pread64(5, "\0\0\"..., 4096, 36675878912) = 4096
pread64(5, "\0\0\"..., 4096, 36675878912) = 4096
pread64(5, "\0\0\"..., 4096, 36944314368) = 4096
btrfs-debug-tree: disk-io.c:739: open_ctree_fd: Assertion `!(!tree_root->node)' failed.
--- SIGABRT (Aborted) @ 0 (0) ---
+++ killed by SIGABRT +++

I also tried the btrfsck again:

$ strace -e pread64 btrfsck -s 0 /dev/sdb2 2>&1 | sed 's-, "\(.\?.\?.\?\).*"-, "\1"-'
pread64(3, "p\2"..., 2859, 65536) = 2859
pread64(3, "\32"..., 2859, 67108864) = 2859
pread64(3, ""..., 2859, 274877906944)   = 0
pread64(3, "p\2"..., 2859, 65536) = 2859
pread64(3, "\32"..., 2859, 67108864) = 2859
pread64(3, ""..., 2859, 274877906944)   = 0
pread64(5, "p\2"..., 2859, 65536) = 2859
pread64(5, "\32"..., 2859, 67108864) = 2859
pread64(5, ""..., 2859, 274877906944)   = 0
pread64(5, "\35"..., 4096, 20971520) = 4096
pread64(5, "\27"..., 4096, 20987904) = 4096
pread64(5, "\25"..., 4096, 20983808) = 4096
pread64(5, "\0\"..., 4096, 36675878912) = 4096
pread64(5, "\0\"..., 4096, 36675878912) = 4096
pread64(5, "\0\"..., 4096, 36944314368) = 4096
btrfsck: disk-io.c:739: open_ctree_fd: Assertion `!(!tree_root->node)' failed.
using SB copy 0, bytenr 65536
--- SIGABRT (Aborted) @ 0 (0) ---
+++ killed by SIGABRT +++
$ strace -e pread64 btrfsck -s 1 /dev/sdb2 2>&1 | sed 's-, "\(.\?.\?.\?\).*"-, "\1"-'
pread64(3, "p\2"..., 2859, 65536) = 2859
pread64(3, "\32"..., 2859, 67108864) = 2859
pread64(3, ""..., 2859, 274877906944)   = 0
pread64(3, "\32"..., 2859, 67108864) = 2859
pread64(5, "\32"..., 2859, 67108864) = 2859
pread64(5, "\35"..., 4096, 20971520) = 4096
pread64(5, "\27"..., 4096, 20987904) = 4096
pread64(5, "\25"..., 4096, 20983808) = 4096
pread64(5, "\0\"..., 4096, 36675878912) = 4096
pread64(5, "\0\"..., 4096, 36675878912) = 4096
pread64(5, "\0\"..., 4096, 36944314368) = 4096
btrfsck: disk-io.c:739: open_ctree_fd: Assertion `!(!tree_root->node)' failed.
using SB copy 1, bytenr 67108864
--- SIGABRT (Aborted) @ 0 (0) ---
+++ killed by SIGABRT +++
$ strace -e pread64 btrfsck -s 2 /dev/sdb2 2>&1 | sed 's-, "\(.\?.\?.\?\).*"-, "\1"-'
pread64(3, "p\2"..., 2859, 65536) = 2859
pread64(3, "\32"..., 2859, 67108864) = 2859
pread64(3, ""..., 2859, 274877906944)   = 0
pread64(3, ""..., 2859, 274877906944)   = 0
No valid Btrfs found on /dev/sdb2
using SB copy 2, bytenr 274877906944
$ 

Does this give any hint about how the tree has been broken?

//Peter