I'm trying to modify the hosts file on my android phone and I am using adb for this on Ubuntu 20.04 to pull the file, modify it and push it back as suggested here. I was able to pull the file but when I try to push it I get an error
adb: error: failed to copy 'Documents/hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system
One suggestion seems to be to run adb remount or adb shell mount -o rw,remount /system (I'm not sure if these meant to be run on the android device itself) and this doesn't work for me, I get
/system/bin/sh: /system/bin/remount: inaccessible or not found
To this, there seems to be a suggestion to run adb root which returns adbd cannot run as root in production builds. Now I'm not sure how to proceed. There are some threads online saying what to do about this but I feel this is way above my head already. I just want to push the hosts file back to the phone. Is there a simple way to do this?
Related
My phone Samsung Galaxy S5 mini is rooted. I'm trying to pull files from /data/data/myapp.package/ to folder on my PC.
adb pull /data/data/myapp.package E:\myapp\myapp.package
it gives me this error
adb: error: failed to copy '/data/data/myapp.package' to 'E:\myapp\myapp.package': Permission denied
I found many questions like mine but no answer solved my problem. Some suggested to execute this command adb root before pulling files. Some suggested to install adbd insecure app to enable root access. In fact after installing that app, phone disappeared from adb terminal. Both solution didn't work for me.
BTW, I can copy files using cp command from adb shell but I have to copy files to sdcard and then pull from sdcard. I'm looking for solution which allows me to copy files directly from /data/data/myapp.package to my PC
Any solution?
For your adb to be able to access /data/data directly (for adb pull), your adbd should be running as root - which can generally be done by adb root command.
adb root would not work on commercial devices like Samsung Galaxy S5 mini as commercial devices have ro.secure=1, i.e., the adbd can't be restarted as root due to a check of property called ro.secure. adbd insecure app circumvents this and restarts adbd in root mode to enable adb pull, etc. to work.
In short, if adbd insecure app doesn't work for you, it's not possible to do adb pull from /data/data in your existing ROM. It might be possible if you change the ROM / do some boot.img tweaks, but I would probably suggest trying latest version / different versions of adbd insecure app before going for ROM changes.
Read more on rooting here.
First you need to hit these two command from command line
adb root
adb remount
then
adb pull /data/data/myapp.package E:\myapp\myapp.package
This is my example pulling DB file from the root directory
adb -e shell "run-as com.example.project cp /data/data/com.example.project/databases/project.db /sdcard"
The key is run-as
Here's a one-liner that lets you pull a file without installing anything else and without having to copy it to a public location on the device to then pull it to your computer:
adb exec-out su -c cat /data/data/myapp.package/my_file.apk > my_file.apk
What this does:
adb exec-out runs a command and outputs the raw binary output
su -c runs the provided command as root
cat <file> prints out the file contents
> <file> redirects the output from adb (i.e. the raw file contents) to a local file.
Question
I want to call my secure website, which is using a self-signed certificate, and is running on my development machine, from my emulator that is running on the same machine
context
I create a self-signed certificate, and installed on my development machine, and edited the hosts file to link the localhost to my domail. So:
https://mydomain:8080 works perfectly on my development machine.
I installed the same certificate on my emulator, so:
https://10.0.2.2:8080 works but there emulator cannot verify the certificate because I am calling 10.0.2.2 while the certificate is issued for mydomain
The solutoin is to link the 10.0.2.2 to my mydomain on the hosts file
The problem is that I am not able to override (edit) the hosts file on the emulator, the error message states that the file is "read-only"
My attempts
It is being a long time and I am trying, I almost tried everything thing I could found, but no success, to list some:
First
adb shell
su
mount -o rw,remount /system
chmod 777 /system
The I get the same error message
Second
I run the emulator from adb command, with writable permission, but the same error happened
Third
I tried to root the emulator so I can use apps, such as Hosts Editor, but after so many trial and errors, I am not able to root the emulator
Well, I tried many, I hope you guys can give me some insights
Update
According to the aastefanov's answer, maybe the system/ folder is still not allowed to have write access on it
I found a solution:
The solution is to modify the hosts file from the shell script, without overtiring it.
Move technical stuff
adb root
adb shell
su //to get the root access
whoami // just to be sure we are the root user now
//now we are root but we cannot modify the hosts file because it is just on read-only state
mount -o rw,remount /system //to make it writable (you can be more specific and apply it to just system/etc folder)
echo "10.0.2.2 williamromadomain" >> /system/etc/hosts
This is just a work around, because I have to do that every time I run the simulator
This is fairly a very old question but I am surprised that none of the solutions are working for me. I need to run an android app as system app in an AVD (in emulator) created for Android version 7.0. For this, I want to push apk file to system partition but I keep getting error saying it is read only file system. I found many similar questions on stackoverflow but nothing is working for me. I restarted adb in root, executed it with remount as suggested in answers to similar questions, but system partition file system permissions do not change. Here is a sample session:
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb root
restarting adbd as root
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb remount
remount succeeded
mvsagar#mvslt:~/sw/android_sdk/platform-tools$ ./adb push /home/mvsagar/projects/AndroidStudioProjects/LcnApps/app/LCNUE.apk /system/app/LCNUE.apk
adb: error: failed to copy '/home/mvsagar/projects/AndroidStudioProjects/LcnApps/app/LCNUE.apk' to '/system/app/LCNUE.apk': couldn't create file: Read-only file system
I have tried manually remounting with read/write(rw) options using adb shell, but the remounting fails.
Is there any way to have read/write permission on system partition?
My dev env is Android Studio on Ubuntu.
In my case, I use a avd( Based on: Android 8.0 (Oreo) Tag/ABI: google_apis/x86_64 ).
$ emulator -avd Nexus_5X_API_26_APIs -writable-system
$ adb root
$ adb remount
Then, /system is writeable.
$ adb push somefile /system/bin/ is work.
When working with Q, this is the only solution that worked for me: https://stackoverflow.com/a/64397712/1898527
Adding here the steps for completion (kudos to the original author):
> emulator -avd Pixel_3a_XL_API_29 -writable-system
> adb shell avbctl disable-verification
> adb disable-verity
Now reboot your emulator so that the changes take effect.
> adb root
> adb remount
> adb shell "su 0 mount -o rw,remount /system"
Note: you will need an emulator without Google Play, otherwise this won't work. You can get it by following the steps described here: https://stackoverflow.com/a/45668555/1898527
use genymotion emulator, which is faster, light weight and pre rooted. (which means you can access system directory)
For the benefit of others, answer to the question was answered a long ago by #Ishamael in another stackoverflow question Read only file system on Android
I am working in emulator to connect in localhost. For some reason, I need to change the locahost network connectivity. I received the localhost file from System and moved to say for eg: C:/temp/host location. In the host file, I edited and again I tried to move to System/etc/hosts but it fails to move the file. It display the error as couldnt create file: Read-only file system. Please suggest me solution.
Below are the Steps followed:
C:\Users\Android\sdk\platform-tools> adb pull /system/etc/hosts C:/temp/hosts
[100%] /system/etc/hosts
The file has been successfully moved to temp folder.
After I edited the file, I tried to push. But it fails.
C:\Users\Android\sdk\platform-tools>adb remount
Not running as root. Try adb root first
C:\Users\Android\sdk\platform-tools> adb root
C:\Users\Android\sdk\platform-tools> adb push C:\temp\hosts\system\etc
adb error: failed to copy 'C:\temp\hosts' to '/system/etc/hosts': couldn't create file Read only file system.
You must do "adb remount" after "adb root", after you can do the push.
adb root
adb disable-verity
adb reboot
adb root
adb remount
and the run the
adb push .....
you may see error like this because of all the reboot and roots
error: no devices/emulators found
just run this command
adb devices
you will see something like this
List of devices attached
0123456789ABCDEF device
and then try it again.
I am currently using 'Visual Studio Emulator for Android' to run android apps on my computer, i find that after using multiple types of emulators bluestacks, genymotion, andy etc. That VS is the most stable and easy-to-use out of them all.
The only problem that i have compared to the other emulators is running apps that require root permission, with this being an emulator i know that its not possible to go the route of rooting via fastboot/recovery, this is the only method i know of rooting as thats how i normally do it on my phone.
I have tried most of the 'rooting' APK's (kingo,towel,frama etc) and none of those have worked.
So would anybody happen to know how i can get root access on Visual Studio Android Emulator?
I am trying to run a touch-replication app (Frep & RepetiTouch) but all of them seem to require root access.
Any advice would be much appreciated. Thanks
Yes, you can. Here are some basics before the steps. Fundamentally all Visual Studio Emulator has root access; if you do adb shell you will get a root prompt. The only thing that is missing is the su binary and access for applications to connect to root shell through su. You can get the su binary from superuser apk from clockworkmod and the access to the root shell through the su daemon.
Installing su binary
Download superuser apk from clockworkmod. Ideal way is to download the app from google play store and navigate to /data/app/ and copy com.koushikdutta.superuser to your pc through adb pull /data/app/com.koushikdutta.superuser <local_path_in_your_system>
Change the .apk extension to .zip.
Navigate to assets/x86/ and copy the su binary to /system/xbin in your emulator
adb push <location_of_su> /system/xbin
chmod with suid and rwx
adb shell
chmod 6777 /system/xbin/su
symlink to /system/bin
ln -s /system/xbin/su /system/bin/su
Run the su daemon
/system/xbin/su --daemon
Giving Access to Applications through su
Install the superuser binary by either dragging and dropping into
the emulator or using adb install <path_to_superuser_apk>
Download rootchecker free\basic or even a terminal emulator for that
matter. We just want to check if our device is rooted.
Run the rootchecker app to check root and you should be able to get
the prompt from superuser.