Repairing ReiserFS file system with reiserfsck

by on July 13, 2006 · 12 comments· LAST UPDATED November 15, 2007

in , ,

Repairing ReiserFS file system with reiserfsck

The idea and commands in this article submitted by Jacques Wagener via email. In his own words, "After nuking my partition by accident (and through my stupidity) I was really disappointed in myself, especially in losing my bookmarks and rss-feeds". The following article is based upon our email communication. I am just putting them as an article.

We have already written about ext2/ext3 file repair using fsck and other utilities. Linux comes with different filesystems and different repair utilities. To repair a ReiserFS filesystem you need to run reiserfsck command, which is a checking tool for the ReiserFS filesystem (just like fsck command for ext2/ext3 file system).

Reiserfsck searches for a Reiserfs filesystem on a device, replays any necessary transactions, and either checks or repairs the file system. ReiserFS saves data or log in a special file for pending disk updates and later on it commit updates to disk resulting into very good filesystem consistency.

Step # 1: Install reiserfsck

You need to install reiserfsprogs package, which includes reiserfsck user level tools for ReiserFS filesystems.
# apt-get install reiserfsprogs

Or if you are using RedHat/Fedor Core Linux:
# yum install reiserfsprogs

Step # 2: Backup partition/disk

Take system down to runlevel 1.
# init 1

Unmount /dev/sda1 (if it is still mounted as read/write only):
# umount /dev/sda1; umount /dev/sda2

Before using any one of the following command you are strongly advised to make a backup copy of the whole partition using dd or ddrescue (recommended) command.
# ddrescue /dev/sda /dev/sdb

OR use dd command:
# dd if=/dev/sda of=/dev/sdb conv=noerror

Step # 3: Check filesystem consistency

Above command makes a backup of your drive. Next check filesystem consistency which will reports problem to you with the following command (assuming that /dev/sda1 is your partition):
# reiserfsck --check /dev/sda1

If you get an error Bad root block 0If you get following message:
Running with --rebuild-tree is required

Then you need to run following command rebuilds the entire filesystem tree using leaf nodes found on the device (this is nothing but indication of corrupted :
# reiserfsck --scan-whole-partition --rebuild-tree /dev/sda1

Where,

  • --scan-whole-partition: This option causes --rebuild-tree to scan the whole partition but not only the used space on the partition. You should always use this option with --rebuild-tree.
  • --check: Checks filesystem consistency and reports, but does not repair any corruption that it finds.
  • --rebuild-tree: This option rebuilds the entire filesystem tree using leaf nodes found on the device. Once you passed this option, do not stop or interrupt building operating.

Recovering corrupted superblock

Each file system has a superblock, which contains information about file system such as:

  • File system type
  • Size
  • Status
  • Information about other metadata structures

If this information lost, you are in trouble (data loss) so Linux maintains multiple redundant copies of the superblock in every file system.

During check (reiserfsck --check /dev/sda1) if you get an error superblock was missing, use following command to fix superblock:
# reiserfsck --rebuild-sb /dev/sda1

Where,

  • --rebuild-sb: This option recovers the superblock on a Reiserfs partition. Normally you only need this option if mount reports "read_super_block: can't find a reiserfs file system".

Caution: Do not run above command twice on same drive. You will damage your partition (data).

Final note

Next logical step is mount your partition /dev/sda1 and check for your data:
# mkdir -p /mnt/data
# mount /dev/sda1 /mnt/data
# cd /mnt/data
# ls
# ls lost+found/ -l

lost+found is a special directory where recovered files are kept by Linux/reiserfsck. You can examine these files and restore the data.

Better backup entire partition using tar or ssh session:
# tar cvf /dev/nst0 /mnt/data

OR use scp to dump data to remote system:
# scp -r /mnt/data you@other.server.com:/backup

See also:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 12 comments… read them below or add one }

1 chadrick July 14, 2006 at 7:59 am

This is same as old article, surviving filesystem failures. Good one :)

Reply

2 Ian July 19, 2006 at 5:53 pm

Tried it. It didn’t work. I ended up using a WINDOWS program called “UFS Explorer” – yes, I paid the $22.95 for it – and it recovered most of my needed data. Running on Windows. I’m sorry, but that’s just wrong, when Linux should be better at dealing with Linux filesystems.

One utility that is needed, if we’re going to put Linux on many desktops, is a utility to read an unmounted drive and recover the data from it without depending on the superblock, inodes, et cetera. I don’t know what, exactly, UFS Explorer does to do its thing, but it does it very nicely. Other utilities are out there that do this; at least one runs in java (okay, crawls in java): rossifstools. It doesn’t do it as well as UFS explorer does, though. And rfstools just sucks; it balks when the filesystem is not whole and intact.

Reply

3 nixCraft July 20, 2006 at 3:34 pm

Ian, sorry to hear that it didn’t worked out for you but it did worked for Jacques. Data recovery is complicated topic (procedure) and it needs some expertise/experience.

Reply

4 Bruce Mincks November 14, 2007 at 12:24 am

I need to fix my swap partition, apparently. I can see all my files are there, using the CAT command, but I can’t get an xterm. The filesystem is read-only. I was confused by the first error message that told me to run fsck when I need to run reiserfsck, apparently, having consulted my SUSE 10 manual. I have never managed to run reiserfsck, because I chickened out after it asked me for the block size (did it also give 4096 by default, then?) and I think the initial number. Now this information is telling me I need to back up evreything and remount it and all this stuff, when the error message seems to suggest it’s not a big deal; it wants me to run reiserfs and fix some bad pointer.

Can someone tell me both the correct syntax for doing this as well as how I find out the correct parameters before I try it?

I got so far as checking the partition, which tells me that I have a corrupted superblock. Then when I try to rebuild the superblock, it starts asking me all these questions I’m not sure about, and I don’t want to lose two months of work here.

I’ll be happy to consult the right man pages if I could figure out which one is really appropriate.

Reply

5 Bruce Mincks November 15, 2007 at 8:33 pm

This is an update of my preceding. It’s not my swap partition; it’s the root partition. I thought it was the swap partitition from misreading the “failed to load hda5″ as it flashed by the bootup diagnostics.

Now I have run residerfsck — check and learned that I have a Problem in Internal Tree 2/120 (of 168)/19 (of 170) there at block 65885, and I need to rebuild the tree, not the superblock. The man pages say it “strongly recommends” that I back up the data before I proceed, but how am I supposed to do that when the partition is now mounted “read only.” All the critical data would fit on a small flash drive, but like any other media, it has a mount point which is now “read only.”

Isn’t this a contradiction, to recommend a backup for a partition that has been mounted read only?

Reply

6 nixCraft November 15, 2007 at 8:51 pm

Bruce,

See step # 2: Backup partition/disk

run dd command to backup data and create new image on other hard disk. You only need read only access.

Reply

7 spiff May 23, 2008 at 3:18 am

Thanks for this article. This helped me repair my corrupt ReiserFS partition.

Reply

8 Fred January 18, 2009 at 4:26 am

You should not attempt this from a remote machine, because going to init 1 will stop ssh, then you are in deep shit.

Reply

9 Toffel August 2, 2009 at 8:09 pm

Thank you for this article. Very useful for me.

Reply

10 Elton September 1, 2009 at 9:33 am

This command not working Suse Linux En 10
reiserfsck –scan-whole-partition –rebuild-tree /dev/sda1

Reply

11 AFP_SCH December 26, 2009 at 3:52 pm

Hi,
I write
“reiserfsck –check /dev/sdb5″

and the system show me this message
“Will read-only check consistency of the filesystem on /dev/sdb5
Will put log info to ‘stdout’

Do you want to run this program?[N/Yes] (note need to type Yes if you do):”

Then i type:
“Yes”

An system show this
“###########
reiserfsck –check started at Sat Dec 26 10:13:53 2009
###########
Replaying journal..
Reiserfs journal ‘/dev/sdb5′ in blocks [18..8211]: 0 transactions replayed
Checking internal tree..

Bad root block 0. (–rebuild-tree did not complete)

Cancelado
usuario@usuario:~$ sudo reiserfsck –scan-whole-partition –rebuild-tree /dev/sdb5
reiserfsck 3.6.19 (2003 http://www.namesys.com)”

I wait 2 days for any answer on diferents forum, then i try this comands
reiserfsck –scan-whole-partition –rebuild-tree /dev/sdb5

Then system show this message
“reiserfsck 3.6.19 (2003 http://www.namesys.com)

*************************************************************
** Do not run the program with –rebuild-tree unless **
** something is broken and MAKE A BACKUP before using it. **
** If you have bad sectors on a drive it is usually a bad **
** idea to continue using it. Then you probably should get **
** a working hard drive, copy the file system from the bad **
** drive to the good one — dd_rescue is a good tool for **
** that — and only then run this program. **
** If you are using the latest reiserfsprogs and it fails **
** please email bug reports to reiserfs-list@namesys.com, **
** providing as much information as possible — your **
** hardware, kernel, patches, settings, all reiserfsck **
** messages (including version), the reiserfsck logfile, **
** check the syslog file for any related information. **
** If you would like advice on using this program, support **
** is available for $25 at http://www.namesys.com/support.html. **
*************************************************************

Will rebuild the filesystem (/dev/sdb5) tree
Will put log info to ‘stdout’

Do you want to run this program?[N/Yes] (note need to type Yes if you do):Yes
Replaying journal..
Reiserfs journal ‘/dev/sdb5′ in blocks [18..8211]: 0 transactions replayed
###########
reiserfsck –rebuild-tree started at Sat Dec 26 10:22:01 2009
###########

Pass 0:
####### Pass 0 #######
The whole partition (122093984 blocks) is to be scanned”

I have 1 day and 3 hors waitin.
I calculate that this work take 10 days,¿¿is this normal??

Thanks!!

Sorry for my english….

Reply

12 linuxhospital October 10, 2012 at 2:19 pm

good explanation !!
it helped me a lot

Reply

Leave a Comment

Tagged as: , , , , , , , ,

Previous post:

Next post: