2

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

I succeeded to make a partition with ext4 filesystem on the SD card, and I mounted successfully following the reference above. However, I still found that the permission issue is there if I want to copy some files from Linux systems to SD card.

I found that the gid of media_rw is 1023, therefore I created a group on Linux system as such:

# groupadd -g 1023 media_rw
# gpasswd -a USER media_rw

After that, I can modify data on sdcard. However, if I create some new files, the owner & group will be that of USER and the mode is 755 or 644, not 775 or 664. Everytime I need to run a root shell and

$ find . -type f -exec chmod 664 {} \;
# chown -R 1023:media_rw .

It's very annoying. I wonder what's the correct way to exchange data for cyanogenmod.

Any help? Thanks!

EDIT: I found a method to set permissions except the owner:

$ rsync -r -p --chmod=D775,F664 -g --chown=:media_rw SOURCE DEST
  • If you create a new file, it will always be owned by the user who created it. So you would have to sudo su - media_rw and work as that when creating files. As for the permissions, check man umask to set the umask correctly in ~media_rw/.profile. // Besides, that's not really an Android question. Wait until your apps create files there and see by whom they're owned ;) – Izzy Jul 2 '15 at 12:50
  • @lzzy Thanks, but I didn't create user media_rw, and even if I did that, I would prefer to set nologin and no shell. I don't know how Android system managed to create files owned by media_rw, and chown needs root privilege. (And yes, it's not really an Android question, but maybe these settings are calibrated for Android devices, and I'm asking a correct way. Maybe the correct way is to use exFAT, but it seems inappropriate to me to use such an obsolete and low-performance filesystem. There's a lot I heard about Android, say case insensitive by std.) – Yai0Phah Jul 3 '15 at 1:49
  • If you just care for the group, you could try to let the "parent folder" (where you mount the storage) belong to that group; AFAIR "child folders" inherit that then as long as the "owner" belongs to that group. As at the same time you might wish to have the created file set to rw for the group, that would be the umask again. But how to set that up for a specific folder/mount, I have no experience. That's better asked at SuperUser or Unix&Linux (wherever it fits better, check their resp. /help/on-topic). I see/share your points for extfs, but not sure how Android deals with it on sd card. – Izzy Jul 3 '15 at 6:23
  • @lzzy I didn't get your point on how to use cp. I found a method. See EDIT. – Yai0Phah Jul 3 '15 at 8:36
  • Good idea! However, shouldn't that be an answer (a little more detailed, maybe)? On SE sites, it's perfectly fine to answer your own question :) – Izzy Jul 3 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.