To err is human; to really foul up takes root privs...
Posted: Sat Nov 25, 2006 12:17 am
About 6 hours ago, I intended to blank my flash drive and redo a bad-block scan (the thing is probably dead at this point, but occasionally, I can get one more use out of it)... so I typed the command
dd if=/dev/zero of=/dev/sda
Note: my flash drive is sdb. sda is my hard drive.
So, about half 1 second later, I killed it and cursed myself for getting a fast hard drive... I had already blasted the first 14 Gib, rendering Windows unbootable, and the partition table useless.
So, I tried gpart (found 2 ext2 partitions and a BFS one, none of which existed, but nothing else.
Worse, I didn't have any form of partition table backup, so I couldn't just restore them.
So, for anybody who screws up this royally on Linux, here's how to recover:
1) don't panic. If I did, I probably would have rebooted...
2) cat /proc/partitions. That will show you the length of each of your partitions, but not the order
3) start up fdisk, and hit 'u' to go to sector mode
4) create partitions, in the order you think they're in, using the default offset and the the number of blocks * 2 reported by /proc/partitions. DON'T create the extended partition, though... otherwise you'll lose the extended partitions.
5) write it to the disk
6) using losetup, stick each partition onto a loopback device, (everyone here should know how to find the parameters for that...) and run
file -s /dev/loop0
to make sure that you have the right parameters. It should report information on your filesystem, and NOT "data"
Also, notice that, until you run hdparm -z, the partition devices are still correct (/dev/sda1...), so you can compare against those.
7) When you're sure that everything is correct, reinstall grub, cross you fingers, and reboot. If the moons are aligned correctly, everything will work.
Then, make an MBR backup. With it, this becomes MUCH easier.
dd if=/dev/zero of=/dev/sda
Note: my flash drive is sdb. sda is my hard drive.
So, about half 1 second later, I killed it and cursed myself for getting a fast hard drive... I had already blasted the first 14 Gib, rendering Windows unbootable, and the partition table useless.
So, I tried gpart (found 2 ext2 partitions and a BFS one, none of which existed, but nothing else.
Worse, I didn't have any form of partition table backup, so I couldn't just restore them.
So, for anybody who screws up this royally on Linux, here's how to recover:
1) don't panic. If I did, I probably would have rebooted...
2) cat /proc/partitions. That will show you the length of each of your partitions, but not the order
3) start up fdisk, and hit 'u' to go to sector mode
4) create partitions, in the order you think they're in, using the default offset and the the number of blocks * 2 reported by /proc/partitions. DON'T create the extended partition, though... otherwise you'll lose the extended partitions.
5) write it to the disk
6) using losetup, stick each partition onto a loopback device, (everyone here should know how to find the parameters for that...) and run
file -s /dev/loop0
to make sure that you have the right parameters. It should report information on your filesystem, and NOT "data"
Also, notice that, until you run hdparm -z, the partition devices are still correct (/dev/sda1...), so you can compare against those.
7) When you're sure that everything is correct, reinstall grub, cross you fingers, and reboot. If the moons are aligned correctly, everything will work.
Then, make an MBR backup. With it, this becomes MUCH easier.