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

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
TheQuux
Member
Member
Posts: 73
Joined: Sun Oct 22, 2006 6:49 pm

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

Post 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.
niteice
Member
Member
Posts: 59
Joined: Tue Oct 03, 2006 3:49 pm

Post by niteice »

:shock:

That's pretty awesome.
User avatar
jhawthorn
Member
Member
Posts: 58
Joined: Sun Nov 26, 2006 4:06 pm
Location: Victoria, BC, Canada
Contact:

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

At least you didn't dial into your harddisk... (historic oopses, chapter one: when Linus changed full-time to Linux)
TheQuux
Member
Member
Posts: 73
Joined: Sun Oct 22, 2006 6:49 pm

Post 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...
My project: Xenon
Post Reply