LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-05-2005, 03:46 PM   #1
Timer
LQ Newbie
 
Registered: Jun 2004
Location: Catalonia
Distribution: Gentoo
Posts: 25

Rep: Reputation: 15
Rescue a damaged partition


First of all, let me tell you all the story:

I realised some files on my /home partition were unreadable and caused system to crash, so I supposed something was broken on my hard disk.

I just went to single-user mode, unmounted the partition, and tried e2fsck, but it reported no errors. Then I ran badblocks, which got freezed at the same block the files were supposed to be.

I read a bit the man pages and found a "mke2fs" program which had an option to check partition headings. I asked it to do this check, but a few seconds later I realised I had mispelled some option and it was actually overriding the partition.

I tried to mount the partition again, but its header was corrupted. So I ran mke2fs again, telling it to create only the partition header. As suggested by documentation, next I ran e2fsck, which repported some errors and fixed them. But the resulting filesystem had only 11 used inodes and was still unmountable.

Since I have some very important data in this partition, there's no backup of it. (I've only seen backups of games data!). But assuming that most of the contents were just stuff, there's a high chance of this important data being still unmodified.

Now, the question is:

What could I try to restore this partition (or, at least, rescue most of its data)?

Thanks.
 
Old 10-05-2005, 04:23 PM   #2
free_ouyo
Member
 
Registered: Mar 2004
Location: Belgium
Distribution: Ubuntu
Posts: 133

Rep: Reputation: 15
Rescue a damaged partition

Hello,

I first suggest to copy the whole parittion to safe place and try a rescue on the backup.

dd if=/dev/my_bad_partition conv=noerror,sync of=/my_backup.dd

you can try to use computer forensic soft like 'sleuthkit' (www.sleuthkit.org - not easy but can work)
you also can try 'foremost' (http://foremost.sourceforge.net/) or 'magicrescue' (http://jbj.rapanden.dk/magicrescue/).
The 2 last are recovery based on magic header of files.

Good luck
--
free_ouyo
 
Old 10-05-2005, 04:46 PM   #3
Timer
LQ Newbie
 
Registered: Jun 2004
Location: Catalonia
Distribution: Gentoo
Posts: 25

Original Poster
Rep: Reputation: 15
Thanks for the suggestions. I'll try these tools and report my (un)success tomorrow.
 
Old 10-06-2005, 11:37 AM   #4
Timer
LQ Newbie
 
Registered: Jun 2004
Location: Catalonia
Distribution: Gentoo
Posts: 25

Original Poster
Rep: Reputation: 15
Well, these are my results:

I first tried to make a image with dd, but dd got locked at some block "x" on the disc. Same for dls tool of sleuthkit.

Then I managed to recover some files from the partition by running magicrescue. It also hanged at that "x" sector, but I could rerun it from a greater block to skip the bad one(s). (After a reset-button reboot). Unfortunately, it didn't look able to find the most important files; it just returned some unnecessary images and stuff like that.

Finally I supposed I could try to grep filenames in the device and then expect to find contents near, but obviously grep reached that "x" damaged block and the system got locked for the nth time.

So what am I expected to do? Throw a curse on the hard disk vendor? The moral you can extract from my case is "buy a CDRW and copy all those important files on it before they abandon you".

Anyway, does anyone know some tool to make a copy of the partition which is capable to skip errors? (blocks will do)

Last edited by Timer; 10-06-2005 at 11:45 AM.
 
Old 10-07-2005, 03:54 PM   #5
Timer
LQ Newbie
 
Registered: Jun 2004
Location: Catalonia
Distribution: Gentoo
Posts: 25

Original Poster
Rep: Reputation: 15
Hello again.

I've finally half-solved my problem by making a backup of my data with "diskimg" (http://www.scylla-charybdis.com/tools.html#diskimg ).

Then I wrote some code to search the raw data on my partition by a keyword. It's quite fast if you are searching for some specific data, which was my case. It compiles with gcc and must be edited for an specific raw input (sorry, it's only a small tool, not a full program). Someone might find it helpful, but it has no warranty.

This is the code listing:

Code:
#include <stdio.h>

#define SIZE 4096

FILE* buffer;
FILE* registre;
FILE* output;
char name[1024];
char* stuff;
int block;
int a,b,c;
int equal;
char chars[1024];
char chars1;
int NCHARS;
int keeponreading;
int realsize;
char outname[1024];


int main(int argc, char* argv[])
{
	if (argc < 2) return 1;
	fprintf(stderr,"%i",argc);
	if (sscanf(argv[1],"%s1023",chars) != 1) return 1;
	NCHARS = strlen(chars);
	stuff = malloc(SIZE+NCHARS);
	registre = fopen("./log.txt","w");
	chars1 = chars[0];
	for(a=0;a<=11;a++)
	{
		sprintf(name,"/shared/sda72.img.%i",a);
		buffer = fopen(name,"rb");
		block =0;
		fprintf(stderr,
"Started reading file %i\n",a);
		keeponreading = -1;
		while (keeponreading)
		{
			block ++; /* We start counting at 1 */
			realsize = fread(stuff,1,SIZE+NCHARS,buffer);
			keeponreading = (realsize==SIZE+NCHARS);
			if ((block % 10240) == 1) fprintf(stderr,
"Now on block %i\n",block);
			for(b=0;b<realsize-NCHARS;b++)
			{
				if (stuff[b] == chars1)
				{
					equal = 1;
					for(c=1;c<NCHARS;c++)
					{
						if (stuff[b+c] != chars[c])
						{
							equal = 0;
							break;
						}
					}
					if (equal == 1)
					{
						fprintf(stderr,
"Found '%s' at block %i of file %i !!!\n",chars,block,a);
						fprintf(registre, "%i %i\n",block,a);
						sprintf(outname, "./%i.%i.bin",a,block);
						output = fopen(outname,"wb");
						fwrite(stuff,1,SIZE,output);
						fclose(output);
					}
				}		
			}
			fseek(buffer,-NCHARS,SEEK_CUR);
		}
		fclose(buffer);
	}
	fclose(registre);
	free(stuff);
	return 0;
}
 
  


Reply



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
Partition damaged at suse 9.1 install Sven Korner Linux - Newbie 5 08-12-2004 08:24 AM
Damaged ext3 partition drigz Linux - Hardware 1 07-03-2004 12:09 PM
Damaged partition after installation ratavaz Mandriva 1 03-22-2004 04:49 PM
Xandros Desktop damaged my XP partition.. why ? Santorres Linux - General 1 12-23-2003 11:50 AM
boot partition suddently damaged demmylls Linux - General 1 11-19-2003 11:29 PM

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

All times are GMT -5. The time now is 04:01 PM.

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