When is (Android) root not root?

Having rooted my Moto G3 smartphone, and before trying to install a custom ROM, I decided to explore what my newly-minted root access would actually provide. In particular, I wanted to clean out some system apps that I never use, and root access is a necessary prerequisite to doing this. There are various ways of removing system apps – from a manual method using a file manager that can make use of root access – to specific apps that are designed to either backup or remove other apps. However, it appears that there can still be problems with the root user not actually having root access!

Since Android is essentially an “app-machine”, my first attempts to uninstall various system apps involved the use of custom apps obtained from the Play Store. These had varied success. Mostly, they went through the process of “uninstalling” a particular system app, without producing any error messages. However, when checking Settings – Apps, the “deleted” app was found to be still present. In another case, the app uninstalled the relevant Android Package (.apk) file but left the associated folder and its sub-directories in place. In short, my system folder was a mess. Folders that had been “deleted” were still there, and others had been only partially deleted.

Various web postings suggest that one problem with not being able to delete system files results from Secure Linux (SELinux) being implemented in the Linux kernel such that an “Enforcing” mode is set. By default, enforcing mode prevents the user – even the root user – from modifying system files. The nominal workaround is to reset the mode, temporarily, to “Permissive”.

This can be done using a terminal app, such as Terminal Emulator for Android. As the name suggests, this app provides a terminal window. The current status of SELinux can be obtained by giving the commands:

su
getenforce

The system will almost certainly respond with: Enforcing. To change this setting, we give the command:

setenforce 0

Entering the getenforce command once more now gives: Permissive. Thus, we have successfully changed the status of SELinux.

However, this is still likely to be insufficient. For example, attempting to delete a system file, notably the file CloudPrint.odex in the /system/app/CloudPrint/oat/arm/ folder, resulted in the message:

rm: CloudPrint.odex; Read-only file system

Clearly, the root user, having root access, and with SELinux set to permissive, is still not able to delete a system file because the system folder is mounted as read-only.

The next solution is to mount the system folder (or really to remount this folder from its current read-only status) as read-write. Note that this does not require SELinux to be set to be permissive. The system folder’s status can be changed even if SELinux is left set to enforcing. Mounting the system folder as read-write is achieved through the command:

mount -o remount,rw /system

Now, having changed directory to /system/app/CloudPrint/oat/arm/, we can remove the file CloudPrint.odex using the command:

rm  CloudPrint.odex

We can now back out of the arm folder and remove this directory using the commands:

cd ..
rmdir arm

However, once we have the system folder mounted as read-write, it’s actually more convenient to use a root-aware file manager, such as Amaze File Manager. Amaze provides simple, directory-tree listings that allow navigation through the various folders of the phone’s file system. And, in particular, the three-vertical-dots icon to the right of each file or folder allows access to various options (see, for example, the options for the Videos folder shown in the sample screenshot).

These options include Delete, which now allows the item to be deleted. In addition, the Properties option provides access to the file or folder’s attributes. The permissions are hidden, but clicking on the “PERMISSIONS” button, and scrolling up, will display them. The file owner (root in this case) can be seen to have Read, Write, and Execute permissions but, as we have seen, even though root has write access doesn’t necessarily mean that any given system file can be deleted!

However, once the system folder has been mounted as read-write, the Delete option does in fact delete a file or folder. So, using Amaze, we can quickly and easily navigate through the system folder and remove and orphaned files and folders, or any other system apps that we wish to “uninstall”.

Once we have completed deleting the selected files and folders, we can (and should) restore the system folder to read-only status. This can be done using the command:

mount -o remount,ro /system

Alternatively, simply re-booting the phone will eliminate the read-write status on the system folder.

One final note of caution – some might say sanity – for anyone considering following this path. If the primary goal of the exercise is to stop specific system apps from (annoyingly) automatically updating, it is much more efficient to simply disable the relevant apps (See: Disabling System Apps on a Smartphone). If you are expecting to save GB’s of disk space – think again. Compared to the footprint of the entire operating system on the phone’s internal storage, the space occupied by a handful of (unused/disabled) apps is very minimal.

However, if to wish to pursue system file deletion as an academic exercise, and learn something more about the Android operating system, then by all means go ahead. The manual method noted above is one way to attain the desired goal. However, it turns out that one of the Play Store apps will probably do the job much easier. Stay tuned for details in the next posting.

References:

How To Remove Unwanted Apps From Your Android Device
http://www.makeuseof.com/tag/remove-unwanted-apps-android-device/

Android File System Structure/Architecture/Layout Details
http://techblogon.com/android-file-system-structure-architecture-layout-details/

Making sense of your Android phone’s storage folders
http://www.androidauthority.com/phone-storage-folders-explained-744100/

Where in the file system are applications installed?
https://android.stackexchange.com/questions/3002/where-in-the-file-system-are-applications-installed

Rooted, yet cannot delete file from \system
https://androidforums.com/threads/rooted-yet-cannot-delete-file-from-system.439534/

[FIX] Issues with uninstalling system apps – even with TiBu?
https://forum.xda-developers.com/google-nexus-5/general/fix-issues-uninstalling-apps-tibu-t2592456

How do I delete this read only file?
https://android.stackexchange.com/questions/49225/how-do-i-delete-this-read-only-file

SELinux on Android
https://lwn.net/Articles/609511/

SELinux System Administration
https://tinyurl.com/SwitchSELinux

SELinux Toggler – Change SELinux Mode in Just One Tap!
http://www.droidviews.com/selinux-toggler-change-selinux-mode-just-one-tap/

Terminal Emulator for Android
https://play.google.com/store/apps/details?id=jackpal.androidterm&hl=en

Guide:Using the Terminal
https://forum.xda-developers.com/wiki/Guide:Using_the_Terminal

mount(8) – Linux man page
https://linux.die.net/man/8/mount

Amaze File Manager
https://play.google.com/store/apps/details?id=com.amaze.filemanager&hl=en

Advertisements
This entry was posted in Android, Commands, Moto G3 and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s