Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
harddrive data recovery [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3474
Location: Canada

PostPosted: Sun Feb 16, 2025 4:15 am    Post subject: harddrive data recovery [SOLVED] Reply with quote

Ok, sooner or later it had to happen and I did lost my backup (and some other) data by moving disks to another raid-1 enclosure (don't ask why).

So now I have a disk with the partition table gone, it looks empty to fdisk. However if I try to create a partition at standard block 2048, it says that there is reiserfs signature,
and do I want to delete it ? So I guess that if I just create a sifficiently large partition, I'll probably get the data from it still intact.

However, the problem is that I had two partitions on that disk. And it is the second one that is more valuable. But I do not know at what block starts.
With the first partition I could make it to cover the whole disk, it will obviously be more than before, and I feel I have a chance to see the data. But that will screw the second partition, perhaps finally.

So the question is, can I find where the second partition was starting ? I would think that somewhere at its start there is the reiserfs signature as well, so is there a way to find it ?


Last edited by dmpogo on Sun Feb 16, 2025 8:43 pm; edited 1 time in total
Back to top
View user's profile Send private message
quilosaq
Veteran
Veteran


Joined: 22 Dec 2009
Posts: 1562

PostPosted: Sun Feb 16, 2025 11:19 am    Post subject: Reply with quote

I think it is impossible to find that data manually. Maybe this article can help:
https://wiki.gentoo.org/wiki/TestDisk

Don't forget to activate the use flag reiserfs in testdisk
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3511

PostPosted: Sun Feb 16, 2025 11:51 am    Post subject: Reply with quote

It certainly is possible.
First, you do have a copy of this disk,don't you? It would suck if you accidentally damaged the data wile trying to recover it.
Second, people usually partition disks without any gaps, and at least some filesystems know how big they are supposed to be. If you can read that from your the FS on your first partition, it will be a good clue about the location of your second partition. Tools for resizing the FS might help.
Third, yes, scanning the whole disk is an option too. FS are structured, so you can find a location of stuff if you know what you're looking for. Signature is certainly a good pointer, even though there will likely be a bunch of false-positives.

Partition table is just a bunch of pointers, losing it, although inconvenient, doesn't immediately delete your data, and with raid 1 each disk can be read as an individual device, so it should be fairly easy to recover. It is weird that you lost your partition table though. Made a mistake witch overwrote your headers with raid's superblock or something?
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54878
Location: 56N 3W

PostPosted: Sun Feb 16, 2025 11:56 am    Post subject: Reply with quote

dmpogo,

You want the mount option -o offset=.
If your drive is /dev/sda, try
Code:
mount -o ro,offset=<bytes to start of partition> /dev/sda /mnt/<someplace>

No partition table needed.
Once you know where the first filesystem ends, thats a big hint to the start of the next, and so on.

testdisc can scan for partition starts if you want some hints but do not let it write a new partition table.
You will probably get a lot of false positives.
The above ro,option= is safe to try.
It's even safer if you can use the -t switch to say try that sort of fs or fail.

== edit ==
It's always a good idea to make a disc image before you start. In case you do something you need to undo

Warninig: The GPT and first 4 entries in MSDOS partition tables are only pointers to data. No harm done if you lose the pointers, its just difficult to find your data,
MSDOS logical partition entries (5 and higher) form a linked list. Getting that wrong will ruin your filesystem(s) in the logical partitions, so don't.
However, the same idea applies. The first logical partition starts at the same disk block as the extended partition.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3474
Location: Canada

PostPosted: Sun Feb 16, 2025 5:40 pm    Post subject: Reply with quote

Thanks Neddy !

I did find last night that testdisk utility and run it to see what it finds. It does find two Linux partitions, seemingly of correct sizes, and reports the starting blocks in CHS format.
Then it finds some FAT16 stuff which it fails to read and which exceeds the disk size. However it is happy to recover the first partition, but says that cannot do the second (also complains that
the disk is too small, perhaps because of fat16). I stopped at that stage.

Both my partitions were primary, I thought that I do not have extended/logical one on this disk.
But somehow, from my memory, partitions were always detected as /dev/sb1 and /dev/sb3, so now I wonder if I did have extended /dev/sb2 ?
I'll be working on your suggestions. It is a great idea to everything on the disk image !


Last edited by dmpogo on Sun Feb 16, 2025 8:44 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54878
Location: 56N 3W

PostPosted: Sun Feb 16, 2025 6:13 pm    Post subject: Reply with quote

dmpogo,

With an MSDOS partition table, it's perfectly possible and legal, to have gaps in the primary partition entries.
The same is true of GPT.

If you don't use the partition table and use mount -o offset= you can establish the size of the first filesystem then fish for a filesystem that starts just off the end of the first one.
No partition table needed.

With a disk image, works just the same. If your image has a partition table,
Code:
losetup -fP /path/to/image
wlll give you /dev/loopXp1 and so on, for the partitions.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3511

PostPosted: Sun Feb 16, 2025 7:02 pm    Post subject: Reply with quote

Quote:
But somehow, from my memory, partitions were always detected as /dev/sb1 and /dev/sb3, so now I wonder if I did have extended /dev/sb2
1-4 were primary partitions, if you made an extended one you'd see higher numbers (starting with 5).
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3474
Location: Canada

PostPosted: Sun Feb 16, 2025 7:14 pm    Post subject: Reply with quote

Ok, Neddy's mount -o offset="" successfully works, all the data seems there

Now the last question, I can create a partition starting at the offset upto the end of the disk, done that before resizing the partitions.
Is there any way to make sure that partition will not come out shorter than before and screw the filesystem ?
(i.e that I did not get some reserved blocks at the end which were not there before, or something)

If I could shrink the filesystem a bit, but
it looks like I can't realliy manipulate the filesystem if I do not have a device, and mount it via offset.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54878
Location: 56N 3W

PostPosted: Sun Feb 16, 2025 7:46 pm    Post subject: Reply with quote

dmpogo,

The partition table entry is only a pointer. If you make pigs ear of it, no user data will be affected unless you make and use another partition that would use some of the space of the first filesystem a second time.
That is, making the partition too small, on its own, is harmless.

If you do make it too small, mount will tell you all about it.

You are working in a disk image ... or have a disk image in case you need an 'undo, ... don't you?

I think offset= uses a loop device ... so you do have a device. /dev/loopX.

Code:
df -h
will show it. You cannot shrink a mounted filesystem. so you would need to use
Code:
losetup
by hand.
Shrinking should not be required.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
dmpogo
Advocate
Advocate


Joined: 02 Sep 2004
Posts: 3474
Location: Canada

PostPosted: Sun Feb 16, 2025 8:43 pm    Post subject: Reply with quote

NeddySeagoon wrote:
dmpogo,

The partition table entry is only a pointer. If you make pigs ear of it, no user data will be affected unless you make and use another partition that would use some of the space of the first filesystem a second time.
That is, making the partition too small, on its own, is harmless.

If you do make it too small, mount will tell you all about it.

You are working in a disk image ... or have a disk image in case you need an 'undo, ... don't you?

I think offset= uses a loop device ... so you do have a device. /dev/loopX.

Code:
df -h
will show it. You cannot shrink a mounted filesystem. so you would need to use
Code:
losetup
by hand.
Shrinking should not be required.


Yes, offset uses loop devices, I noticed it with lsblk -f
Anyway I just recreated a partition, first on the image, then on the real disk, and it all worked out just fine, I have full disks operational. Thanks a lot !
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum