So I'm just trying to modify the hosts file on a family members phone. I've put the phone in debug mode and pulled the hosts file, edited it, but when I try to push it I get the message, "adb: error: failed to copy 'D:/hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory"
Here's the commands I've used:
adb pull /system/etc/hosts D:\hosts
/system/etc/hosts: 1 file pulled. 0.0 MB/s (56 bytes in 0.003s)
adb push D:\hosts /system/etc/
adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory
This is my first time using android debugging/adb and nothing else I've read helped. Thanks in advance.
EDIT: So I've made a little progress. I realized that the hosts file is not in a hosts directory, so I changed it to adb push D:\hosts /system/etc which still didn't work, but adb push D:\hosts\hosts /system/etc gave me the response adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system So it looks like my problem is now in adb shell chmod
EDIT2: So after some more research I came across this Read only file system on Android. When trying mount -o rw,remount /system I get mount: '/dev/block/dm-0' not user mountable in fstab. In the mounts file /dev/block/dm-0 is on /system. The new problem is fstab is not located in /etc
EDIT3: It looks like my big problem is I have to root the phone I think. I don't have su or sudo to do the remount. Seeing as it's not mine, I don't want to root the phone.
Related
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?
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'm trying to install valgrind on my android device, but when i try to execute adb push Inst /
i get an error
C:\VmFiles>adb push Inst /
push: Inst/data/local/Inst/bin/vgdb -> /data/local/Inst/bin/vgdb
failed to copy 'Inst/data/local/Inst/bin/vgdb' to '/data/local/Inst/bin/vgdb': N
o such file or directory
Ofc file vgdb exists in this directory
C:\VmFiles>ls Inst/data/local/Inst/bin
callgrind_annotate cg_diff valgrind vgdb
callgrind_control cg_merge valgrind-di-server
cg_annotate ms_print valgrind-listener
after some observation i found there is no directory Inst/bin in local
so first you need to make a directory in /data/local/Inst/bin
and for that you need root access to your device because you cant access /data/ directory without root permissions
then do following steps.
first go to directory where vgdb is placed then
execute
adb push vgdb /data/local/Inst/bin/
Syntax for adb push :
adb push <PATH_OF_FILE_ON_HOST> <PATH_OF_FILE_ON_DEVICE>`
Since you are trying to push from Inst/data/local/Inst/bin/ path. Use the below command with absolute path.
adb push /full/path/to/Inst/data/local/Inst/bin/ /path/on/device/test_folder/
This should push all (both files and directory) content of the directory Inst/data/local/Inst/bin/ to /path/on/device/test_folder/
Make sure /path/on/device/test_folder/ exist, or run below command before hand.
adb shell mkdir /path/on/device/test_folder/
Use adb shell ls /path/on/device/test_folder/ to list, if your files are transferred to the device.
Also make sure you have permission to write to /path/on/device/test_folder
Note: You will usually have permission to write to /sdcard/ but again will require root permission to assign execute permission (chmod) to the transferred binary.
In this case, may need to root the device.
When I run below command directly on prompt, it works fine by pulling all files from emulator sdcard:
adb -s emulator-5556 pull /sdcard/.
However when I create bash file (extract.sh) with above command and run it I get following error:
remote object 'C:/Program Files (x86)/Git/sdcard/' does not exist
As can be seen it somehow adds C:/Program Files (x86)/Git before it. These are the contents of bash file:
#!/bin/bash
adb -s emulator-5556 pull /sdcard/.
Does anyone have an idea of why it works when direcly typing on prompt and not via bash file ? Thanks
Is there any reason you're not specifying the destination directory? For example, the batch command I use when pulling pictures from my phone over USB is adb pull "/sdcard/DCIM/Camera" "E:\Phone Pics\HTC DNA" which specifies both the source directory on the phone and the destination directory on my computer. As a side note, like enedil I recommend using this in a batch file when working in Windows.
My problem is i can write files on sd card in emulator but i find the solution to this problem in stack overflow here to implement that you have to add a group media_rw under android.permission.WRITE_EXTERNAL_STORAGE in platform.xml so for i successfully pulled the xml file but after editing the file i can't push that file so when i am pushing it gives the below error
[Java is awesome]:~$ adb push platform.xml /system/etc/permissions/
failed to copy 'platform.xml' to '/system/etc/permissions//platform.xml': Read-only file system
to overcome this i remount the adb and again i tried i gives the below error
[Java is awesome]:~$ adb remount
remount succeeded
[Java is awesome]:~$ adb push platform.xml /system/etc/permissions/
failed to copy 'platform.xml' to '/system/etc/permissions//platform.xml': Out of memory
so how can push the file or is there any alternative that can enable editing of file with in the adb shell
Thanks in advance
You need to increase the /system partition size accordingly to account for the extra bytes in the file:
You can do this with the following command:
emulator -partition-size <size>
Where is the size depends on your system image plus the extra bytes.