9

I see some mentions here of creating an ext4-formatted SD card, but no guide. This closely-related question suggests there is no way to do it, but my question differs in that my phone is specifically rooted.

I formatted my card as ext4 (GUID partition-table); my Cyanogenmod phone mounted it at /mnt/fuse/sdcard1. I followed instructions here to mount the card at /storage/sdcard1, by creating the following script at /data/local/userinit.sh

#!/system/bin/sh
REALMNT=/mnt/fuse/sdcard1_real
if ! [ -d "$REALMNT" ]; then
  mkdir "$REALMNT" || exit 1
fi
mount -t ext4 /dev/block/mmcblk1p1 "$REALMNT"
sdcard "$REALMNT" /storage/sdcard1 1023 1023 &

I restarted and attempting to copy a file (using ES File Explorer) and paste it into its parent directory, which failed:

/storage/sdcard1/foo/bar.mp3: open failed: EACCES (Permission denied).

I can actually play the file fine, so I can open it. FWIW, when I try copying from the original mount point (/mnt/fuse/sdcard1), I get a slightly different error:

Failed to copy the file bar.mp3

I'm using a Samsung Galaxy S3 with Cyanogenmod 10.2.0-i9300.

==EDIT==

su
ls -l /mnt/fuse
drwxrwxr-x media_rw media_rw   2014-03-04 22:08 sdcard1

That was all. There is no sdcard1_real in this directory, so I suppose the script is failing?

==EDIT2==

I tried modifying the script to troubleshoot. The script begins fine, but then fails on mkdir "$REALMNT" with the error /data/local/userinit.sh[6]: : not found.

==EDIT3==

I know that the script doesn't work, so fixing it might solve my question, but I thought the following was interesting. I formatted my SD card in my Linux computer, and transferred some files to it. Oddly enough, permission errors only occur in the subdirectories that I created. In the root of the partition (via /storage/sdcard1), I already have write permission.

9
  • 1
    As root, please execute ls -l /mnt/fuse/ and ls -l /mnt/fuse/sdcard1_real. Then edit your question to include the results. My guess is "wrong file permissions" – either for the mount, or for the foo/ directory on the card. Remember, ext4 supports full *nix file permissions, incl. user and groups.
    – Izzy
    Commented Mar 4, 2014 at 13:21
  • You type su in terminal to get root. You may need to confirm granting the permission on the phone, if you're doing it for the first time.
    – Chahk
    Commented Mar 4, 2014 at 13:52
  • Either the script is failing, or it's not executed at all. You might wish to add some debug output, e.g. echo Script executed > /mnt/fuse/sdcard1/test.log, and check if it is running at all. If so, make the previous-to-last line mount -t ext4 /dev/block/mmcblk1p1 "$REALMNT" 2> /mnt/fuse/sdcard1/test.log and check the error message. Or execute the script manually to see: su /data/local/userinit.sh.
    – Izzy
    Commented Mar 4, 2014 at 14:00
  • @Izzy touch shows that the script is running. I tried executing the script manually with su /data/local/userinit.sh, but this failed. I also tried su echo foo, and get a similar error: Unknown id: echo.
    – Sparhawk
    Commented Mar 5, 2014 at 1:46
  • As for your EDIT3, see my first comment: ext4 supports full *nix file permissions, incl. user and groups. You've created those directories with a user that doesn't exist on your Android device, so they belong to "unknown user / unknown group". If you didn't grant write access to "world", only root could write there. You should make yourself familiar with those *nix basics when using such a file system on portable media ;) As for the script, I again suggest adding some more debug information, e.g. using echo to output each command before it's executed, and redirect error output with 2>>.
    – Izzy
    Commented Mar 5, 2014 at 10:15

4 Answers 4

7

This was supposedly fixed several months ago, but people are still reporting problems. I can read items on the card, but do not have write permission. To fix it, I combined strategies from a few sources.

  1. Partition card with MS-DOS partition table and ext4 filesystem. I used GParted on my (Linux) desktop computer.
  2. Insert the card into your phone. (You will probably not have write access now.)
  3. Open the terminal emulator, installed by default in Cyanogenmod.
  4. Type in the following (I recommend WiFi Keyboard for large blocks of text). Give the emulator root privileges when it requests them.

The $ and # indicate prompts, so don't type them in.

$ su
# chown media_rw:media_rw /mnt/media_rw/sdcard1
# chmod g+w /mnt/media_rw/sdcard1

This changes the SD card's permissions. The owner and group change from system to media_rw, and it also gives the group write access.

1
  • need -R for recursif chown -R media_rw:media_rw /mnt/media_rw/sdcard1
    – m3asmi
    Commented Dec 24, 2016 at 15:14
2

Not sure if it is any help, but possibly the issue is that that you are trying to mount in the wrong place ? This is my working script that works on an S3 mini with CM11:

#!/system/bin/sh
REALMNT=/mnt/media_rw/sdcard1
if ! [ -d "$REALMNT" ]; then
mkdir "$REALMNT" || exit 1
fi
mount -t ext4 -o rw,noatime /dev/block/mmcblk1p1 "$REALMNT"
sdcard "$REALMNT" /storage/sdcard1 1023 1023 

The REALMNT location already existed, so of course the mkdir was never called. And media_rw/sdcard1 is already owned by media_rw

I also had to update /etc/permissions/platform.xml to include: <group id="media_rw"/> in: <permission name="android.permission.WRITE_EXTERNAL_STORAGE">

7
  • Thanks. I'd somewhat given up on this, since I also had high battery usage with my script. Since it's fixed in trunk, I won't bother with a workaround any more. Thanks though, and +1.
    – Sparhawk
    Commented May 4, 2014 at 2:20
  • @Sparhawk: Not sure which CYM version you use, but my SD card is not mounted automatically. Commented Sep 6, 2014 at 20:47
  • @LuisA.Florit I'm not sure if you meant to reply to this answer. Anyway, I'm using 11-20140804-SNAPSHOT-M9-i9300. I've posted more info in another answer.
    – Sparhawk
    Commented Sep 13, 2014 at 23:42
  • @Sparhawk: My card is not even mounted, and the mount procedure in Settings fails. Maybe the problme is related my question here (su fails to mount): android.stackexchange.com/questions/82089/…` I use cm-11-20140804-SNAPSHOT-M9-mondrianwifi.zip . Commented Sep 14, 2014 at 14:26
  • @LuisA.Florit Not really sure. Perhaps ask a new question?
    – Sparhawk
    Commented Sep 16, 2014 at 6:47
0

There was an answer posted up by adasdadasd that I wanted to accept, but has since been deleted. I'll reproduce it below, and accept my answer, but if adasdadasd resurfaces, please repost and I'll delete this and accept yours.

https://jira.cyanogenmod.org/browse/CYAN-332

https://github.com/CyanogenMod/android_packages_providers_MediaProvider/commit/faf3f77b9222554227740aed8127714ea9e3f407

Fixed by default? New change in github.

0

Here the simpeline

#!/system/bin/sh
REALMNT="/mnt/media_rw/extSdCard"
mount -t ext4 -o rw,noatime /dev/block/mmcblk1p1     "$REALMNT"
sdcard "$REALMNT" /storage/extSdCard 1023 1023 &

And here writable ext4 on external sd

#!/system/bin/sh
chown media_rw:media_rw /mnt/media_rw/extSdCard
chmod g+w /mnt/media_rw/extSdCard

You can change "extSdCard" like "sdcard1" where your external sdcard mounted

Iam used stockrom with Kingroot, but I try Supersu its trouble with mounting filesystem

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .