FORUMS
Remove All Ads from XDA

[SCRIPT/FIX] Internal sdcard permissions (/data/media/)

379 posts
Thanks Meter: 211
 
By xak944, Senior Member on 5th April 2013, 06:40 PM
Post Reply Email Thread
This should be applicable to any ROM on devices which share internal storage for applications and the internal "sdcard" (Note II, SGS3, probably others). Symptoms may include inability to take screenshots and other failures, and will usually show a "Permission denied" in logcat for files under /data/media/. The underlying problem is that permission is denied to the filesystem, even by the root user when the ROM is booted (this is strange and I still don't understand why). Running "Fix permissions" did not fix this issue for me (that script doesn't change any permissions on the sdcard).

When booted into recovery (ClockworkMod was tested in my case), root has the ability to reset the permissions properly. To fix the problem, connect with adb while booted in recovery and run the following commands to correct the permissions:

Code:
chown -R media_rw:media_rw /data/media/
find /data/media/ -type d -exec chmod 775 {} ';'
find /data/media/ -type f -exec chmod 664 {} ';'
UPDATE (Credit to @Quinny899) If that does not work, you may also want to reset the SELinux contexts for the media partition with this command:
Code:
restorecon -FR /data/media/
Hope this helps!
The Following 60 Users Say Thank You to xak944 For This Useful Post: [ View ] Gift xak944 Ad-Free
 
 
29th June 2013, 07:26 AM |#2  
skoshy's Avatar
Member
Thanks Meter: 9
 
Donate to Me
More
I recently restored a Nandroid backup of my old Nexus 7 on a replacement Nexus 7. Most everything worked okay, but screenshots, deleting certain files and directories, and other basic operations weren't really working, and "Fix permissions" didn't help.

Running the commands here worked like a charm! I used TWRP and I have JellyBeer 4 on my Nexus 7. Thanks!
The Following User Says Thank You to skoshy For This Useful Post: [ View ] Gift skoshy Ad-Free
2nd July 2013, 04:36 PM |#3  
xak944's Avatar
OP Senior Member
Flag North Carolina
Thanks Meter: 211
 
More
skoshy,

I'm glad this helped you. JellyBeer is a fantastic ROM. Cheers!
5th July 2013, 12:14 PM |#4  
TheByteSmasher's Avatar
Senior Member
Flag Atlantis
Thanks Meter: 742
 
Donate to Me
More
Quote:
Originally Posted by xak944

skoshy,

I'm glad this helped you. JellyBeer is a fantastic ROM. Cheers!

Well, I created a ZIP of this for people to flash in Recovery, ADB sideload or in an App like Fashify... Only to realize that XDA superstar @osm0sis had already done pretty much the same thing with his sdcard Fix Permissions Script Found here. His script uses pure edify whereas mine uses linux commands.. Both work but his Was First so I will only leave the link for his.
Cheers!
The Following 2 Users Say Thank You to TheByteSmasher For This Useful Post: [ View ] Gift TheByteSmasher Ad-Free
5th July 2013, 12:19 PM |#5  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,933
 
Donate to Me
More
Yeah it's kinda funny. I had that script posted up in the ADBsync thread back in February because I noticed things could start acting funny when I restored an entire sdcard backup to one of my devices. But hey, great minds think alike! Good work all around!

Thanks @TheByteSmasher for bringing another use for the zip to my attention! I didn't know those things had a tendency to go awry on their own as well!

Edit:

Here's the edify script equivalent of the above, plus the proper original perms for /data/media itself, and the special perms that CWM likes its subfolder to have (root + all). TWRP keeps its backups under the primary user subfolder (/data/media/0) and doesn't seem to care as much.

cwm-sdcard.Fix.Permissions.zip/META-INF/com/google/android/updater-script:
Code:
ui_print("");
ui_print("sdcard Fix Permissions Script");
ui_print("by osm0sis @ xda-developers");
show_progress(1.34, 0);

ui_print("");
ui_print("Mounting...");
run_program("/sbin/busybox", "mount", "/data");
set_progress(0.2);

ui_print("");
ui_print("Setting /data/media to media_rw and fixing...");
set_perm_recursive(1023, 1023, 0775, 0664, "/data/media");
set_perm(1023, 1023, 0770, "/data/media");
set_progress(0.8);

ui_print("");
ui_print("Setting /data/media/clockworkmod perms...");
set_perm_recursive(0, 0, 0775, 0777, "/data/media/clockworkmod");
set_progress(1.0);

ui_print("");
ui_print("Unmounting...");
unmount("/data");
set_progress(1.2);

ui_print("");
ui_print("Done!");
set_progress(1.34);

Available over in my Odds and Ends thread as TheByteSmasher mentioned before.
The Following 5 Users Say Thank You to osm0sis For This Useful Post: [ View ]
5th July 2013, 10:21 PM |#6  
xak944's Avatar
OP Senior Member
Flag North Carolina
Thanks Meter: 211
 
More
Nice. Good to know this is a well known issue, I thought I was nearly alone (and it drove me up the wall for a while until I figured it out).

Does anyone know what is technically causing even the root user not to be able to write? I'm curious.
The Following User Says Thank You to xak944 For This Useful Post: [ View ] Gift xak944 Ad-Free
6th July 2013, 01:24 AM |#7  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,933
 
Donate to Me
More
Probably because even root apps only run root commands when they need to, so for simple stuff could run into the same issue. Just a guess, but makes sense.
6th July 2013, 02:11 AM |#8  
xak944's Avatar
OP Senior Member
Flag North Carolina
Thanks Meter: 211
 
More
I'm not talking about root apps. When I had the issue I couldn't modify any files with a shell over adb as the root user. Write operations always resulted in 'permission denied' errors. Generally in Linux, the only way this can occur is with filesystem permissions (root user bypasses this), the immutable bit (not set), or if it's a read-only filesystem (didn't appear to be based on the output of 'mount').
6th July 2013, 02:59 AM |#9  
TheByteSmasher's Avatar
Senior Member
Flag Atlantis
Thanks Meter: 742
 
Donate to Me
More
Quote:
Originally Posted by xak944

I'm not talking about root apps. When I had the issue I couldn't modify any files with a shell over adb as the root user. Write operations always resulted in 'permission denied' errors. Generally in Linux, the only way this can occur is with filesystem permissions (root user bypasses this), the immutable bit (not set), or if it's a read-only filesystem (didn't appear to be based on the output of 'mount').

Osm0sis actually states in the description of his zip, that when you use ADB push to put some stuff on the SD it can mess with the permissions... that's what did it for me.. but I guess a nandroid restore can cause it too depending on how it performs the action.

Sent from my Nexus 4 using Tapatalk 4 Beta
The Following 2 Users Say Thank You to TheByteSmasher For This Useful Post: [ View ] Gift TheByteSmasher Ad-Free
23rd July 2013, 04:53 AM |#10  
osm0sis's Avatar
Recognized Developer / Recognized Contributor
Flag Halifax
Thanks Meter: 29,933
 
Donate to Me
More
I'm ditching the idea of editing fix_permissions. The way they do all the system files is extremely intelligent and done on-the-fly based on the contents of certain system files to trace through. Adding something specifically for internal sdcards, even with the appropriate checks, would be a hack compared to all the really great work they've done to make the script device-nonspecific.
The Following 2 Users Say Thank You to osm0sis For This Useful Post: [ View ]
25th February 2014, 05:18 PM |#11  
Junior Member
Thanks Meter: 0
 
More
Deleted
Post Reply Subscribe to Thread

Tags
/data/media/, fix permission, internal sdcard, permission denied, screenshot

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes