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.

Sparhawk
  • 336
  • 1
  • 5
  • 17
  • 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 Mar 04 '14 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 Mar 04 '14 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 Mar 04 '14 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 Mar 05 '14 at 01: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 Mar 05 '14 at 10:15
  • @Izzy If I understand correctly, the purpose of the script is to fix these permission inconsistencies? I did do more debugging, but perhaps EDIT2 wasn't clear enough. The script ran up to exit 1, then failed with the error stated. – Sparhawk Mar 06 '14 at 22:56
  • Could it be the script runs too early, and /mnt/fuse is not there when you try to mkdir (try putting an ls /mnt before the mount command)? If so, a mkdir -p "$REALMNT" || exit 1 could work around that – but I'm not sure to the side-effects when the system tries to create /mnt/fuse later and it does already exist. – Izzy Mar 07 '14 at 10:58
  • @IrfanLatif I don't have a phone with an SD card anymore, but unlike your answer in the link, I don't remember any problems with "every app will create files with its own UID", as per my answer below. I can't really check this anymore unfortunately though. Anyway hopefully your link is useful to some here. – Sparhawk May 10 '20 at 00:02

4 Answers4

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.

Sparhawk
  • 336
  • 1
  • 5
  • 17
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">

user59177
  • 21
  • 2
  • 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 May 04 '14 at 02:20
  • @Sparhawk: Not sure which CYM version you use, but my SD card is not mounted automatically. – Luis A. Florit Sep 06 '14 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 Sep 13 '14 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):http://android.stackexchange.com/questions/82089/difference-between-su-vs-root-ssh-login-for-mounting` I use cm-11-20140804-SNAPSHOT-M9-mondrianwifi.zip . – Luis A. Florit Sep 14 '14 at 14:26
  • @LuisA.Florit Not really sure. Perhaps ask a new question? – Sparhawk Sep 16 '14 at 06:47
  • @Sparhawk: I've asked several questions about CYM, and got not a single answer. Without even using CYM much I've faced several bugs (like this one), and noone has been able to give a clue about any of them (not in stackexchange, nor in CYM forum). I think I'll install another custom ROM, a more solid one. This is simply not working properly for me. – Luis A. Florit Sep 17 '14 at 00:07
  • I used this script in Stock Android 4.4.4 (Galaxy Note 4), but the files in /storage/sdcard1/ are shown with ownership 0.1015 instead of 1023.1023, giving lots of 'permission denied' errors of course. Any idea why? – Luis A. Florit Feb 07 '15 at 13:25
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

Ykg
  • 1
  • 1
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.

Sparhawk
  • 336
  • 1
  • 5
  • 17