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 ?
What filesystem do you have on that SD-card? Likely FAT32, which does not support ownership.
But is it an SD card.
I mean, the directory name says so, butβ¦
~ $ realpath /sdcard
/storage/emulated/0
~ $
β¦it may also not be.
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.
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)
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.
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?
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 ......