How to repair a BTRFS partition?

I started a thread about a system journal file being read-only, which turned out to be because openSuSE loaded read-only. The thread is here.

With help, I have traced it down to what seems to be a problem with a BTRFS partition. Running dmesg I saw the messages “BTRFS csum failed” and “BTRFS info (device sda5) is forced read only”.

So how do I repair this partition?

All help greatly appreciated.

The output from fsck, for what it is worth, is

   linux@linux:~> sudo fdisk -l

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: E1E4D0AA-99CF-4B01-8178-79155CB3675B

Device         Start        End    Sectors   Size Type
/dev/sda1       2048     206847     204800   100M EFI System
/dev/sda2     206848     468991     262144   128M Microsoft reserved
/dev/sda3     468992  691472835  691003844 329.5G Microsoft basic data
/dev/sda4  691474432  695678975    4204544     2G Microsoft basic data
/dev/sda5  695678976  779571199   83892224    40G Microsoft basic data
/dev/sda6  779571200 1953523711 1173952512 559.8G Microsoft basic data

Disk /dev/loop0: 466.2 MiB, 488833024 bytes, 954752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
linux@linux:~> sudo fsck -v /dev/sda1
fsck from util-linux 2.25.1
fsck.fat 3.0.26 (2014-03-07)
fsck.fat 3.0.26 (2014-03-07)
Checking we can access the last sector of the filesystem
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
1) Remove dirty bit
2) No action
? 2
There are differences between boot sector and its backup.
This is mostly harmless. Differences: (offset:original/backup)
  65:01/00
1) Copy original to backup
2) Copy backup to original
3) No action
? 3
Boot sector contents:
System ID "MSDOS5.0"
Media byte 0xf8 (hard disk)
       512 bytes per logical sector
      1024 bytes per cluster
      6654 reserved sectors
First FAT starts at byte 3406848 (sector 6654)
         2 FATs, 32 bit entries
    393728 bytes per FAT (= 769 sectors)
Root directory start at cluster 2 (arbitrary size)
Data area starts at byte 4194304 (sector 8192)
     98304 data clusters (100663296 bytes)
63 sectors/track, 255 heads
      2048 hidden sectors
    204800 sectors total
Checking for unused clusters.
Checking free cluster summary.
/dev/sda1: 96 files, 21764/98304 clusters
linux@linux:~> sudo fsck -v /dev/sda2
fsck from util-linux 2.25.1
e2fsck 1.42.12 (29-Aug-2014)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sda2

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>
 or
    e2fsck -b 32768 <device>

linux@linux:~> sudo fsck -v /dev/sda3
fsck from util-linux 2.25.1
linux@linux:~> sudo fsck -v /dev/sda4
fsck from util-linux 2.25.1
linux@linux:~> sudo fsck -v /dev/sda5
fsck from util-linux 2.25.1
If you wish to check the consistency of a BTRFS filesystem or
repair a damaged filesystem, see btrfs(8) subcommand 'check'.
linux@linux:~> sudo fsck -v /dev/sda6
fsck from util-linux 2.25.1
If you wish to check the consistency of an XFS filesystem or
repair a damaged filesystem, see xfs_repair(8).

I do not know why your are trying fsck on all file systems you have while you think you have a problem with a Btrfs file system.

And checking the only file system that seems to be Btrfs, it says:

linux@linux:~> sudo fsck -v /dev/sda5
fsck from util-linux 2.25.1
If you wish to check the consistency of a BTRFS filesystem or
repair a damaged filesystem, see btrfs(8) subcommand 'check'.

I do not use Btrfs, but reading this I would do

man btrfs

and look what is explained there about the ‘check’ function.

Hi
There is probably more detailed info here;
https://btrfs.wiki.kernel.org/index.php/Btrfsck

On 2015-05-01 17:56, hcvv wrote:
>
> I do not know why your are trying fsck on all file systems you have
> while you think you have a problem with a Btrfs file system.

