How to get adb remount to work? - android

I'm attempting to remove certain files from the SD image mounted on the emulator.
NDUNN-PC ~
$ adb devices
List of devices attached
emulator-5554 device
NDUNN-PC ~
$ adb shell rm -f /sdcard/maps/*
rm failed for -f, Read-only file system
NDUNN-PC ~
$ adb remount
remount succeeded
NDUNN-PC ~
$ adb shell rm -f /sdcard/maps/*
rm failed for -f, Read-only file system
From all the docs I've read, remount is supposed to toggle between read-write/read-only permissions. But that doesn't seem to work in this case. Any idea what's wrong? Using Windows XP, emulator is running Android SDK 1.6 (with Google Maps APIs).

Removing the -f command from rm made it work. Weird.

Related

how to wipe cache android from adb terminal?

I'm using an android system builded with yocto and I do often the updates of the apps with adb from linux, but after a certain quantity of updates the partition /dev/block/mmcblk2p3 remain full, and I can't continue to do others updates.
How can I wipe the cache or clean it. using adb commands?
you can try adb shell su -c "rm -rf /data/data/<app's package>/cache/*"
if your application is compiled with a debug key, you can also use run-as command in adb's shell. So it would look like this: adb shell run-as <app's package> rm -rf /data/data/<app's package>/cache/* This method does not require root.
or below requires root
rm -r /data/dalvik-cache
rm -r /cache/dalvik-cache
adb shell run-as <app's package> rm -rf /data/data/<app's package>/cache/*
I resolved the my problem.
before sending the update files you need to kill the app process.
killall my_app_name_process
then
push files like this
adb push "my_app_name_process" /my_path/my_app_name_process
adb shell pm clear com.my_app.vow

How Do I Make System Writeable in Android Studio Emulator?

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

Android Run script in ADB shell

I am trying to fallow this tutorial in order to install SSL certificate on Android emulator.
I need to start the emulator from command line, so I run
emulator -avd myDevice -http-proxy myIp:8888
After device is started I want to copy my certificate file from PC to the device, so I run those commands
mount -o remount,rw /system
cp /sdcard/5ed36f99.0 /system/etc/security/cacerts/
cd /system/etc/security/cacerts/
chmod 644 5ed36f99.0
I bundle them all together using this suggestion
The final command looks like this:
adb shell su -c 'mount -o remount,rw /system; cp /sdcard/5ed36f99.0 /system/etc/security/cacerts/; cd /system/etc/security/cacerts/; chmod 644 5ed36f99.0'
But I am getting an error:
su: invalid uid/gid '-c'
If I do it from the shell it works, but then when I restart the emulator it restore the system to previous state without saving my changes.
How can I solve those two problems?

Attempting to gain r/w access to android /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.

Why do I get a "sqlite3: not found" error on a rooted Nexus One when I try to open a database using the adb shell?

# sqlite3 /data/data/com.moodme.android/databases/moodme
sqlite3 /data/data/com.moodme.android/databases/moodme
sqlite3: not found
As an alternative (may not be secure or even good idea though) you can always upload the sqlite3 binary to /system/bin this worked for me:
First lets mount /system/ to allow read/write (rw)
$ adb shell
$ su
# mount -o remount,rw /system
in another terminal change directory (cd) to where sqlite3 is and lets push it
$ ls
sqlite3
$ adb push sqlite3 /sdcard/
Now back to the other shell lets copy and change permissions of the binary
# cat /sdcard/sqlite3 > /system/bin/sqlite3
# chmod 4755 /system/bin/sqlite3
Now lets mount back /system/ as read only (ro)
# mount -o remount,ro /system
And now we can use sqlite3 from shell:
# sqlite3 /data/data/com.telly/databases/fun.db
SQLite version 3.7.4
Enter ".help" for instructions
sqlite> .tables
android_metadata lulz
Note: I'm using the sqlite3 binary that comes with "SuperOneClickv1.6.5-ShortFuse"
You can always pull sqlite3 binary from emulator:
Start an emulator and then from a terminal
$ adb pull /system/xbin/sqlite3
If you are lazy like me you can download one right here for ICS or before or for Jelly Bean and later here
Make sure to use the proper one for your Android version as you may get eloc_library[1306]: 14446 cannot locate 'sqlite3_enable_load_extension'... or similar errors on execute
On the Android emulator, sqlite3 is in /system/xbin. There is no /system/xbin on a Nexus One (Android 2.2). Hence, I suspect that sqlite3 is not installed on the Nexus One.
From the answer of evelio, I had problem to push the sqlite3 file to /system/bin. So, instead, I have pushed it to the /sdcard.
In this thread I found the right Solution (answer of Kila):
How can I install sqlite3 on rooted NexusOne runs Gingerbread
$ adb push sqlite3 /sdcard/
$ adb shell
$ su
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
# dd if=/sdcard/sqlite3 of=/system/bin/sqlite3
# chmod 4755 /system/bin/sqlite3
# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system
It works on my Samsung Galaxy S II with 2.3.3.
To install sqlite3 on NON-ROOTED devices, here is a way that has been proved working on my Galaxy S3, FYR.
$ adb -e pull /system/xbin/sqlite3 # get sqlite3 binary from emulator with the same CPU arch.
$ adb -d push sqlite3 /mnt/sdcard # push it
$ adb -d shell
$ run-as <PACKAGE_NAME> # run as your app, which should be debuggable.
$ cd databases; pwd
/data/data/<PACKAGE_NAME>/databases
$ cat /mnt/sdcard/sqlite3 > sqlite3 # copy it to internal storage directory
$ ls -l sqlite3
-rw-rw-rw- u0_a138 u0_a138 36860 2014-03-26 06:37 sqlite3
$ chmod 777 sqlite3 # change mode bits, to be executable
$ ./sqlite3 # now it works on your NON-ROOTED device
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
On the Nexus 4 do the following :
adb shell
$ su
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
# dd if=/sdcard/sqlite3 of=/system/xbin/sqlite3
# chmod 777 /system/xbin/sqlite3
# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system
Notice the folder is /system/xbin and the chmod is 777
Some more information that may help someone about this issue
For the people who wonder where to get a working sqilte3 file binary to copy:
You can use the emulator to get a working binary. You must before check if your build is based on _86, _64, or ARM and replicate this image or you may get an incompatible version that will cause an err.
Checking which version is your android device
https://www.quora.com/How-can-I-check-whether-my-Android-phone-is-32-bit-or-64-bit
Building ARM in android studio
Android Studio - How Can I Make an AVD With ARM Instead of HAXM?
Then, use the notes below to move files between your machine and back to the android device.
Making adb writable
Android Emulator sdcard push error: Read-only file system
Copying files from adb to local device machine
How to copy selected files from Android with adb pull
On a rooted device nexus 4 these links with the instruction on this page worked. Hope it helps someone. The key is you need to mount to get writing permission in the device via adb.

Categories

Resources