Hi,

I would like to change the owner of a directory on the sdcard /sdcard/aDirectory

I have a terminal installed on my Android 10 (LineageOS 17) com.android.terminal

sudo is not present so I use su and it works.

su
#Terminal was granted Superuser rights

cd /sdcard
chown 10:10 aDirectory
#I don't get any error message.

stat aDirectory
#Uid (0/root)

So the owner stay root no matter what I’m doing, any ideas ?

17 points

What filesystem do you have on that SD-card? Likely FAT32, which does not support ownership.

permalink
report
reply

But is it an SD card.

I mean, the directory name says so, but…

~ $ realpath /sdcard
/storage/emulated/0
~ $

…it may also not be.

permalink
report
parent
reply

It doesn’t matter. FAT filesystems - which are usually the default on SD cards, simply do not support ownership or file permissions. Linux emulates these attributes at mount time, but they apply to the entire SD card. You can mount an SD card and tell Linux to act as if root owns everything on the card; you that you own everything on the card; and it will be so until you unmount it and remount it with a different ownership.

These are filesystem level attributes, not device attributes. If you have a modern internal nvme drive and you format it with vfat, you will not be able to set permissions or ownership at the file level, but only at mount time, for the entire drive.

permalink
report
parent
reply

I am talking about some devices using /sdcard to mount internal storage.

permalink
report
parent
reply
15 points
*

Unless the SD card is using a Linux filesystem, you won’t be able to use Linux access permissions.

Most SD cards are preformatted to FAT or exFAT in order to maximise compatibility. If you don’t need to use the card on any non-linux devices you should be able to reformat it and gain the ability to chown/chmod (should go without saying, but back up any data on the card you want to keep before this)

permalink
report
reply
2 points

There are other comments here which might have some relevance but imo this one is the most likely the most applicable. I’ve had this experience with other filesystems over and over and it seems like it’s almost always a problem. Apparently NTFS supports permissions in a similar way to Linux if you set it up exactly right, but I’ve never taken the time to try that.

permalink
report
parent
reply
11 points
*

Nine times out of ten, running chown on Android is an astronomically bad idea. 10 times of 10, what you’re trying to do right now, is an astronomically bad idea.

What is it you are trying to do? Or rather, why?

permalink
report
reply
10 points

If you want to change the owner of fat partition, you can do it while mounting, e.g. mount -t fat -o uid=10,gid=10 ......

permalink
report
reply

Android users all kinds of overlays over the sdcard directory. This is part of how it enforces storage access for apps. There’s probably a way to override these settings, but they sure as hell aren’t easy.

There’s also another layer of permissions somewhere seeing as I can’t access certain files on /sdcard that were created by the recovery. I assume it’s an selinux context issue (it always is).

Changing ownership should work on real SD cards with normal storage, but it won’t for the emulated internal /sdcard.

permalink
report
reply

Android

!android@lemmy.world

Create post

DROID DOES

Welcome to the droidymcdroidface-iest, Lemmyest (Lemmiest), test, bestest, phoniest, pluckiest, snarkiest, and spiciest Android community on Lemmy (Do not respond)! Here you can participate in amazing discussions and events relating to all things Android.

The rules for posting and commenting, besides the rules defined here for lemmy.world, are as follows:

Rules


1. All posts must be relevant to Android devices/operating system.


2. Posts cannot be illegal or NSFW material.


3. No spam, self promotion, or upvote farming. Sources engaging in these behavior will be added to the Blacklist.


4. Non-whitelisted bots will be banned.


5. Engage respectfully: Harassment, flamebaiting, bad faith engagement, or agenda posting will result in your posts being removed. Excessive violations will result in temporary or permanent ban, depending on severity.


6. Memes are not allowed to be posts, but are allowed in the comments.


7. Posts from clickbait sources are heavily discouraged. Please de-clickbait titles if it needs to be submitted.


8. Submission statements of any length composed of your own thoughts inside the post text field are mandatory for any microblog posts, and are optional but recommended for article/image/video posts.


Community Resources:


We are Android girls*,

In our Lemmy.world.

The back is plastic,

It’s fantastic.

*Well, not just girls: people of all gender identities are welcomed here.


Our Partner Communities:

!android@lemmy.ml


Community stats

  • 2.6K

    Monthly active users

  • 1.4K

    Posts

  • 27K

    Comments