I'm trying to setup hosts file for android emulator. I saw this advice:
adb remount
adb push hosts /etc/system/hosts (most tutorials suggest
this file)
adb push hosts /system/etc/hosts (some VM systems seem to
prefer this file instead!, for me this worked)
But when I do adb remount it writes "remount of the / superblock failed: Permission denied". I'm going to adb shell, but it also writes an error.
generic_x86:/ # mount -o remount,rw /system
mount: '/system' not in /proc/mounts
1|generic_x86:/ # mount -o rw,remount,rw /system
mount: '/system' not in /proc/mounts
generic_x86:/ # mount -o remount,ro /system
mount: '/system' not in /proc/mounts
1|generic_x86:/ # whoami
root
I reinstalled Android Studio twice it didn't help. Could anyone help pls?
Usage of -writable-system flag made ADB remount work. Hosts were replaced with the new file.
Launched emulator as:
emulator.exe -writable-system -avd Nexus_5X_API_28_x86
The hosts file is located at a directory that is not allowed to write over a file. So, you should first copy hosts to somewhere else, edit it, and then copy it back.
For example, let's work on the standard emulator:
Run the following command while the emulator is open:
adb devices
This command will show the running emulators. Run the following command to disable the emulator's read-only behaviour:
adb -s emulator-5554 remount
After this step, it should log remount succeeded. Then you should copy the emulator to another directory for editing:
adb -s emulator-5554 pull /system/etc/hosts ~/Desktop/
After this step, it will log about the file transfer's success. Now you can edit the hosts file. After the edit, you should push the file back. First of all, you should reboot the adb:
adb reboot
Emulator will restart itself. After this, you can remount the adb:
adb -s emulator-5554 remount
After the remount, you can push back hosts file:
adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts
Related
I want to be able to write to /system in my Android Studio Emulator. I've made sure to use a rootable, non-Google Play Services AVD. I'm currently using the Pixel 2 - API 28 AVD (targets Android 9.0).
I've made sure to run adb root and that works, though adb remount gives remount of the / superblock failed: Permission denied as an error. (I also tried running adb disable-verity and rebooting before remounting, but I still get the same remount error.)
I've tried adb shell mount -o rw,remount /system, but I get mount: '/system' not in /proc/mounts.
I've also tried
adb shell
su
mount -o rw,remount /system
but get the same mount: '/system' not in /proc/mounts error
(I've tried it without /system too. It appears to work, but if I then try to write to /system, I get mv: /system: Read-only file system)
I've tried emulator -avd -writeable-system but I get 'emulator' is not recognized as an internal or external command, operable program or batch file.
Can someone please help me figure out how to run the emulator in such a way that I can write to /system?
On Windows open a command prompt/power shell in C:\Users\YourUser\AppData\Local\Android\Sdk\tools and execute
.\emulator.exe -writable-system -avd Pixel_2_API_28
In another command prompt/power shell in C:\Users\YourUser\AppData\Local\Android\Sdk\platform-tools execute
.\adb.exe remount
On Linux you can use the the following commands:
$ANDROID_HOME/tools/emulator -writable-system -avd Pixel_2_API_28
adb remount
I'm trying to edit the hosts file on the Marshmallow emulator, but I can't do it. I use ADB tool:
I start emulator using emulator.exe
adb mount
adb pull /system/etc/hosts c:\temp
Then I edit hosts file
ADB push c:\temp\hosts /system/etc (this step doesn't work, because I get error - "read-only file system").
Also, I tried to do adb shell and then SU commands and then mount -o rw,remount /system. But every time when I try to edit hosts file, I get the error that file system is read only.
Any ideas?
Try this for the remount:
adb shell
setenforce 0
mount -o rw,remount /system
setenforce 1
These steps work for me (Windows 8.1 and Android Studio emulator (qemu))
Open a Command Prompt
cd %localappdata%\Android\sdk\tools
Run the emulator from the command line with -writable-system flag, e.g.
emulator -avd (your AVD name) -writable-system
While the emulator is booting (wait until the Android splash appears):
cd %localappdata%\Android\sdk\platform-tools
adb root (do not proceed until this command has been successful)
adb remount
adb push c:\temp\hosts /system/etc/hosts
I recently rooted my Droid X and everything seems to be working perfectly. I made some changes to build.prop and when I do adb push build.prop /system/ I get the following error: failed to copy 'c:\build.prop' to '/system//build.prop': Read-only file system.
How can I fix this?
Not all phones and versions of android have things mounted the same.
Limiting options when remounting would be best.
Simply remount as rw (Read/Write):
# mount -o rw,remount /system
Once you are done making changes, remount to ro (read-only):
# mount -o ro,remount /system
adb remount
works for me and seems to be the simplest solution.
While I know the question is about the real device, in case someone got here with a similar issue in the emulator, with whatever tools are the latest as of Feb, 2017, the emulator needs to be launched from the command line with:
-writable-system
For anything to be writable to the /system. Without this flag no combination of remount or mount will allow one to write to /system.
After the emulator is launched with that flag, a single adb remount after adb root is sufficient to get permissions to push to /system.
Here's an example of the command line I use to run my emulator:
./emulator -writable-system -avd Nexus_5_API_25 -no-snapshot-load -qemu
The value for the -avd flags comes from:
./emulator -list-avds
Got this off an Android forum where I asked the same question. Hope this helps somebody else.
On a terminal emulator on the phone:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
Then on the cmd prompt, do the adb push
I think the safest way is remounting the /system as read-write, using:
mount -o remount,rw /system
and when done, remount it as read-only:
mount -o remount,ro /system
adb disable-verity
adb reboot
adb root
adb remount
This works for me, and is the simplest solution.
On my Samsung galaxy mini S5570 (after got root on cellphone):
Fist, as root, I ran:
systemctl start adb
as a normal user:
adb shell
su
Grant root permissions on touch screen
mount
list all mount points that we have and we can see, in my case, that /dev/stl12 was mounted on /system as ro (ready only), so we just need do:
mount -o rw,remount /dev/stl12 /system
Try the following on the command prompt:
>adb remount
>adb push framework-res_old.apk /system/framework-res.apk
Here is what worked for me. I was running an emulated Android 7.1.1 (Nougat) device.
On a terminal, I hit the following command. One thing to be noticed is the -writable-system flag
./emulator -writable-system -avd Nexus_6_API_25 -partition-size 280
On another tab
./adb shell
su
mount -o rw,remount -t ext4 /dev/block/vda /system
All the changes that you do on the /system contents will survive a restart.
I checked with emulator and following worked.
adb reboot
adb root && adb remount && adb push ~/Desktop/hosts /system/etc/hosts
As mentioned above as well, execute second step in single shot.
Open terminal emulator on the phone:
then
adb shell
after that daemon is started
su
mount -o rw,remount /mnt/sdcard
then the read only is converted into the read-Write.
Sometimes you get the error because the destination location in phone are not exist. For example, some android phone external storage location is /storage/emulated/legacy instead of /storage/emulated/0.
mount -o rw,remount /dev/stl12 /system
works for me
This worked for me
#Mount as ReadOnly
su -c "mount -o rw,remount /system"
# Change Permission for file
su -c "chmod 777 /system/build.prop"
#Edit the file to add the property
su -c "busybox vi /system/build.prop"
# Add now
service.adb.tcp.port=5678
# Reset old permissions
su -c "chmod 644 /system/build.prop"
# Mount as readonly again once done
su -c "mount -o ro,remount /system"
I found this article from google, and thought I'd add the steps necessary on a Sony Xperia Z (4.2.2).
The Sony has a watchdog process which detects when you've changed ro to rw on / and /system (these are the only ones I was trying to modify) and possibly others.
The following was what I ran to perform the changes I was trying to achieve. I pasted these into a window, because removing the execute bit from /sbin/ric needs to be done quickly in order to stop it restarting itself. (I tried stop ric; this doesn't work - although it worked on a previous version of android on the phone).
pkill -9 ric; mount -o rw,remount -t rootfs /
chmod 640 /sbin/ric
mount -o rw,remount /system
I modified the hosts file here, so this is the place you make the changes you need to the filesystem. To leave things the way we found them, do this:
mount -o ro,remount /system
chmod 750 /sbin/ric
mount -o ro,remount -t rootfs /
At which point ric should automatically restart. (It restarted for me automatically.)
Adding a little bit more to Jan Bergström's answer: Because Android is a Linux based system, and the path in Linux contains forward slashes(../), while using push command, use "/" to define destination path in the Android device.
For Example, the command goes: adb push C:\Users\admin\Desktop\1.JPG sdcard/pictures/
Notice that here, back slashes are used to define source path of the file to be pushed from windows PC and forward slashes are used to define destination path because Android is a Linux based system. You don't have to act as a root to use this command and also, it works perfectly fine on production devices.
Thanks, Sérgio, for "mount" command without parameters idea.
I'd need to made adb push into /data/data/com.my.app/lib for some test issue, and get "Read-only filesystem" message.
ls command shows me:
root#android:/ # ls -l /data/data/com.my.app/
drwxrwx--x u0_a98 u0_a98 2016-05-06 09:16 cache
drwxrwx--x u0_a98 u0_a98 2016-05-06 09:04 files
lrwxrwxrwx system system 2016-05-06 11:43 lib -> /mnt/asec/com.my.app-1/lib
So, it's understood, that "lib" directory is separated from other application directories.
Command
mount -o rw,remount /mnt/asec
didn't resolve "r/o fs" issue, it wants device parameter before directory parameter.
"df" command didn't help also, but shows that my /mnt/asec/com.my.app-1 directory is at the separate mount point.
Then I looks by mount and voila!
root#android:/ # mount
.........
/dev/block/dm-4 /mnt/asec/com.my.app-1 ext4 ro,dirsync,relatime 0 0
Next steps are already described upwards: remount to RW, push and remount back to RO.
it sames that must extract and repack initrc.img and edit init file with the code of mount /system
Copy files to the SD-card?
Well, I assume you like to copy data to the Sd-card from the developers computer? You might have rooted the devise and made the area you address available?) I had about the same problem to upload data files for my application(Android Studio 1.3.2 in Win7), but.
First the adb command-shell has to be found in th path:
PATH=%PATH%;C:\Users\XXXXX\AppData\Local\Android\sdk\platform-tools (the folder AppData is hidden, so you have to set the folder setup not hiding concealed files and folder to find it, Path works regardless)
You have to spell the folder path right or you get a read-only error message, most likely it must start with /sdcard or it is read only area. As soon as I did no problem pushing the file to the emulator.
So for instance the the adb command can look like this:
adb push C:\testdata\t.txt /sdcard/download/t.txt
If there's a failure in copying the read-only file you can try locating the original file in the root directory and modify it with a root text editor (preferably) RB text editor, it comes with ROM Toolbox app.
Try this in a Terminal Emulator as root:
restorecon -v -R /data/media
In my case I was using the command adb push ~/Desktop/file.txt ~/sdcard/
I changed it to ~/Desktop/file.txt /sdcard/ and then it worked.
Make sure to disconnect and reconnect the phone.
As chen-xing mentioned the simplest way is:
adb reboot
But for me I had to change my settings first:
Settings → Developer options → Root access
Make sure ADB has Root access:
I just only needed this:
su -c "mount -o rw,remount /system"
Working on a root script for the Nexus 4 with the latest stock rom .img for google (occam) and I have the following code snippet:
./adb wait-for-device
echo "remounting system"
./adb shell "mount -o remount,rw /system"
./adb push su /system/bin/
echo "pushing super user"
./adb push Superuser.apk /system/app/
echo "pushing busybox"
./adb push busybox /system/xbin/
./adb shell "chmod 06755 /system/bin/su"
./adb shell "chmod 0644 /system/app/Superuser.apk"
./adb shell "chmod 04755 /system/xbin/busybox"
./adb shell "cd /system/xbin"
./adb shell "busybox --install /system/xbin/"
I keep getting the error
mount: Operation not permitted
failed to copy 'su' to '/system/bin//su': Read-only file system
pushing super user
failed to copy 'Superuser.apk' to '/system/app//Superuser.apk': Read-only file system
pushing busybox
failed to copy 'busybox' to '/system/xbin//busybox': Read-only file system
Unable to chmod /system/bin/su: No such file or directory
Unable to chmod /system/app/Superuser.apk: No such file or directory
Unable to chmod /system/xbin/busybox: No such file or directory
/system/bin/sh: busybox: not found
I've tried using multiple methods of obtaining r/w access, but nothing seems to be working. I have to automate this process due to the fact that other people will use the script so it needs to be automation friendly, but I just can't figure this out.
I've also tried the
#su
#mount
#mount | grep system
followed by inputting the partition with the system mount and changing it to r/w access, but that also hasn't worked.
Really frustrated at this point. Can anyone help?
It gives the error because you aren't root. The system partition is mounted read-only. You can try to push the binary to /data/local/tmp. Then you can make su executable and eventual run it. But it doesn't mean you can have root. To become root you need to push an exploit like psneuter to /data/local/tmp and run it. It crashes the shell and reopen a new one with root rights. Then you can remount the system-partition read-write and install su.
Try the commands below
adb shell "su -c mount -o remount,rw /system"
adb shell "su -c chmod 06755 /system/bin/su"
and so on.
I recently rooted my Droid X and everything seems to be working perfectly. I made some changes to build.prop and when I do adb push build.prop /system/ I get the following error: failed to copy 'c:\build.prop' to '/system//build.prop': Read-only file system.
How can I fix this?
Not all phones and versions of android have things mounted the same.
Limiting options when remounting would be best.
Simply remount as rw (Read/Write):
# mount -o rw,remount /system
Once you are done making changes, remount to ro (read-only):
# mount -o ro,remount /system
adb remount
works for me and seems to be the simplest solution.
While I know the question is about the real device, in case someone got here with a similar issue in the emulator, with whatever tools are the latest as of Feb, 2017, the emulator needs to be launched from the command line with:
-writable-system
For anything to be writable to the /system. Without this flag no combination of remount or mount will allow one to write to /system.
After the emulator is launched with that flag, a single adb remount after adb root is sufficient to get permissions to push to /system.
Here's an example of the command line I use to run my emulator:
./emulator -writable-system -avd Nexus_5_API_25 -no-snapshot-load -qemu
The value for the -avd flags comes from:
./emulator -list-avds
Got this off an Android forum where I asked the same question. Hope this helps somebody else.
On a terminal emulator on the phone:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
Then on the cmd prompt, do the adb push
I think the safest way is remounting the /system as read-write, using:
mount -o remount,rw /system
and when done, remount it as read-only:
mount -o remount,ro /system
adb disable-verity
adb reboot
adb root
adb remount
This works for me, and is the simplest solution.
On my Samsung galaxy mini S5570 (after got root on cellphone):
Fist, as root, I ran:
systemctl start adb
as a normal user:
adb shell
su
Grant root permissions on touch screen
mount
list all mount points that we have and we can see, in my case, that /dev/stl12 was mounted on /system as ro (ready only), so we just need do:
mount -o rw,remount /dev/stl12 /system
Try the following on the command prompt:
>adb remount
>adb push framework-res_old.apk /system/framework-res.apk
Here is what worked for me. I was running an emulated Android 7.1.1 (Nougat) device.
On a terminal, I hit the following command. One thing to be noticed is the -writable-system flag
./emulator -writable-system -avd Nexus_6_API_25 -partition-size 280
On another tab
./adb shell
su
mount -o rw,remount -t ext4 /dev/block/vda /system
All the changes that you do on the /system contents will survive a restart.
I checked with emulator and following worked.
adb reboot
adb root && adb remount && adb push ~/Desktop/hosts /system/etc/hosts
As mentioned above as well, execute second step in single shot.
Open terminal emulator on the phone:
then
adb shell
after that daemon is started
su
mount -o rw,remount /mnt/sdcard
then the read only is converted into the read-Write.
Sometimes you get the error because the destination location in phone are not exist. For example, some android phone external storage location is /storage/emulated/legacy instead of /storage/emulated/0.
mount -o rw,remount /dev/stl12 /system
works for me
This worked for me
#Mount as ReadOnly
su -c "mount -o rw,remount /system"
# Change Permission for file
su -c "chmod 777 /system/build.prop"
#Edit the file to add the property
su -c "busybox vi /system/build.prop"
# Add now
service.adb.tcp.port=5678
# Reset old permissions
su -c "chmod 644 /system/build.prop"
# Mount as readonly again once done
su -c "mount -o ro,remount /system"
I found this article from google, and thought I'd add the steps necessary on a Sony Xperia Z (4.2.2).
The Sony has a watchdog process which detects when you've changed ro to rw on / and /system (these are the only ones I was trying to modify) and possibly others.
The following was what I ran to perform the changes I was trying to achieve. I pasted these into a window, because removing the execute bit from /sbin/ric needs to be done quickly in order to stop it restarting itself. (I tried stop ric; this doesn't work - although it worked on a previous version of android on the phone).
pkill -9 ric; mount -o rw,remount -t rootfs /
chmod 640 /sbin/ric
mount -o rw,remount /system
I modified the hosts file here, so this is the place you make the changes you need to the filesystem. To leave things the way we found them, do this:
mount -o ro,remount /system
chmod 750 /sbin/ric
mount -o ro,remount -t rootfs /
At which point ric should automatically restart. (It restarted for me automatically.)
Adding a little bit more to Jan Bergström's answer: Because Android is a Linux based system, and the path in Linux contains forward slashes(../), while using push command, use "/" to define destination path in the Android device.
For Example, the command goes: adb push C:\Users\admin\Desktop\1.JPG sdcard/pictures/
Notice that here, back slashes are used to define source path of the file to be pushed from windows PC and forward slashes are used to define destination path because Android is a Linux based system. You don't have to act as a root to use this command and also, it works perfectly fine on production devices.
Thanks, Sérgio, for "mount" command without parameters idea.
I'd need to made adb push into /data/data/com.my.app/lib for some test issue, and get "Read-only filesystem" message.
ls command shows me:
root#android:/ # ls -l /data/data/com.my.app/
drwxrwx--x u0_a98 u0_a98 2016-05-06 09:16 cache
drwxrwx--x u0_a98 u0_a98 2016-05-06 09:04 files
lrwxrwxrwx system system 2016-05-06 11:43 lib -> /mnt/asec/com.my.app-1/lib
So, it's understood, that "lib" directory is separated from other application directories.
Command
mount -o rw,remount /mnt/asec
didn't resolve "r/o fs" issue, it wants device parameter before directory parameter.
"df" command didn't help also, but shows that my /mnt/asec/com.my.app-1 directory is at the separate mount point.
Then I looks by mount and voila!
root#android:/ # mount
.........
/dev/block/dm-4 /mnt/asec/com.my.app-1 ext4 ro,dirsync,relatime 0 0
Next steps are already described upwards: remount to RW, push and remount back to RO.
it sames that must extract and repack initrc.img and edit init file with the code of mount /system
Copy files to the SD-card?
Well, I assume you like to copy data to the Sd-card from the developers computer? You might have rooted the devise and made the area you address available?) I had about the same problem to upload data files for my application(Android Studio 1.3.2 in Win7), but.
First the adb command-shell has to be found in th path:
PATH=%PATH%;C:\Users\XXXXX\AppData\Local\Android\sdk\platform-tools (the folder AppData is hidden, so you have to set the folder setup not hiding concealed files and folder to find it, Path works regardless)
You have to spell the folder path right or you get a read-only error message, most likely it must start with /sdcard or it is read only area. As soon as I did no problem pushing the file to the emulator.
So for instance the the adb command can look like this:
adb push C:\testdata\t.txt /sdcard/download/t.txt
If there's a failure in copying the read-only file you can try locating the original file in the root directory and modify it with a root text editor (preferably) RB text editor, it comes with ROM Toolbox app.
Try this in a Terminal Emulator as root:
restorecon -v -R /data/media
In my case I was using the command adb push ~/Desktop/file.txt ~/sdcard/
I changed it to ~/Desktop/file.txt /sdcard/ and then it worked.
Make sure to disconnect and reconnect the phone.
As chen-xing mentioned the simplest way is:
adb reboot
But for me I had to change my settings first:
Settings → Developer options → Root access
Make sure ADB has Root access:
I just only needed this:
su -c "mount -o rw,remount /system"