LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Have just wiped a partition on a running system. (https://www.linuxquestions.org/questions/linux-software-2/have-just-wiped-a-partition-on-a-running-system-939267/)

273 04-11-2012 07:41 AM

Have just wiped a partition on a running system.
 
I have, stupidly, just managed to wipe my home partition, which is stored on a software RAID5 (md0) of three disks, in gparted. Is there any way to recover from this, or do I have to reformat and put my data back?
I'm currently copying hidden config files etc across just in case but I wondered if there is a way to recover things?
Yes, I know, I'm am idiot and should be more careful.

descendant_command 04-11-2012 07:56 AM

How exactly did you "wioe" it?

testdisk can be very useful for recovering deleted partitions.

273 04-11-2012 07:58 AM

Sorry, yes, I mean I deleted the partition in gparted, but the data is still there.. It's ext3 if that matters.

pan64 04-11-2012 08:02 AM

theoretically you may have a chance, because maybe only the partition entry had been deleted. Based on other partitions and disk geometry you may restore it and mount it again.

This is only an example: http://www.easeus.com/partition-recovery/ You may need to boot from a recovery disk containing the software.

descendant_command 04-11-2012 08:03 AM

... and committed the change?

but not rebooted yet?

Presumably you are on a live cd? (gparted shouldn't delete a mounted partition)

Install testdisk and see if it will find / re-instate the deleted partition.

note: I've never used it on raid and have no idea if it will work.

273 04-11-2012 08:10 AM

Yes, comitted but not rebooted. Nope, not on a live CD, but gparted definately shows /devmd0 as unallocated.
Not sure how to use testdisk, but am trying it now. Any tips?

descendant_command 04-11-2012 08:22 AM

type 'testdisk' then follow the prompts. :)

273 04-11-2012 08:30 AM

I take it the partition type is Intel (it was partitioned)?
I'm not sure what I'm supposed to expect. It said somethng about partition endblock not found, or similar, now I'm doing a quick search which seems to be searching the whole drive.

jschiwal 04-11-2012 08:59 AM

As mentioned, testdisk will scan and repair disk partitions. If you deleted or altered the partitioning, but didn't format the new partitions, you only need to restore the partition table, which is just a table of numbers.

Before running I'd recommend using "fdisk -l -b512 /dev/sdb" and writing down or saving the results, so you have a backup of the partitions which are good.

Could you give us an idea how many partitions were on /dev/sdb and which one got whacked? It is also possible to attach a loop device inside the disk, at an offset. E.G. the first partition probably starts at 2048*512 bytes. So it is possible to recover the partition table manually using losetup, file & df if testdisk doesn't succeed.

jschiwal 04-11-2012 09:07 AM

I spent too much time on my last response and didn't see your last post.

What is the offset of the partition you found?

If you run "sudo /sbin/losetup -fs /dev/sdb -o <offset>" you can attach a loop device to the beginning of the partion. Then mount the loop device. Using "sudo file -s /dev/loop#" you can check that there is a filesystem there. Then "df --block-size=512 /dev/loop#" can tell you how many blocks are in the filesystem, which also tells you where the partition ends, by adding the size to the start.

273 04-11-2012 09:16 AM

There was only one partition and it's not listed with fdisk -l /dev/md0
testdisk is still looking and I think it will take some time...

273 04-11-2012 03:00 PM

OK, now I'm confused. I decided to give up with testdisk because it wasn't finding anything and I have a backup so I rebooted.
Everything is fine:
Code:

# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdc1[0] sde1[2] sdd1[1]
      625137152 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
     
unused devices: <none>

So, perhaps, RAID devices don't need partitions? Or is something bad likely to happen down the line?
Code:

fdisk -l /dev/md0
GNU Fdisk 1.2.4
Copyright (C) 1998 - 2006 Free Software Foundation, Inc.
This program is free software, covered by the GNU General Public License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.


Disk /dev/md0: 640 GB, 640132416000 bytes
255 heads, 63 sectors/track, 77825 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start        End      Blocks  Id  System


jschiwal 04-11-2012 08:13 PM

The drives making up the raid volume were reassembled, but you still need to restore the partition.

Since there was only one partition on the volume, that should make things easy. Simply repartition it with fdisk, select the ID (e.g. 83 for Linux). The filesystem should still be there if you didn't reformat.

Alternately, attach a loop device. Then check for a filesystem. The partition probably starts at 2048. Although for older versions of linux (and XP) the first partition started at sector 63.
Code:

#assume filesystem starts are block.  Use 512 byte sectors to avoid rounding errors.
sudo losetup -fs /dev/md0 -o $((2048*512))

# I'm assuming it returned loop1.  Use the loop device returned by the losetup command.
sudo file -s /dev/loop1

#assuming a filesytem was found, Lets mount the filesystem:
sudo mount /dev/loop1 /mnt/

#find out the size of the filesystem:
df --block-size=512 /mnt/

# add the number of blocks to the start block.  That will be the top of the partition.


273 04-11-2012 08:25 PM

Thanks, I'll have a look at that in the morning.
What I don't understand is why everything seems to be working fine, with /dev/md0 mounted on /home and no apparent ill effects after a reboot? If things are working why do I need to do anything else?
I'm trying to work out what's going on here for future reference if nothing else.

jschiwal 04-12-2012 07:01 AM

OK, the md0 device has a file system on it isn't a drive image.
Having used gparted on it confused me.


All times are GMT -5. The time now is 10:36 AM.