You are here

Recover Raspberry PI sdcard for use on windows

I had a (Chinese) 8GB class 10 sdcard that tested fine with h2Testw but gave mmc0: Timeout waiting for hardware interrupt - cmd18 in the Raspberry PI.

So it was unusable to boot the PI but I also found that I could not get rid of the partioning using windows. All methods I tried only formatted the 56MB first parttion. On my Windows 8 PC disk manager showed only one partition.

I finally managed to recover the card for use on windows using a portable running CentOs 6 linux.

Find out sdcard device

After you inserted the SD card in the reader you can use dmesg to get the name of the device.

[root@nhq-lenovo raspberry]# dmesg | tail
...
mmc0: card 0002 removed
mmc0: new high speed SDHC card at address 0002
mmcblk0: mmc0:0002 SDMMC 7.41 GiB
 mmcblk0: p1 p2

Remove partition

Once you know the device use fdisk to remove the partitions. Make sure you're working on the correct device, all data on the disk/card will be lost.  Display the current partition to check the size are what you expect before deleting.

[root@nhq-lenovo raspberry]# fdisk /dev/mmcblk0

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/mmcblk0: 7964 MB, 7964983296 bytes
4 heads, 16 sectors/track, 243072 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00014d34

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1             129        1920       57344    c  W95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary.
/dev/mmcblk0p2            1921       59200     1832960   83  Linux
Partition 2 does not end on cylinder boundary.

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Selected partition 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create new partition

I had thought the above steps would be sufficient but windows still could not use the disk. I first had to create a new partition on linux. After that the card could be formatted on windows.

[root@nhq-lenovo raspberry]# fdisk /dev/mmcblk0

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-243072, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-243072, default 243072):
Using default value 243072

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@nhq-lenovo raspberry]#