Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,814,105 Members 45,022 Now Online
XDA Developers Android and Mobile Development Forum

[GUIDE] How to mount ext4 formatted MicroSD card on Android 4.2.2 Phone/Tablet.

Tip us?
 
sashavasko
Old
(Last edited by sashavasko; 3rd September 2013 at 05:07 PM.) Reason: Added command to kill adb server to avoid power drainage, added note on umask 077
#1  
Junior Member - OP
Thanks Meter 7
Posts: 2
Join Date: Jul 2012
Location: Jefferson City, MO

 
DONATE TO ME
Database [GUIDE] How to mount ext4 formatted MicroSD card on Android 4.2.2 Phone/Tablet.

Why?

MicroSD cards are traditionally formatted using ExFAT filesystem. The trouble is that while universally compatible, ExFAT is rather primitive filesystem prone to data loss, and poor speed. Linux ext4 on the contrary is highly reliable and very fast.
Trouble is that, and I quote, "Android supports devices with external storage, which is defined to be a case-insensitive and permissionless filesystem." (see http://source.android.com/devices/tech/storage/)
Well that pretty much narrows it down to dumb stuff like ExFAT.
Note: As of JB (Android 4.1) default umask is 077, which means that files created by apps on the ext4 formatted SD card will only be readable by the same apps, unless you manually update permissions. See this thread for more: http://forum.xda-developers.com/show...=889471&page=5
The good news is that Android has Linux at its core, which naturally supports ext4, and actually all of the internal storage is (or will be in near future) formatted this way. The design limitation mentioned above is somewhat artificial and is enforced by
restricted functionality of funky little daemon, called vold. The sole purpose of vold is not monitor external storage,
detect filesystem on it, mount it as specified in /etc/vold.fstab (or vold.xxx in Android 4.3), and then report to the Volume Manager.Volume Manager in turn notifies the MTP application, and all other apps, displays icons and handles rest of user-visible stuff.
Stock Android vold only supports ExFAT/vfat filesystem. It has been improved in Cyanogenmod to support ext4 and NTFS filesystems, but for those of us stuck with OEM Android this goodness in unavailable. In my experience simply re-building vold from CM as part of AOSP,
while yields an executable, this executable results in a boot loop for an unclear reason.

All hope lost seemingly, yet there is a silver lining.

Silver Lining?

If MicroSD card is mounted manually in the way that vold can see it, re-running vold will properly report it to the Volume Manager and it will be recognized and utilized by apps.
In theory this is easy to accomplish on any rooted device, in practice there are a number of obstacles:
  1. On a locked device, it is not possible to update init script to run the commands at system bootup.
  2. Since Android 4.2, mount propagation no longer work (as described here http://forum.xda-developers.com/show...php?p=36889027),
    so if sdcard is mounted in terminal, vold will still not see it. Hence the mount operation has to be done in adb.
  3. Furthermore in Android 4.2.2, running adb on localhost is broken as a result of it loosing its private key.
    See here https://code.google.com/p/android/is...etail?id=48126 for more.

The solution?
Pre-requisites:
Step 1 - Fix adb localhost.
Open terminal and type the commands:

Code:
su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
start adbd
HOME=/sdcard adb start-server
adb connect localhost
adb -s localhost:5555 shell
exit
stop adbd
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd
Step 2 - Install scripts.

Please note that the script msd2.sh has to be modified if your device uses different partition names.
To get list of partition names available run command:

Code:
adb shell cat /proc/partitions
There are 3 (very simple) scripts:
sd.sh is just a convenience so that you don't have to type su everytime.
It calls msd1.sh which takes care of starting localhost adb in a reliable way.
It then executes msd2.sh in adb shell, which actually does the mounting trickery.

To install scripts, download the zip file below, open terminal, unzip the archive and change into msd directory.
Then connect your phone to your PC and run the following commands:

Code:
adb push sd.sh /sdcard/sd.sh
adb push msd1.sh /sdcard/msd1.sh
adb push msd2.sh /sdcard/msd2.sh
adb shell
su
mount -o rw,remount /system
cp sd.sh /system/xbin/
cp msd1.sh /system/xbin/
cp msd2.sh /system/xbin/
chmod 755 /system/xbin/*.sh
mount -o ro,remount /system
exit
exit
Step 3 - Profit.

In terminal app run command:

Code:
sd.sh
There will be some messages in notifications bar and then you will be asked if it is ok to restart MTP application. Click Ok.
That should be it.

Note that this last command will have to be executed every time device reboots (see obstacle #1).
You can automate it using Script Manager app from marketplace. In this case, ask Script Manager to run msd1.sh instead, marking it as Root script.



Disclaimers

I've developed and tested this procedure on Samsung Galaxy S4 Active phone from ATT.
Should work for any other Android 4.2 device.
The steps outlined are non-destructive if done properly and should not affect any other functionality, yet obviously I do not assume any responsibility for you damaging your device in the process.

It is a good idea to read the linked articles before performing the procedure, to get a better understanding of what is actually going on.
Attached Files
File Type: zip MountExt4SD.zip - [Click for QR Code] (995 Bytes, 1287 views)
The Following 3 Users Say Thank You to sashavasko For This Useful Post: [ Click to Expand ]
 
zzarr
Old
#2  
Junior Member
Thanks Meter 0
Posts: 1
Join Date: Oct 2012
Default Motorola Droid 4 (xt894)

Hello!

if you have a Motorola Droid 4 you need to change the third row in "msd2.sh" from
"mount -t ext4 /dev/block/mmcblk1p1 /storage/extSdCard && sleep 5 && /system/bin/vold" to
"mount -t ext4 /dev/block/mmcblk0p1 /storage/sdcard1 && sleep 5 && /system/bin/vold"

in order to get it to work, thanks for the guide!

Best Regards
/ Rasmus
 
SeaFargo
Old
#3  
SeaFargo's Avatar
Senior Member
Thanks Meter 31
Posts: 252
Join Date: Feb 2011
Location: Rome
Thumbs up It works well on TW based MIUI

It works well on TW based MIUI, so many many thanks!!!
But I still have the permission problems mentioned.

AOSP based MIUI is ext4 compatibile out of the box, and without permission problems.

This trick is amazing, but the permission issue make it useless ...

I can not shot a picture and than have to manually change the permission of tehf ile in order to view it on the gallery ...

Is there a definititive solution?
Raf.

[Motorola Defy - Official MIUI Dev. Ed. - GWK74 - android-2.3.7_r1 - Holo Launcher]
[Samsung GT-I9505 Galaxy S4 - MIUI v5 - JDQ39E - android-4.2.2_r1.1 - 3.4.66-ChronicKernel - ext4 sdcard - Advanced Xperia Z Launcher 2.0.6]
[Testing the new i9505 MIUI official porting and ext4 sdcard]
 
clint93
Old
#4  
Junior Member
Thanks Meter 0
Posts: 1
Join Date: May 2014
Default My lg l3 e400..sd card not mounted

to sashavasco:

sir, pls help configuring my phone...the codes u've given at the top part seems to work accordingly..but after when i entered the command
"cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys"
it says: "no such file or directory"
can you point out the problem of the device plss...
i appriciate your response..
my phone s LG L3 E400..CYANOGENMOD 9..external sd wont mount on my device
 
kevp75
Old
(Last edited by kevp75; 5th June 2014 at 01:28 PM.)
#5  
kevp75's Avatar
Senior Member
Thanks Meter 859
Posts: 1,853
Join Date: Aug 2012

 
DONATE TO ME
Quote:
Originally Posted by sashavasko View Post
Why?


Step 1 - Fix adb localhost.
Open terminal and type the commands:

Code:
su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
start adbd
HOME=/sdcard adb start-server
adb connect localhost
adb -s localhost:5555 shell
exit
stop adbd
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd
I am getting an error here: adb -s localhost:5555 shell stating device offline. I've done this 6 times now, and it's always the same error

Galaxy S4 i337 NC1 Rooted
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2014-06-05-08-25-53.jpg
Views:	171
Size:	193.2 KB
ID:	2781871  
Rockin' it from my Vision-X N3 US on My Note 3

Check me out online @ http://kevin.pirnie.us
 
Gigionaytor
Old
#6  
Junior Member
Thanks Meter 0
Posts: 5
Join Date: Sep 2014
Quote:
Originally Posted by kevp75 View Post
I am getting an error here: adb -s localhost:5555 shell stating device offline. I've done this 6 times now, and it's always the same error

Galaxy S4 i337 NC1 Rooted
the same for me...
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes