Coding with Titans

so breaking things happens constantly, but never on purpose

Restore SD card original size on Windows

Since I play a lot with IoT using my Raspberry Pi – on both – Windows and Raspbian, I ended up holding several SD cards, which don’t report almost any size on Windows. Somehow they are seen only as 70MB disks, even if they originally were 32GB cards. Where are then the missing bytes? Believe me, they are there and it’s simply the partition table (written on top of the SD card) that makes them hidden or treated even as unallocated space. And because Windows Explorer doesn’t allow any advanced management on that front, as its only feature - drive format - is not powerful enough, we need to go one level deeper.

Here is my recipe. If you browse the Internet, lots of people suggest using SD Association’s formatter tool. I confirm, it might be OK and it worked for me several times. But there is also another way, that uses build-in command-line utility called diskpart. This little tool will serve all our needs and we will feel like true admins. One warning before starting – it’s so powerful that I recommend double-checking all executed commands and their contexts to avoid accidental damages done to system disk and its partitions.

After that, all is more less straightforward. Run command-console in admin mode and execute (assuming the SD card is already somehow connected to the PC):

a) list available drives

b) select drive, where to restore full capacity

c) verify existing partitions

d) clear it

e) create a primary partition occupying whole available space

f) have fun!

Full listing from my sample session looks like following:

C:\WINDOWS\system32>diskpart


Microsoft DiskPart version 10.0.10240

Copyright (C) 1999-2013 Microsoft Corporation.
On computer: TAJFUN

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online           29 GB      0 B        *
  Disk 1    Online           29 GB    22 GB

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online           29 GB      0 B        *
* Disk 1    Online           29 GB    22 GB

DISKPART> list part

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary             64 MB  2048 KB
  Partition 0    Primary           4276 MB    72 MB
  Partition 0    Primary            600 MB  4348 MB
  Partition 0    Extended          2424 MB  4948 MB
  Partition 0    Logical           1024 KB  4948 MB
  Partition 0    Logical           2420 MB  4952 MB

DISKPART> clean

DiskPart succeeded in cleaning the disk.

DISKPART> create part pri

DiskPart succeeded in creating the specified partition.

DISKPART> list part

  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
* Partition 1    Primary             29 GB  1024 KB


Once done, this partition on SD card can be formatted as FAT32, NTFS or anything else.