Monday, June 8, 2009

Using testdisk and gparted to Fix My USB Stick

OK, I messed something up. I used 'dd' to write to /dev/sdc aka my USB key. Something like this:
dd if=./stage1/stage1 of=/dev/sdc
dd if=./stage2/stage2 of=/dev/sdc seek=1
Well, it seems, I wiped out the partition table or something. When I came back to Ubuntu, there was no icon for the USB key. When I went to gparted, it was there, but instead of a partition, there was only an 'unallocated'. I tried to use gparted's "Create Partition Table..." but I just an error message about being unable to access /dev/sdc.

To google!

Naturally, I'm not the first moron to screw up a USB key. I get to stand on the shoulders of morons before me. They asked, and the google-verse responded: testdisk.
sudo apt-get install testdisk
testdisk /dev/sdc
It took a little while to get my testdisk legs. But soon I found that you can wipe out the MBR and then select 'none' as a file system, and then recreate a boot sector as FAT16 or something like that. I still couldn't add a partition. But at least I repaired it enough that Linux regards it as FAT16.

I logged out and this time gparted allowed me to make a partition. Whew! Now that I have it working again, maybe I'll do:
dd if=/dev/sdc of=/home/mark/backups/Cruzer256.bak
so if I wipe it out again, I can do:
dd if=/home/mark/backups/Cruzer256.bak of=/dev/sdc
Now back to figure out where I went wrong in causing this problem in the first place... Maybe I should have done:
dd if=./stage1/stage1 of=/dev/sdc1
dd if=./stage2/stage2 of=/dev/sdc1 seek=1

No comments:

Post a Comment