Sunday, July 2, 2017

cyanogenmod - How can I mount an ext4-formatted SD card with correct permissions (with root)?


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.




Answer



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.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...