If you’ve ever pulled an SD card out of a Raspberry Pi and attempted to re-flash it with another disk image, you may have noticed something funny…
"My X Gigabyte SD card has shrunk to a few megabytes! What gives?" No, your SD card isn’t ruined, there’s just a few steps we need to follow to clean up our card and make it good as new.
We’re going to use a windows utility called diskpart. Be aware that this process will wipe everything on the SD card.
Start off with your SD card unplugged from your computer.
Open command prompt (Hold the Windows Key and press R to access the run menu. Type in cmd and hit enter). Windows 10 Users, you have a cool "power-user" menu available when you hit Win + X. You can run command prompt and other utilities from here.
At the prompt, enter the command diskpart
Another window with the diskpart utility opens.
List the available disks with list disk
Looking at the list, we can see all the storage devices connected to the computer, in this case I have only the main hard-drive listed.
Connect your SD card to the computer now and run list disk again to see which disk we’re interested in. I’m using an 16 GB card, which has appeared as Disk 1 and 14GB. The capacity will never fully match what your card is specified as, for a few technical reasons.
I’m going to execute select disk 1, where you will replace the number 1 with whichever number corresponds to your SD card.
Execute list disk again and you’ll see that your SD card should be selected, as indicated by an asterisk (*)
We’re going to clean the SD card, and reset it’s configuration:
Execute clean which resets the SD card configuration and then create partition primary
Once this step is completed, you should see your SD card reappear in the file explorer. You should receive a prompt that the SD card needs to be formatted. Format your card with the default settings and you’re good to go! You’ll be able to re-image the SD card for use in a Raspberry Pi, or return it to whatever digital camera you “borrowed” it from!