Page 1 of 1

To err is human; to really foul up takes root privs...

Posted: Sat Nov 25, 2006 12:17 am
by TheQuux
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.

Posted: Sun Nov 26, 2006 9:18 pm
by niteice
:shock:

That's pretty awesome.

Posted: Mon Nov 27, 2006 3:15 pm
by jhawthorn
I've made that mistake many times when I meant to be formatting my ipod. Luckily I've always had my partition table memorized and have been able to fix it via live CD. :D

Posted: Mon Nov 27, 2006 3:23 pm
by Candy
At least you didn't dial into your harddisk... (historic oopses, chapter one: when Linus changed full-time to Linux)

Posted: Tue Nov 28, 2006 2:32 am
by TheQuux
Candy wrote:At least you didn't dial into your harddisk... (historic oopses, chapter one: when Linus changed full-time to Linux)
I've done that, too... and used my grub boot floppy as a framebuffer...

Actually, a random screenshot from my framebuffer-hacking days is http://thequux.com/modules/xoopsgallery ... 01/fb2.png. (ps... that console font has been converted to a vga font image, and is in my latest kernel snapshot...). I do believe that that was my crowning achievement... besides the fbforth library which was a completely FORTH-based interface to the Linux fbdev interface...

Ahh, it just goes to show that it's not just command line tools that are being used in unintended ways...