How to copy an apk into /system/ folder using adb? - android

While using android debug bridge remount, it changes the system folder to r/w, but
as soon as the user tries to copy some file using android debug bridge to the system folder it changes to read-only

If the device is not rooted, you cannot copy anything to the System or Data partitions.
With root do the following commands in a command prompt or linux shell and all should be fine:
adb push fileName /data/local/tmp
adb shell
su
mount -o remount, rw /system
cp /data/local/tmp/fileName /system/folderOfYourChoise
chmod 644 (if its an apk and you want the system to use it as a system app)
exit (exits the su shell)
exit (exits the adb shell)
adb reboot (to apply and see changes on the device)

Related

Hosts file for Android emulator

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

how to convert app to system app ?

How do install a *.apk from adb command line?
First I tried to cp the *.apk from /sdcard/backups/apps to /system/app (after rw mounting the file system of course)
I did successfully move it to /system/app but the *apk was not "installed"
I used this code :-
**
adb shell
su
mount -o rw,remount /system
adb shell
su
cd /sdcard
mv com.ogp.gpstoggler-1.apk /system/priv-app
finally after I write
chown 644 /system/priv-app/com.ogp.gpstoggler-1.apk
and press enter the result is
Unable to open /system/priv-app/com.ogp.gpstoggler-1.apk: No such file or direc
tory***
how to fix this ? thank you ?
Instead of using "mv" use "cp" to copy it to system/priv-app folder.
Ensure it is in the priv-app folder using "ls"
use chmod 777 to give it privileges
Ensure it has the correct privileges using "ls -l"
use "adb reboot" to have the system install the application.
Edit
One thing I forgot to note - if you go into the system/priv-app folder and you see that all the other APK's are in their own folders, you might also have to create a folder for your apk.
mkdir system/priv-app/app_name
cp app_name.apk system/priv-app/app_name
cd system/priv-app/app_name
chmod 777 system/priv-app/app_name/app_name.apk
adb reboot

How to push files to sbin folder on the Android device?

I'm not able to turn on recovery mode, just the factory mode.
Communication between PC (Windows) and Android phone works fine over ADB, but the phone is not storing files after reboot.
Script in which I'm trying to transfer certain files ((sd)parted) to /sbin directory:
adb -d shell stop
adb -d shell su -c "mount -o rw,remount rootfs /"
adb -d shell su -c "chmod 0777 /sbin"
echo Copying files
adb push e2fsck /sbin/
adb push mke2fs /sbin/
adb push parted /sbin/
adb push resize2fs /sbin/
adb push sdparted /sbin/
adb push tune2fs /sbin/
echo Rebooting
adb reboot
Why files aren't stored on the device. What went wrong?
I need to repartition the file system, so that's the reason why I need these files.
adb root
... does not work, it get's stuck.
Please help.
You won't be able to. The rootfs in Android gets put into the boot image, which is compressed and expands into a ramdisk by the bootloader on bootup. This has the kernel, init, read-only properties, sbin, etc. If you remount the rootfs as root and write to these locations, your changes won't persist after a reboot. (ie they won't be written to the compressed boot.img)
You could get the AOSP or Cyanogenmod for your device if it is available, and rebuild the whole boot image with your files included, then flash that to your device. Here, you can also modify your partition table. I wouldn't recommend this, unless you really know what you are doing.

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.

adb remount permission denied, but able to access super user in shell -- android

so, i'm trying to push some files to /system on android device (zte)
I've rooted, connected with ADB,
adb remount -> I get permission denied
adb shell su -> I'm able to access shell and create folders etc and edit filesystem
(but in shell I can't copy a file from my computer to device)
Any help please
In case anyone has the same problem in the future:
$ adb shell
$ su
# mount -o rw,remount /system
Both adb remount and adb root don't work on a production build without altering ro.secure, but you can still remount /system by opening a shell, asking for root permissions and typing the mount command.
emulator -writable-system
For people using an Emulator: Another possibility is that you need to start the emulator with -writable-system. That was the only thing that worked for me when using the standard emulator packaged with android studio with a 4.1 image. Check here: https://stackoverflow.com/a/41332316/4962858
Try
adb root
adb remount
to start the adb demon as root and ensure partitions are mounted in read-write mode (the essential part is adb root). After pushing, revoke root permissions again using:
adb unroot
Some newer builds require the following additional adb commands to be run first
adb root
adb disable-verity
adb reboot
Then
adb root
adb remount
you can use:
adb shell su -c "your command here"
only rooted devices with su works.
Start /w Writable System
Using Emulator Images without Google Play
This does not work with production Android images, i.e. ones with Google Play
Use non-Google Play images for root access & writeable system
Start your emulator from a command prompt as a writable system, using its AVD Name (Pixel3a in this example, see AVD Name below to find or change yours. Make sure another emulator instance is not running when using this command):
emulator #Pixel3a -writable-system
(Keep this command handy. You will need to use it any time you want to access your emulator as 'writable'. I use an alias in gitbash to start my emulator from a gitbash terminal, everytime.)
This launches the emulator.
When startup is complete, open another command prompt/terminal (this one is stuck running the emulator) and:
adb root
Result should be:
$ adb root
restarting adbd as root
Then:
adb remount
Result:
$ adb remount
remount succeeded
When you:
adb shell
and:
su
You should now have full root/writable access:
$ adb shell
generic_x86_arm:/ # su
generic_x86_arm:/ #
To add a domain to hosts file
$ cd /etc
$ cp hosts hosts.bak1
$ cat hosts
127.0.0.1 localhost
::1 ip6-localhost
$ echo '10.0.2.2 my.newdomain.com' >> hosts
$ cat hosts
127.0.0.1 localhost
::1 ip6-localhost
10.0.2.2 my.newdomain.com
10.0.2.2 is "localhost" for an Android emulator. It will delegate to your Windows/Mac hosts file & DNS services. Any domain you add to your development machine's hosts file, will work as 10.0.2.2 on your Android Emulator hosts file.
AVD Name
In Android Studio AVD Manager can be launched from menu:
Tools > AVD Manager
If your emulator name has spaces, you can change that by clicking the pencil icon on right hand side.
I named my emulator 'Pixel3a' without spaces for ease of typing.
I rebooted to recovery
then
adb root; adb adb remount system;
worked for me
my recovery is twrp v3.5
Try with an API lvl 28 emulator (Android 9).
I was trying with api lvl 29 and kept getting errors.
#echo off
color 0B
echo =============================================================================
echo.
echo ClockworkMod Recovery for SAMSUNG GALAXY SIII E210L
echo.
echo ClockworkMod Recovery (v6.0.1.2 Touch)
echo.
echo ¡ô¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¡ô
echo ¨U ¨U
echo ¨U SAMSUNG GALAXY SIII E210L ¨U
echo ¡ô¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¡ô
echo.
echo 1) (Settings\Developer options©¥ USB debugging)
echo.
echo 2) CWM SAMSUNG GALAXY SIII E210L
echo.
echo 3) THANK!!!!!!
echo.
echo =============================================================================
echo ARE YOU READY? GO! ¡·¡·¡·
#pause
echo.
echo adb...
adb.exe kill-server
adb.exe wait-for-device
echo wiat¸!
echo.
echo conect...
adb.exe push IMG /data/local/tmp/
adb.exe shell su -c "dd if=/data/local/tmp/GANGSTAR-VEGAS-1.3.0-APK-Andropalace.net.apk of=/mnt/sdcard/Android/GANGSTAR-VEGAS-1.3.0-APK-Andropalace.net.apk
adb.exe shell su -c "rm /data/local/tmp/bootloader.img"
adb.exe shell su -c "rm /data/local/tmp/recovery.img"
echo ===============================================================
echo ClockworkMod Recovery!
echo.
#pause

Categories

Resources