No, he didn’t. That’s a copy paste from the previous thread. He tested
all partitions, then, reading that text, I told him that the crucial one
was “fsck -v /dev/sda5”, which is a btrfs and I don’t know how to repair.

So I suggested to him to post a new thread asking specifically how to
repair a btrfs partition.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

Thanks, Malcolm. I’ve had a look at this, and at the pages it recommends, and I have to declare myself thoroughly confused.

If my btrfs partition is sda5, for example, (which it is) then how do I format a btrfs check command? And is there anything I should do beforehand? Remember that I will be running this from a rescue disk.

Can anyone give advice on this?

You may find this older thread worth reading (only a couple of pages long), or rather the two slightly different examples of a recovery procedure (mine is 2nd one at post #15) included there:

Re: Tumbleweed after Update to Kernel 3.17.1-52.1 has corrupted Btrfs Root Partition

Thanks, that’s very useful. I’m feeling very optimistic after reading that thread.

But a couple of questions due to me getting into unknown territory:

Firstly, is there no problem in installing btrfsprogs when running from a CD?

Secondly, I’m not running Tumbleweed, or at least I don’t think I am. In fact I don’t even know what this is. Does this make any difference?

Should not make a difference if not Tumbleweed we are speaking of the file system and there is not all that much different in Tumbleweed.

General Note:
Fixing a broken files system of any kind may be a problem simply because if sufficiently messed up an automated system may not be able to totally piece it back together. And pieces left over can be found in lost&found. With pure text files it is not hard to piece any fragments back together but complex documents and binaries is near impossible. So if for root after you “fix” the file system if you have stuff left in lost&found. Your system is most likely still broken reinstall (using update from DVD) is the only real option.

Firstly: No problem installing btrfsprogs [or a limited amount of other packages] into the live system with YaST or zypper. I say “limited” because it’s limited by the size of the live virtual root file space in RAM. You also need to have the appropriate repos configured - that should be ok with the appropriate openSUSE rescue CD.

Secondly: one assumes you were running standard 13.2 release on the target btrfs partition (?). That has btrfsprogs with kernel at 3.16.7 and you may have gathered from the older Tumbleweed (it’s a rolling release system) thread that btrfsprogs at 3.17 was required for the repair because it had the improved “btrfs check” tool. At that time the 3.16 version was useless/broken. Since then, 13.2’s btrfsprogs 3.16 was updated to 3.16.2-4.1 in Main Update repo. However I’m not sure if the newer repair tool was back-ported to 3.16.2 package, although I know some fixes were.

So the question becomes: What version of rescue CD were you planning to use?

On 2015-05-02 19:36, johngwalker wrote:

> Secondly, I’m not running Tumbleweed, or at least I don’t think I am. In
> fact I don’t even know what this is. Does this make any difference?

No, from what I remember from your other thread, you are not on Tumbleweed.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

I created it from 13.2. So i suppose I’ll be fine.

I checked out about Tumbleweed and I’m definitely not on it. Nor, I deduce from the documentation I saw, should I be (I need the nvidia driver) so I’ll just leave it alone!

Possibly, but not a certainty if you followed my comments re the 3.16.2 version that is in 13.2 :. Let us know how it goes!

Originally the 3.16 version I used didn’t do any good or harm. If it doesn’t work, you may need to download and burn a factory/Tumbleweed rescue CD for the procedure.

The version on the rescue disk is 3.16.2. Yast offered me a later version of 3.16.2 but when I tried to upgrade it need 244 updates to make it compatible. The update failed on lack of space.

So I tried btrfs check --repair using the version on the rescue disk. This seems to have partially worked, in that, when I boot, the error messages are different, but the btrfs partition still isn’t loaded and it’s stilled forced the OS to load as read-only. Whne the OS loads it finds errors in specific files, which it didn’t before. So I’m off to find a Tumbleweed rescue disk.

One question: while it would be dangerous of me to load Tumbleweed, would it be sensible to maintain a Tumbleweed rescue disk? It seems that this wouldn’t actually potentially harm my system whilst it would give me access to the latest version of various tools. Or afre there dangers I haven’t spotted?

Well you are the latest in a long row. Have problems with… Brtfs. At least you where asking for help in the forum. Think of all(outside) that have tried and will tell their friends that openSUSE sucks having simular problems.

A reflection.

regards

Thanks, consused.

I burnt a Tumbleweed rescue disk and checked the btrfs version, which is now 3.19. I ran it, rebooted and, mirabile dictu, I was able to get back into my system! So than you very much.

However, it put a lot of files into lost+found, so I’m not sure what might have disappeared.

One thing that is definitely wrong is my list of repositories in Yast. Packman and nvidia both disappeared. I’ve restored these, but I’m not sure if I’ve got everything correct. I’ve had one conflict already when the system tried to upgrade.

So what are the recommended repositories?

I was thinking the same thing. And at least I’ve got more than one machine. I use a laptop for my email and various other things, so I was able to ask in the forums despite having my desktop not functioning.

I have a friend who said she’d love to use linux, but I was afraid to install it for her because I wouldn’t be able to support her. I’m glad I didn’t now.

Hmm, should I be surprised at 244 additions for a minor version change? Yes, it would need further investigation, so please at least post the full name of the iso file you downloaded for “rescue disk”

So I tried btrfs check --repair using the version on the rescue disk. This seems to have partially worked, in that, when I boot, the error messages are different, but the btrfs partition still isn’t loaded and it’s stilled forced the OS to load as read-only. Whne the OS loads it finds errors in specific files, which it didn’t before.

Not surprised by that result, but it’s not good news and may have compromised further repair. What (if any) report did the “btrfs check” tool give you?

So I’m off to find a Tumbleweed rescue disk.

Please post back with the full name of the Tumbleweed rescue CD’s iso file you download before proceeding.

One assumes you have recovered or copied any data files you can’t afford to lose, or attempted to do so. Are you reaching a point where it may be quicker to re-install the system?

One question: while it would be dangerous of me to load Tumbleweed, would it be sensible to maintain a Tumbleweed rescue disk? It seems that this wouldn’t actually potentially harm my system whilst it would give me access to the latest version of various tools. Or afre there dangers I haven’t spotted?

Possibly it is the only alternative wrt openSUSE 13.2 with btrfs and a rescue cd, unless one can mount the partition on another Tumbleweed system. Since both openSUSE and SLE are leading with btrfs, finding alternative rescue cd’s, e.g. SystemRescueCD, at the necessary btrfs version level may continue to be difficult or impossible. Inadequate file system repair tools is one of the reasons I decided to only install 13.2 release with btrfs in a VirtualBox VM as a testing vehicle.

You’re welcome. That is good news, and very well done to get through it.

You can ignore anything asking for info in my previous post which crossed after yours. I hadn’t pressed enter when I had an incoming phone call of some length. So when I did hit enter, it was somewhat outdated! :slight_smile:

Just use ext4 it is stable and works fine. The decision to use BTRFS as the default file system is more political then technical. BTRFS make senses in a commercial environment but it really brings little to the table for the average desktop user. Any file system can go south. But BTRFS recovery tools are still not quite there but seem to be coming along. Part of the problem is that not all the bells and whistles promised by the design are available and working. like RAID mode built in. Also the fact that normal Linux tools do not report disk usage accurately with BTRFS because of snapper which also requires 2X the disk space as in the past to keep it’s snapshots. I can see snapper being of real us in a developers machine but not so much in a normal desktop. It is just a waste of hidden space. </rant>

Since you have stuff showing up in last&found and this is the root/system partition then things are still not right use the full DVD and do a upgrade to restore the files. Trying to sort out lost&found is not something that you want to deal with.