2013/09/02

Bootable ext4 Micro SDHC card reported as “Damaged SD card” by Android phone

TL/DR – if you have ext3/4 partition on your Micro SDHC card (e.g. you boot some Linux from it) and then try to put this card into Android phone, it will complain about “Damaged SD card” until you erase (zero out) bootloader from ext3/ext4 partition.

 

http://www.lg.com/uk/images/lg-mobile-phones/p920/gallery/medium07.jpg

Android phone complains about damaged sdcard after bootloader installation. But not just any bootloader. It actively dislikes any bootloader on ext3/4 partions. It complains and refuses to mount sdcard. If you force mount in terminal/ADB - it will mount, but bootloader will be corrupted (do not know exactly why, but has to do something with security and signing of Android system bootloader). My card is multi-partition, and while I mount PRT1 (FAT32), Android corrupts Partition Boot Record (PBR) on PRT4 (EXT4). To avoid this problem I zeroed out PBR on PRT4 (where Linux resides) and Android immediately stopped compaining about the card. Mounts it, scans it, uses for camera/gallery storage, etc.

NOTICE AGAIN: ZERO OUT EXT3/4 PARTITION BOOTSECTOR to allow mounting of FAT32 partition in Android. Strange, I know. I think Android is crazy cautious about EXT3/4 bootloaders, to prevent booting unsigned ROMs from any EXT3/4 filesystem, no matter if it is on internal or external sdcard.

I couldn’t google up anything on this topic, and spent couple of days understanding and then solving this issue. Here goes more detailed explanation. Hopefully it saves time to other people trying to read bootable FAT32/EXT4 card in Android (keywords: USB multi-boot, Micro SDHC, Android, SD Card is Damaged, bootloader, grub, mbr)

I use Sandisk Ultra Micro SDHC (UHS-1) 64 GB card in my phone (LG Optimus 3D, ICS 4.0.4) and in compact Lexar USB3.0 card reader on a keychain.

64GB

On Android, I use excellent app DriveDroid to expose bootable IMGs to PC via USB cable (mostly Windows Defender Offline x32/x64, and Windows 8 Install/Recovery). But I also use USB 3.0/MicroSDHC reader with  multiple ISOs, Porteus Linux and a real installation of Linux Mint on EXT4. It is fast enough. Boots in a minute. Speed is OK, feels like a slow laptop HDD of 2010.

ultra64@r630lexar

Card is partitioned into:
MBR  with BOOTMGR (here and in other cases, installed with BOOTICE (free Windows app) 
PRT1: FAT32 -50GB with BOOTMGR (NT6) - Largest partition for data - compatibile with most devices
PRT2: NTFS - 1GB NTLOADER*
PRT3: NTFS - 1GB NTLOADER*
PRT4: EXT4 - 12GB - used to be GRUB2, now empty boot sector

*PARTITIONS 2 and 3 are small stubs between FAT32 (max space) and EXT4 (limited space at the end of  card). I figured that one day I might want to reduce FAT32 and experiment with another or two partitions, without having to move EXT4. I guess PRT2 and PRT3 are not relevant further to this topic.

I played quite a lot with the PRT1, it boots Windows 8 BootMgr, and from there I have added syslinux and grub4dos and can go between them, chainloading each other in circles.  What is interesting, is that I can put any bootloader on FAT32 (PRT1) and it will not affect my card when I put it into Android phone.

THE PROBLEM BEGAN AFTER INSTALLATION OF LINUX ON PRT4(EXT4). Android refuses to mount the card. I forced it through terminal with
su
mount -t vfat /dev/block/mmcblk1p1 /mnt/sdcard/_ExternalSD

File explorers then can see the card but message about Damaged SD Card still hangs there in notifications. When I unmount the card and try booting Linux, it freezes silently. Turns out bootloader of GRUB2 in PRT4 is corrupted.

In order to solve this problem, I booted Mint's vmlinuz/initrd directly from GRUB4DOS on PRT1 and reinstalled GRUB2 on PRT4, then used BOOTICE to copy PBR from EXT4 partition (512 bytes) and save it into file on FAT32. Now I can boot it from BOOTMGR directly into GRUB2.mbr file and use Linux. Then, I used BOOTICE's sector editor functionality, to fill first sector (512 bytes) of PRT4 with zeroes. After doing, this, Android stopped compaining about the card and happily mounts FAT32 partition.

Enjoy, and share in the comments your weird and geeky setup. I am really interested in miniscule and versatile computers and what you use them for.

No comments:

Post a Comment