3

I need help checking and repairing a BTRFS partition. It all started with a few directories on my system being inaccessible. Permissions of these directories are shown with question marks when I execute ls -l:

d????????? ? ?           ?            ?  dir1/
d????????? ? ?           ?            ?  dir2/
d????????? ? ?           ?            ?  dir3/

I suspect something went wrong during my last backup with rsync. When I try to delete one of these directories with rm -frv dir1 I obtain the following error:

rm: cannot remove 'dir1': Input/output error

I unmounted the partition and ran the BTRFS' check with

sudo umount /dev/sda1
sudo btrfs check /dev/sda1

I obtain numerous errors of the type:

root 5 inode 77131 errors 2001, no inode item, link count wrong
        unresolved ref dir 68134 index 0 namelen 11 name <filename.ext> filetype 1 errors 6, no dir index, no inode ref

Please find below the summary of the btrfs check command:

ERROR: errors found in fs roots
found 291234099200 bytes used, error(s) found
total csum bytes: 268053312
total tree bytes: 372293632
total fs tree bytes: 58654720
total extent tree bytes: 7356416
btree space waste bytes: 45522801
file data blocks allocated: 290844143616
 referenced 290844143616

Would you please guide me here? How do I repair the file system? The manual page of the btfrs check warns against using the repair command.

1 Answer 1

2

Do you have a backup? If not, make one now. It obviously won’t include the corrupted data, but losing only that is better than losing everything.

Once you have a backup, just run the check command in repair mode. It may fix things. If it does, then you’re fine. If it doesn’t, or it makes things worse, just nuke the volume and restore from the backup. Based on past experience, if you’re using the latest version of btrfs-progs (current latest as of writing this answer is 6.0.2), it’s likely that the repair mode will at least get the filesystem into a consistent state (though you will probably lose those corrupted directories).

In either case, you should probably look into what caused this issue in the first place.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .