LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-02-2012, 05:27 PM   #1
nroberto13
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Rep: Reputation: Disabled
ext4 recovery based on root directory inode


Hi mates,

I'm trying to recover an ext4 fs after a superblock corruption.
Let me describe what I've got.

1 usb disk of 750GB
2 partition 1: 700+gb, 2: the rest
the first partition contains the corrupt fs.

I tried to use fsck with backup superblock, but no luck.
what I could manage to find is the root directory inode, using a scandrive app.

What's in my mind, having the root dir inode is basically the most important thing, using it I could either reconstruct superblock or iterate through all the inodes and copy data to another fs.

unfortunately I'm not good enough in programming to write a tool for the iteration so I would choose the 1st option, to reconstruct the superblock.

do you guys know , what fields a re required in the superblock to be able to mount it, I guess magic number and state flag would be mandatory, but not sure what else should I fill in?

or if you know a tool which could do the iteration through the inodes using the root directory as a starting point, let me know please.

any help is much appreciated.

thank you!
 
Old 12-02-2012, 09:27 PM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
It seems this is your first post. So, Welcome to LQ!

To do that, may not be complex work, but a certain time-consuming task.

BTW, have you tried running 'fsck' without any switch? This will reread the records and restore them after your 'y' (Yes) replies each prompt.

Last edited by malekmustaq; 12-02-2012 at 09:29 PM.
 
Old 12-03-2012, 06:42 AM   #3
nroberto13
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
thank you! nice to meet you .

tried to run fsck without switches, but complains about superblock.
 
Old 12-03-2012, 07:23 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by nroberto13 View Post
I'm trying to recover an ext4 fs after a superblock corruption.
Please describe the cause (or causes) of corruption in order of events, verbosely, how long ago this happened and do include any "repairs" you have tried.


Quote:
Originally Posted by nroberto13 View Post
I tried to use fsck with backup superblock, but no luck.
How many backup superblocks did you try? Have you tried finding all alternative superblocks using 'mke2fs -n'? What is the output fsck gives? If you run (a Live CD containing) testdisk on the drive (no partitions mounted and use the "/debug /log" switches to save a log file) you "browse" the partition? ( Proceed > Choose partition table type ("none" because its a partition) > Advanced > Undelete). If that doesn't work look at "testdisk.log" for clues. And what does the drive include? An OS? Just files?
 
Old 12-03-2012, 08:13 AM   #5
nroberto13
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
cause:

the disk was attached to a router, running openwrt.
under heavy disk usage, openwrt messes up something, I can see disk read errors, but if I scan the disk attached to a computer, everything seems fine with the disk, no bad sectors.
I guess the issue is due to lack of power in the router's usb port, the disk is just usb powered, no additional power adapter.
Unfortunately it;s not the first time, so I'm considering to buy an active usb hub.
It happened 2 weeks ago, I ran fsck right after the corruption, but didn't help. No other destructive repair was tried, just passive scans for valid part tables, superblock or root dir inodes.

tried to find alternative superblocks with fsck -n, but none of them worked.
testdisk is able to detect partitions, but can't read fs.
I guess fsck messed up all the backup superblocks

here's the log:

Interface Advanced
Geometry from i386 MBR: head=255 sector=63
check_part_i386 failed for partition type 83
check_part_i386 failed for partition type 83
get_geometry_from_list_part_aux head=255 nbr=4
get_geometry_from_list_part_aux head=8 nbr=1
get_geometry_from_list_part_aux head=16 nbr=1
get_geometry_from_list_part_aux head=32 nbr=1
get_geometry_from_list_part_aux head=64 nbr=1
get_geometry_from_list_part_aux head=128 nbr=1
get_geometry_from_list_part_aux head=240 nbr=1
get_geometry_from_list_part_aux head=255 nbr=4
1 P Linux 0 1 1 90499 254 63 1453882437
2 P Linux 90500 0 1 90531 254 63 514080
search_superblock
Couldn't open reiser filesystem
Couldn't open reiser filesystem
Couldn't open reiser filesystem
Change partition type:
1 P Linux 0 1 1 90499 254 63 1453882437
search_superblock
Partition table type (auto): Intel
Disk /dev/sdb - 750 GB / 698 GiB - ADATA HDD CH94
Partition table type: None

Interface Advanced
P Unknown 0 0 1 91201 80 63 1465149168
Change partition type:
P ext4 0 0 1 91201 80 63 1465149168
search_superblock

P ext4 0 0 1 91201 80 63 1465149168
Can't open filesystem. Filesystem seems damaged.

P ext4 0 0 1 91201 80 63 1465149168
Can't open filesystem. Filesystem seems damaged.

the only thing I can see could work is to use that root dir inode as base.
 
Old 12-03-2012, 05:57 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by nroberto13 View Post
tried to find alternative superblocks with fsck -n, but none of them worked.
I don't know if it's a reading or typing thing but I said mke2fs as in
Code:
mke2fs -n /dev/sdb1
and (making a backup with 'dd' and) then feeding those superblock numbers to fsck, but since you already ran fsck previously I wouldn't have too much hope wrt the outcome. A last ditch effort may be to re-run 'mke2fs' with the -S switch (see 'man mke2fs') or try your luck carving files with Photorec.
 
Old 12-04-2012, 02:09 AM   #7
nroberto13
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
sorry, it was a typing thing.
So I tried to find backup superblock with mke2fs -n -I 128 -m 0 /dev/sdb1 , because i wanted inode size 128 bytes, to be able to mount with different tools on windows box, and don't need reserved area.

Tried the -S, actually this is exactly what I was looking for, but unfortunately didn't work as I expected .
after mke2fs -S -I 128 -m 0 /dev/sdb1 I ran fsck, lot of errors ... , afterwards mounted, but fs is empty.

tried to see where is root dir inode located now, and it's different sector than it was before, so there's no chance to work.
it was either a fake root dir inode detected before, or the fs structure changed somehow.

before mke2fs -S i found root dir inode at sector 41224, and now it's at 41232, quite close , exactly 1 block dif ( having block size 4096 ) .
 
Old 12-04-2012, 06:25 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by nroberto13 View Post
(..) I tried to find backup superblock with mke2fs -n -I 128 -m 0 /dev/sdb1 , because i wanted (..)
Maybe I should have explained this right away but the reason for running 'mke2fs -n' is to get diagnostics output in a way that does not alter or deteriorate the state the file system is in any further. Any commands that alter the file system serve only to worsen the problem and any reason for wanting to run altering commands should have been discarded as unwanted. Even though it is your responsibility I'm sorry to see that after failing to heed the warnings twice, after running an uncontrolled fsck you now went for creatively interpreting commands instead of just running what was asked for.
The downside is you just painted yourself in the SNAFU-completely-SOL corner.
The upside is I can now congratulate you with your new paper weight.
 
Old 12-04-2012, 07:55 AM   #9
nroberto13
LQ Newbie
 
Registered: Dec 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
I was completely aware of what i was doing, so just took my chance.

I wasn't clear enough I think, I ran the mke2fs -n with those switches because I used those switches when I created the fs, for the reasons enumerated before, sorry for misunderstanding.
the man of mke2fs clearly says to run fsck after mke2fs -S. anuway, the root dir inode being allocated in a different place, the fs wouldn't work without the fsck either.
running fsck, it just overwrote my old root inode with inode bitmap I guess.

Appreciate your help!

Thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
root inode is not a directory patrick.begou Linux - Server 2 11-26-2010 04:49 AM
EXT4 data recovery micemicerabies Linux - General 5 08-26-2010 01:28 PM
ext4 recovery behaviour grete Slackware 3 12-10-2009 11:48 AM
Corrupted root inode on ext3 RAID - data recovery LostTowel Linux - Software 2 08-23-2008 11:10 PM
Directory access denied to root user: inode hack? netmar Linux - Security 2 07-31-2004 04:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration