You are not logged in.

#1 2011-05-18 18:42:16

The Mishanator
Member
From: Washington (state)
Registered: 2009-09-08
Posts: 54

recover part of hard drive

Here is the mess I've created. I was trying to "zero out" a flash drive (/dev/sdf) and so I did "sudo dd if=/dev/zero of=/dev/sda"

notice the /dev/sda instead of /dev/sdf... I noticed this right after I hit enter, so I pressed ctrl-c as quickly as I could, unfortunately, 46 mb of /dev/sda had already been written to. Is there any way to recover from this (aside from reinstalling)? My partition layout is such that the first 4gb are swap. However, the boot sector as well as the partition table are destroyed... Is it hopeless, or is there a way to fix this?

Offline

#2 2011-05-18 23:39:53

akurei
Member
From: Bochum, NRW, Germany
Registered: 2009-05-25
Posts: 152
Website

Re: recover part of hard drive

First dd the hdd so you have a backup and can't destroy anything.
Second: I can't help you with the second step, but if you manage to repair your partition table, then:
Third: If you remember the syntax of your mkfs command you used when you created the partition, you can use

       -n     Causes mke2fs to not actually create a filesystem, but display what it would do if it were to create a filesystem.  This can be used to determine  the
              location  of  the backup superblocks for a particular filesystem, so long as the mke2fs parameters that were passed when the filesystem was originally
              created are used again.  (With the -n option added, of course!)

for ext filesystems to determine the superblock backups and then you can

       -S     Write  superblock and group descriptors only.  This is useful if all of the superblock and backup superblocks are corrupted, and a last-ditch recovery
              method is desired.  It causes mke2fs to reinitialize the superblock and group descriptors, while not touching the inode table and the block and  inode
              bitmaps.   The e2fsck program should be run immediately after this option is used, and there is no guarantee that any data will be salvageable.  It is
              critical to specify the correct filesystem blocksize when using this option, or there is no chance of recovery.

if I recall correctly to recreate the FS without touching the "file-table" from one of the backup superblocks.

But create a backup via dd first!!!

EDIT: Oh and this also happened to me aswell. My apologies... Hope you have a backup.

Last edited by akurei (2011-05-18 23:48:21)

Offline

#3 2011-05-19 02:45:51

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: recover part of hard drive

You inspired me to type this in a terminal:

sudo dd if=/dev/sda of=/mnt/samsung1000/Backups/SSD_boot_sector bs=512 count=2048

Thanks! smile  (In fact, only the first 512-bytes sector has to be backuped if this is an MBR partition table.)

Now if your first partition is swap, you only have to restore the partition table... It shouldn't be too hard; I think there is a tool for that, but I don't remember its name...

Edit: you'll have to reinstall grub too of course.

Last edited by stqn (2011-05-19 02:49:28)

Offline

#4 2011-05-19 02:48:48

The Mishanator
Member
From: Washington (state)
Registered: 2009-09-08
Posts: 54

Re: recover part of hard drive

Thanks, I'm in class now, but I will try this (find mentioned tool & stuff) once I get home and let you know how it goes.

Offline

Board footer

Powered by FluxBB