How to edit root files in /sys (Permission Denied)?


Question

I have been trying to change root files in my phone through an app I am developing. The phone I have is a Moto G6, fully rooted. I'm using terminal emulators to run commands on my phone. I've tried "Terminal Emulator for Android" and "Shell Terminal Emulator" apps to try to make my files modifiable.



The commands I've tried to run are as follows:



su
mount -o rw,remount /system


In Terminal Emulator for Android this appears to work because it offers no error message but in Shell Terminal Emulator I'm hit with the following:



"...whatever.../system not user mountable in fstab"


So I went to check if it worked anyway and tried to modify a file in the root browser. The file:



/sys/devices/virtual/android_usb/android0/power/control


The file currently has the permissions set as "rw-r--r--" and filled with the text "auto" and after trying to save the file with the contents "0" instead I'm provided with this big ugly error message:



Error when saving file
=====Description=====
java.io.FileNotFoundException: "...file name..." and then (permission denied)


What I want to know is why I don't have permission to edit these files, afterall my phone is fully rooted and I have granted root access to the text editor.



Any solution or step in the right direction is greatly appreciated.


Answer


in Shell Terminal Emulator app I'm hit with the following:

"...whatever.../system not user mountable in fstab"




toybox mount returns that error when UID isn't 0 i.e. you aren't root.




tried to modify a file in the root browser. The file:

/sys/devices/virtual/android_usb/android0/power/control




/system and /sys are two different filesystems. Mounting one R/W won't allow you R/W access to the other. /system is the mount point of a partition which contains Android OS. It can't be mounted R/W without getting root access and without disabling dm-verity. sysfs is Linux kernel's pseudo filesystem which provides information related to hardware stuff and exposes some interfaces to userspace for kernel configuration and tweaking.



sysfs is mounted R/W by default but not every file in this filesystem can be modified. Only some specific values can be written to specific files. The file you are trying to write is related to power management of USB Gadget driver of kernel which is to let the device be in some kind of slave role (device mode), not in USB host role. Possible values for control file are auto and on as per documentation.




after trying to save the file with the contents "0" instead I'm provided with this big ugly error message




I'm not sure about that Java related error, you can get better help at stackoverflow. However you can get a root shell and do:



~# echo -n on >/sys/devices/virtual/android_usb/android0/power/control


This must work, I've tried that in GUI text editor too. Probably the value 0 you are trying to write isn't a valid value for kernel, except if you are changing something at driver level.



If the purpose is only to edit files for testing which can't be accessed / modified without root, create / edit / delete a file in /data/local. /data doesn't need remounting.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes