# btrfsck [cold]

## idella4

Some months ago I followed a post by devsk re btrfs.  It concluded btrfs is still unstable.

https://forums.gentoo.org/viewtopic-t-838367-highlight-btrfs.html

In the process I tried a partition with btrfs.  Sure enough it corrupted along the lines described in the post.

My partition was 48 GB.  Being an experiment, I allocated non system data able to be re-acquired, such as /distfiles which was a collection of a few years of gentoo packages and kernels.

In order to use the partition space again in a regular file system, I made  a copy of it with dd.

The copy is an image of the partition in the corrupted state.

Although i can re-acquire the data [not the problem], I would prefer to rescue the data and copy it over, then happily delete the image.

I re-ran the tests from the post on btrfs with the 2.6.36 kernel version, and it still fails, running out of space and reporting erroneous measurements of % used.

What puzzles me equally is by its own admission on the documentation at kernel.org

 *Quote:*   

> 
> 
> Creating a filesystem of at least 1Go is recommended.
> 
>         Note: Be aware that for that size, it will report full when reaching about 75%.
> ...

 

Here is the image

```

genny idella # ls -ld /mnt/fedora/store/gen2.img

-rw-r--r-- 1 root root 48233009664 Nov  2 21:41 /mnt/fedora/store/gen2.img

```

48.233 Gb. Attempting to use btrfs' own image program failed due to the corruption. 

Using the 2.6.36 kernel and btrfs tools. here is the deficit.

```

genny idella # btrfsck /mnt/fedora/store/gen2.img

parent transid verify failed on 41647026176 wanted 10501 found 10514

parent transid verify failed on 41647026176 wanted 10501 found 10514

parent transid verify failed on 41647026176 wanted 10501 found 10514

Segmentation fault

```

The tool fails to repair the corruption.  Being corrupt, when attempting to copy the data out, it generally hangs.  I can only agree with devsk who followed it closely for while and was puzzled how with these flaws it ever got into the kernel main stream

Short of using a hex driver reader or sending the 48 Gb to the devs,

is there some way of re-acquiring this data, or is it truly trashed?

On the subject, does anyone know what a sub-volume and a snapshot are in btrfs and what they are generally used for?  Reading the doc page it assumes the reader already knows but I don't know that snapshots and sub-volumes are std supply in ext3 or 4.

----------

## aCOSwt

 *idella4 wrote:*   

> 
> 
> On the subject, does anyone know what a sub-volume and a snapshot are in btrfs and what they are generally used for?  Reading the doc page it assumes the reader already knows but I don't know that snapshots and sub-volumes are std supply in ext3 or 4.

 

Well, on this subject, I think this is worth reading (if you did not already)

http://webcache.googleusercontent.com/search?q=cache:C7ZO44ZrZtIJ:https://btrfs.wiki.kernel.org/index.php/Btrfs_design&cd=1&hl=fr&ct=clnk&gl=fr&client=opera

----------

## idella4

I am currently reading https://btrfs.wiki.kernel.org/index.php/FAQ#What_is_a_snapshot.3F

which covers your ref.  I can still say at this point all this doc info explains how it is intended to work and what it can do but it has failed.

The tool that ought fix the damage, btrfsck, doesn't fix it

I am tinkering at the edges with this file system out of curiosity since it is interesting in its own right.  I've just converted a sid to btrfs which now fails on converting back because I subtracted and re-added a 1G space, just another shortcoming of the file system tools.

I still ask; is there a way to copy out the data, a way that clearly is different to the provided means.

----------

## kingfame_147

Well it is a known problem that there is now working fsck for btrfs :)

You can write an e-mail to the btrfs mailinglist and ask for help there. The devs often help ppl to get there data back when they have problems like you.

Btrfs is still alpha/beta and if you use it you should have that in mind.

----------

## idella4

 *Quote:*   

> 
> 
> Btrfs is still alpha/beta and if you use it you should have that in mind.
> 
> 

 

Always have had.  As I said the data is all replaceable.  Emailing the devs, yes could do, pretty heavy handed for non-critical data.  It appears the btrfsck they have made is restricted and as you said they as anticipating a proper one soon.

 *Quote:*   

> 
> 
>   Btrfsck
> 
> The filesystem checking utility is a crucial tool, but it can be a major bottleneck in getting systems back online after something has gone wrong. Btrfs aims to be tolerant of invalid metadata, and will avoid using metadata it determines to be incorrect. The disk format allows Btrfs to deal with most corruptions at run time, without crashing the system and without requiring offline filesystem checking. 

 

It fails.

This is an exercise that satisfies curiosity mostly so I'm hoping for a solution from the forum here if possible.  Won't cry or be surprised if it doesn't come.

Wondering if someone knows a way by using low level alternatives like dd, du or a hex reader or such.

----------

## idella4

bump

anyone.  perhaps ddrescue??  I emerged ddrescue.  Sure enough it write a file, but does someone know how to utilise the file to restore data?  The data is 48 Gb of distfiles and packages and kernels.  What is needs is to write it out in the form of the rescued files and folders, but it just writes files and folders and binary data alike to a single file;   sheesh!!  To rescue file by file and folder by folder manually is not a popular way to use months of spare time.

Hmmm, I wonder; the output file need be loop mounted??

----------

## idella4

Conflicting results.  Tried loop mounting the rescue.img

```

genny test # tail /var/log/messages

Nov  4 07:37:04 genny kernel: [  823.277398] attempt to access beyond end of device

Nov  4 07:37:04 genny kernel: [  823.277401] loop1: rw=0, want=91300760, limit=1953125

Nov  4 07:37:04 genny kernel: [  823.277412] attempt to access beyond end of device

Nov  4 07:37:04 genny kernel: [  823.277414] loop1: rw=0, want=91300760, limit=1953125

Nov  4 07:37:04 genny kernel: [  823.277422] attempt to access beyond end of device

Nov  4 07:37:04 genny kernel: [  823.277425] loop1: rw=0, want=91562904, limit=1953125

Nov  4 07:37:04 genny kernel: [  823.277431] btrfs: failed to read tree root on loop1

Nov  4 07:37:04 genny kernel: [  823.280077] btrfs: open_ctree failed

Nov  4 07:37:05 genny agetty[2902]: /dev/hvc0: No such file or directory

Nov  4 07:37:05 genny agetty[2901]: ttyS1: tcgetattr: Input/output error

```

Anyone know how to acquire a /dev/hvc0

Correct me if I'm wrong but /dev/hvc is a xen tty.  Where is it pulling that from??

----------

## idella4

bump

```

genny gentoo # tail /var/log/messages

Nov  4 09:35:03 genny agetty[2914]: /dev/hvc0: No such file or directory

Nov  4 09:35:09 genny kernel: [  891.786633] device fsid 3040bc2891641def-d82a5bf1c9c6afa7 devid 1 transid 10531 /dev/loop2

Nov  4 09:35:09 genny kernel: [  891.885469] attempt to access beyond end of device

Nov  4 09:35:09 genny kernel: [  891.885473] loop2: rw=0, want=91300760, limit=195312

Nov  4 09:35:09 genny kernel: [  891.885483] attempt to access beyond end of device

Nov  4 09:35:09 genny kernel: [  891.885486] loop2: rw=0, want=91300760, limit=195312

Nov  4 09:35:09 genny kernel: [  891.885495] attempt to access beyond end of device

Nov  4 09:35:09 genny kernel: [  891.885497] loop2: rw=0, want=91562904, limit=195312

Nov  4 09:35:09 genny kernel: [  891.885504] btrfs: failed to read tree root on loop2

Nov  4 09:35:09 genny kernel: [  891.889039] btrfs: open_ctree failed

```

Anyone know how to tackle this?

I'm making a file of the first few gig.

Does it mean I need to record a rescue file the full size of the corrupted btrfs file size 48.2 Gig for the mount attempt to capture the limit ?

It looks as if I can use ddrescue to do it but I have to re-liberate the 48 G partition to copy the destination file to it. Looks as if copying small segments make an unmountable image file.

----------

