• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

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

Search This thread

sashavasko

New member
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/showthread.php?t=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/showthread.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/issues/detail?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.
 

Attachments

  • MountExt4SD.zip
    995 bytes · Views: 15,276
Last edited:

zzarr

New member
Oct 11, 2012
4
1
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
 
  • Like
Reactions: obade ameer

SeaFargo

Senior Member
Feb 24, 2011
322
59
Rome
rvd.it
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?
 

clint93

New member
May 15, 2014
1
0
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

Recognized Contributor
Aug 29, 2012
8,372
7,236
MA
kevinpirnie.com
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
 

Attachments

  • Screenshot_2014-06-05-08-25-53.jpg
    Screenshot_2014-06-05-08-25-53.jpg
    193.2 KB · Views: 2,416
Last edited:

karels.werk

New member
Oct 1, 2014
1
0
same error "unable to connect to local host:5555"

rooted Asus memo-7 build ME173X_US_user_4.2.404152_20140714 release-keys. But thanks for the heads up on Cyanogenmod.
 

Nothing89

New member
Jan 10, 2010
3
1
>>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.

Re-running vold crashes it ("Segmentation fault") if sdcard is already mounted in ext4. If not, it restarts gracefully.
Stock android 4.4.2. AFAIK, vold must inform userspace stuff that sdcard is available, without it, android do not see any sdcard at all...
What can be done here?

p.s. Is there anywhere patched or recompiled vold which supports ext4?
 
  • Like
Reactions: kevp75

DemisesAngel

Member
Mar 24, 2011
48
3
I had to modify terminal commands a bit to allow me to connect properly. Only moving the "start adbd" command down because the key needed to be appended to "adb_keys" before starting the service back up.
Code:
su
setprop service.adb.tcp.port 5555
adb kill-server
stop adbd
HOME=/sdcard adb start-server
cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys
start adbd
adb connect localhost
adb -s localhost:5555 shell
exit

I'm also still dealing with the "msd1.sh" script execution consistently asking about my fingerprint and not remembering it. If I don't press "continue" quick enough it claims the resource is busy, which prompted me to also change the msd1.sh script sleep from 2 to 5. I have gotten the notification that msd2.sh has been elevated, which seems like it ran, but my partition still doesn't get mounted, even though I've got the right one from the /proc/partitions output.

Another note, because I had BusyBox installed, I needed to prepend "busybox" (no quotes) to the mount command in the msd2.sh or else that wouldn't work either.

Anyone have thoughts?
 
Last edited:

aziz07

Senior Member
Oct 27, 2013
320
65
I followed DemisesAngel suggestion. There was no error this time but nothing happens when running any of the 3 scripts. I tried mmcblk1 and mmcblk1p1, also changed microsd path to match, /MicroSD, but nothing works. Even with manual ext4 mount command ...
Clicking mount in settings still results in incompatible storage and file explorer shows no sdcard.

Edit: Set permissions, script will run but nothing mounts unsupported file system ...
 
Last edited:

Compguymn

New member
Jul 24, 2015
1
0
Error directory already exist

I folllow the steps but i.think I meaaes up.
When u run through DemiseAngel scripts
At:
car /sdcard/.android/adbkey.pub >> /
Error:tmp-mkish:cant create /:Is a directory
To I attempt to find and rm it, or would that mess something up

Rca RCT677W22
 

WrathBand

Member
Jun 26, 2013
29
1
Zajecar
I dont know if this thread is closed but I have one simple question, can I somehow partition sdcard and have a little space for music and other stuff, and to use ext4 partition alongside with this, lets say "visible" partition ( I mean on windows).
 

whitedavidp

Senior Member
Jul 31, 2012
574
167
I dont know if this thread is closed but I have one simple question, can I somehow partition sdcard and have a little space for music and other stuff, and to use ext4 partition alongside with this, lets say "visible" partition ( I mean on windows).

First, I have been able to create a formatted partition of less than the full size of an SD card. I did this because my Android seems to have issues with anything larger than 16GB and all I had lying around was a 64GB. I did not try to do anything with the remaining space. Maybe it could work, maybe not. I would have my doubts.

Second, thanks for this discussion. Here is what "kind of" works on my Android 5.1 TV computer:

su -mm -c mount -t ext4 -o noatime /dev/block/mmcblk0p1 /storage/sdcard1 && sleep 5 && /system/bin/vold
chown -R root:sdcard_r /storage/sdcard1
chmod 771 /storage/sdcard1

I say "kind of" because this is still not seen as a true, external storage card by Android or file manager apps (and the like). However, all apps can read/write/traverse the folder tree and do what they need to. You do NOT have to be root except to do this. As things stand for me now, I have to re-issue this upon every re-start of Android. But using Tasker makes this pretty easy to accomplish.
 

sieger007

Senior Member
Jul 4, 2008
221
18
Dublin
long as a problem remains so do this thread ! . Well i am on 7.x and wonder if the op would post a method or even approach for getting a
Code:
ext4
partitioned sdcard so that vold is well aware of that and will mount sdcardfs on that giving all apps access to the partitions. I have 3 of these on my card .
 

Top Liked Posts

  • There are no posts matching your filters.
  • 9
    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/showthread.php?t=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/showthread.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/issues/detail?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.
    1
    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
    1
    >>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.

    Re-running vold crashes it ("Segmentation fault") if sdcard is already mounted in ext4. If not, it restarts gracefully.
    Stock android 4.4.2. AFAIK, vold must inform userspace stuff that sdcard is available, without it, android do not see any sdcard at all...
    What can be done here?

    p.s. Is there anywhere patched or recompiled vold which supports ext4?
    1
    Is there a method to auto mount ext4 partition on external SD that works on lineageOS 17.1 on S4 i9506?