LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-29-2023, 04:28 AM   #1
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Rep: Reputation: 0
I am an idiot - help recovering files from EXT4 hard drive


Hi there.

I have done something stupid and pressed initialise instead of mount on a hard drive I was adding to my server.

It started to wipe the drive and I managed to stop it after about six second.

Now, I cannot access any files.

I had a look online and came up with something called Testdisk.

I selected EFI GPT and analyse and have left it running since.

Is Testdisk going to be my best bet for getting any files back?
 
Old 05-29-2023, 04:36 AM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,153

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Yes, wait for it depending on how big is your drive.

If Testdisk is able to recover something, it will show you what are the things that you can recover.

or check out this link below:
https://www.computerhope.com/forum/i...topic=168659.0


Goodluck!
 
1 members found this post helpful.
Old 05-29-2023, 04:43 AM   #3
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,527

Rep: Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495
Were you doing this in windows? What software were you using to 'initialize' the disk? The link below to the microsoft site indicates that you cannot initialize a drive that has already been formatted. Since windows does not by default recognize a Linux filesystem, this could be a problem. Initializing a disk does erase all data.

https://learn.microsoft.com/en-us/wi...lize-new-disks

Which Linux distribution/version are you using. Is it on a virtual machine or directly on hardware? More info is probably needed to get help but Testdisk is about the best software available that I am aware of to recover data.
 
1 members found this post helpful.
Old 05-29-2023, 04:59 AM   #4
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Original Poster
Rep: Reputation: 0
Thanks guys.

I am running Openmediavault 6 on two different servers.

I unmounted the disk (EXT4) from one and tried to mount it in the other but I accidentally pressed initialise instead.
 
Old 05-29-2023, 10:18 AM   #5
Jan K.
Member
 
Registered: Apr 2019
Location: Esbjerg
Distribution: Windows 7...
Posts: 773

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Running servers and no backups?

Kids these days...
 
1 members found this post helpful.
Old 05-29-2023, 11:12 AM   #6
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Jan K. View Post
Running servers and no backups?

Kids these days...
I was almost too ashamed to write on here - cannot believe I got caught out.

Slightly ironically, the reason I was moving harddrives was to set up a backup harddrive!
 
Old 05-29-2023, 01:30 PM   #7
mrmazda
LQ Guru
 
Registered: Aug 2016
Location: SE USA
Distribution: openSUSE 24/7; Debian, Knoppix, Mageia, Fedora, others
Posts: 5,817
Blog Entries: 1

Rep: Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068Reputation: 2068
The best tools on Linux do one thing well rather than several things not so well. Format and initialize shouldn't have been together, at least, not without a following are you sure confirmation required for something so devastating as initializing a disk that has formatted partitions.
 
1 members found this post helpful.
Old 05-29-2023, 04:18 PM   #8
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
First, make a bit for bit copy of that drive somewhere, if you can. If you start playing around you can make things worse.

Run:

Code:
mkfs.ext4 -n <device>
It will give you a list of backup superblocks that are likely the same as the original file system. If you're lucky, one of those superblocks may be intact. Then use fsck with that backup to see what you can recover. Always work on copies of the data! Each time you run fsck you'll be modifying the filesystem. You want a clean slate each time.

After 6 seconds you definitely lost some data, whether a good superblock can be found or not.

Also as a last resort you can use photorec, which is typically packaged with testdisk. It uses metadata and signatures to recover files. Depending on fragmentation and such, you may still lose data even if it recognizes the header, metadata, whatever. If you use photorec you will definitely lose filenames.

Last edited by goumba; 05-29-2023 at 04:19 PM.
 
1 members found this post helpful.
Old 05-30-2023, 03:57 AM   #9
remmilou
Member
 
Registered: Mar 2010
Location: Amsterdam
Distribution: MX Linux (21)/ XFCE
Posts: 212

Rep: Reputation: 69
Quote:
Originally Posted by goumba View Post
First, make a bit for bit copy of that drive somewhere, if you can. If you start playing around you can make things worse.

Run:

Code:
mkfs.ext4 -n <device>
It will give you a list of backup superblocks that are likely the same as the original file system. If you're lucky, one of those superblocks may be intact. Then use fsck with that backup to see what you can recover. Always work on copies of the data! Each time you run fsck you'll be modifying the filesystem. You want a clean slate each time.

After 6 seconds you definitely lost some data, whether a good superblock can be found or not.

Also as a last resort you can use photorec, which is typically packaged with testdisk. It uses metadata and signatures to recover files. Depending on fragmentation and such, you may still lose data even if it recognizes the header, metadata, whatever. If you use photorec you will definitely lose filenames.
This is certainly a VERY GOOD advice. Do yourself a favor and follow it...
Besides Testdisk (and photorec) there is another (free) option for rescuing data, especially from EXT file systems:
R-Linux: https://www.r-studio.com/free-linux-recovery/
It might be even your best option for file recovery, since your medium is EXT4.
Good luck.
 
1 members found this post helpful.
Old 05-30-2023, 04:03 AM   #10
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Original Poster
Rep: Reputation: 0
Thanks you for the further advice.

Can I just check what the difference is between fsck and gdisk, please?

Which should I use to try and repair the disk?

Edit - have just seen that R-Linux has been added to the mix.

Last edited by elsmandino; 05-30-2023 at 04:06 AM.
 
Old 05-30-2023, 04:31 AM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Quote:
Originally Posted by elsmandino View Post
Which should I use to try and repair the disk?
So far I don't see any evidence of what was actually done. What was initialised ? - the disk (partition table) or the filesystem ?. Those tools address different aspects of those questions. I haven't tried R-Linux, but it's self-promo looks polished.
What does "lsblk -f" show for the affected disk ?.
 
1 members found this post helpful.
Old 05-30-2023, 06:22 AM   #12
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by syg00 View Post
So far I don't see any evidence of what was actually done. What was initialised ? - the disk (partition table) or the filesystem ?. Those tools address different aspects of those questions. I haven't tried R-Linux, but it's self-promo looks polished.
What does "lsblk -f" show for the affected disk ?.
I agree - it isn't quite clear what I have done, exactly.

Having looked at the Openmediavault manual, initialise seems to mean that I was applying a new file system to the disk - i.e. EXT4 to a disk already running EXT4.

I am not quite sure exactly what this involves but I am hopeful that this is less destructive than actively trying to wipe the disk.

Once TestDisk has stopped running, I shall run "lbslk -f" and see what it comes back with.
 
Old 05-30-2023, 10:56 AM   #13
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Original Poster
Rep: Reputation: 0
Further to this thread, I got the following two screens as attached.

Any advice on what to do, now, would be much appreciated.
Attached Thumbnails
Click image for larger version

Name:	Before.jpg
Views:	27
Size:	235.6 KB
ID:	41124   Click image for larger version

Name:	After.jpg
Views:	27
Size:	244.6 KB
ID:	41125  
 
Old 05-30-2023, 01:38 PM   #14
elsmandino
Member
 
Registered: Oct 2009
Posts: 103

Original Poster
Rep: Reputation: 0
I gave up with TestDisk as it seems to be struggling.

I tried gdisk and have come out with the following:

Code:
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue May 30 19:25:18 2023 from 192.168.1.100
root@omvtemp:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   5.5T  0 disk
└─sda1   8:1    0   5.5T  0 part /srv/dev-disk-by-uuid-63c34541-0fd4-4ffc-bc49-2
sdb      8:16   0   1.8T  0 disk
└─sdb1   8:17   0   1.8T  0 part /srv/dev-disk-by-uuid-39cd1bac-1f3e-473c-8743-a
sdc      8:32   0 465.8G  0 disk
└─sdc1   8:33   0 465.8G  0 part /srv/dev-disk-by-uuid-dc07c53d-d6a0-4027-a500-5
sdd      8:48   0  59.6G  0 disk
├─sdd1   8:49   0  58.7G  0 part /
├─sdd2   8:50   0     1K  0 part
└─sdd5   8:53   0   975M  0 part [SWAP]
sde      8:64   0   4.5T  0 disk
└─sde1   8:65   0   4.5T  0 part /srv/dev-disk-by-uuid-bcaf61dd-18c0-45c6-ac6d-e
sdf      8:80   0  12.7T  0 disk
└─sdf1   8:81   0  12.7T  0 part
root@omvtemp:~# gdisk /dev/sdf
GPT fdisk (gdisk) version 1.0.6


Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present


Found valid GPT with protective MBR; using GPT.


Command (? for help):
Can anything be done from here?

Last edited by elsmandino; 05-30-2023 at 01:41 PM.
 
Old 05-30-2023, 05:35 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,724

Rep: Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918
gdisk is a command line partitioning tool for GPT based disks and is not a repair tool. fsck is a filesystem repair tool but it will not work in this case nor find lost files. lsblk will output partition information in a nice format.

When a filesystem is formatted basically all the superblock structure, inode table and block data is initialized but typically the data block i.e. where all the files are located is left as is. The inode table is how the filesystem finds the files on disk. I would try running photorec. It ignores the filesystem and searches the "raw" disk for file signatures. To reduce fragmentation ext4 can write files anywhere on disk and with a 12TB filesystem there is a lot of real estate to look at so it will not be a fast process.

https://www.cgsecurity.org/wiki/PhotoRec
 
1 members found this post helpful.
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help recovering formatted LUKS Ext4 partition anon072 Linux - General 4 10-02-2013 01:27 AM
Need help recovering files from old hard drive with Fedora Core installation okorkie Linux - Newbie 11 06-14-2012 01:47 PM
Recovering MySQL Database from EXT4 Formatted Hard Disk ... ckoeber Linux - General 10 02-12-2012 09:55 AM
Recovering files from a filevault-ed OS X hard drive? ichbindaswalros Linux - Software 6 02-21-2011 03:27 AM
Recovering Hard Drive files CycloLink Linux - Hardware 6 01-29-2004 07:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:33 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