1

While experimenting with how to fix this, I came across a suggestion to wipe the MBR, so I did.

dd if=/dev/zero of=/dev/sdb bsize=512 count=1

Whoops. No partition table.

Yes, I have backups, but I’d still like those partitions back. What should I do? There are a few proprietary products which claim to magically fix partitions and recover data, but I don't trust them. Can I restore the partitions with ordinary Linux/Windows commands?

EDIT: Given that the first partition is exactly 4MB (special boot partition) can I safely determine where the next partition starts, at least, and work from there?

4
  • 1
    You deleted the partitions there is nothing those commands that do exist can recover. You need to restore the partitions using your backups.
    – Ramhound
    Commented Nov 21, 2014 at 16:25
  • Isn't there a way to search through the rest of the disk to find something that looks like the beginning of an ext4 section and infer the partition table from that?
    – spraff
    Commented Nov 21, 2014 at 16:29
  • Have you rebooted since wiping the table? Commented Nov 21, 2014 at 16:55
  • 1
    @Ramhound: No, he only wiped the MBR (which includes the partition table). See the "count=1"? That count is in blocks. So only one block was zeroed. Commented Nov 21, 2014 at 17:04

2 Answers 2

1

There is a free, open-source, cross-platform utility called TestDisk that seems to be able to do this. http://www.cgsecurity.org/wiki/TestDisk is the developer's site, here: https://en.wikipedia.org/wiki/TestDisk is a WP article on it, and here: http://www.geekyprojects.com/storage/how-to-repair-a-damaged-partition-table-or-mbr/ is a review / usage guide.

I haven't tried it personally, but since you have little to lose at this point..

update: And, oh look - here: Vista - wiped MBR and HEAD of disk - how to recover? is a superuser Q&A including a successful use of TestDisk.

2
  • This worked perfectly. Very clever.
    – spraff
    Commented Nov 23, 2014 at 10:02
  • p.s. - I got TWO downvotes on this, before your "it worked." I really wish they had explained what their objections were, rather than just "throwing rocks." If there's an actual problem with this answer we all (myself not excluded) would benefit from hearing it. Commented Nov 24, 2014 at 6:04
1

If you have not rebooted yet, the kernel still knows the old layout, which can be retrieved from /sys.

#!/usr/bin/env bash
dev=${1:-sda}
dev=${dev#/dev/}
for part in /sys/class/block/${dev}[0-9]*; do
    num=$(<$part/partition)
    start=$(<$part/start)
    size=$(<$part/size)
    end=$((start+size-1))
    echo "# partition $num: start $start, size $size, end $end"
    echo "sgdisk /dev/$dev --new=$num:$start:$end"
    #echo "parted /dev/$dev mkpart primary $start $end"
done
3
  • @gravity That recovers the information, but it doesn't actually fix the partition table on the disk. Commented Nov 21, 2014 at 17:09
  • 1
    @JamieHanrahan: It was written for a GPT system earlier, so it outputs sgdisk commands that can be reviewed and copy&pasted. I'm too lazy to figure out the primary/logical split that MBR requires, so it's close enough if you copy&paste the relevant numbers to fdisk's "add a new partition" mode. Commented Nov 21, 2014 at 17:52
  • 1
    Good stuff. btw, unless he had four or more partitions (total) there is likely no primary/logical split. You can have up to four primaries. If you want more than four partitions, then one primary becomes an "extended" partition with logical partitions inside it. It's possible to have extended partitions in other circs, but it's uncommon. Commented Nov 21, 2014 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .