dd ruined my USB stick, how do I recover?

I tried to copy a Linux distro over to my USB using DD. But half way through it failed because the computer went to sleep or something.

I plugged the USB in and I get a message saying it's unreadable now on the Mac. I've plugged it into a Windows box, and ran Diskpart, but it's saying the volume is 0 bytes.

I've tried to get it to show in Linux and Mac to no avail. The issue happened when using dd on my macbook, hence why I've asked on Apple SA.

Any advice on what to do from here? I recall I had a similar issue in the past but don't know how to fix it.


Solution 1:

I'm assuming there is nothing on the USB stick you need to recover, since you were writing over it with dd.

Plug it into your macbook and if it shows up with in /dev as a proper device, you should be able to use dd to clear the beginning and end of the stick to make it look like a brand new USB stick.

dd if=/dev/zero of=/dev/disk__ bs=1024 count=100

will clear the beginning of the stick. (Be absolutely sure that you have the correct device id for the "of=" parameter !! Make sure it wasn't there right before you inserted the USB stick into the computer.)

However, there may be a GPT partition at the end of the stick. To write to the end, you'll probably want to use seek= with the number of blocks on the device minus 50 or so.

Once those are cleared, you should be able to add a new partition table to the USB stick using the disk utility.

If that doesn't work, using the first form without "count=100" would overwrite the whole stick with zeros. That's probably overkill, but at that point any system should recognize it as a new device