I've got a rooted phone running, have done adb root; adb connect <phone>; adb shell; and I am unable to rm, chmod, chown or in any way rid myself of some files under /storage/sdcard1/path/this_is_to_be_deleted/some_files.foo.
I am also unable to remove them via the file manager or terminal on the phone, even with superuser granted. WTF?
How on earth does root not have rights to rm anything and everything? On all the *nix systems I've used root can rm -rf /*, dd if=/dev/zero of=/dev/sda or any other virtually suicidal thing it wants.
Ok, for some ungodly reason, it was necessary to cd /mnt/media_rw/sdcard1; chown -R media_rw:media_rw *; cd /storage/sdcard1/path; rm -r this_is_to_be_deleted;
Explanations would be welcome!
Doing adb shell is not going to give you root, which is what HappyCactus is trying to say. You have to do:
> adb root
# _
If you see a hash mark, you are root.
If that doesn't work, try this:
> adb shell
$ su
# _
If that still doesn't give you a #, something is going on or your device isn't actually rooted.
Related
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
I am working on building AOSP for nexus 5X. code builds and installs and runs,
but when trying to access adb shell, I couldn't get to su.
I checked and /system/xbin/su is now in su_exec tag, so I modified file_contexts to put su in system tag
shell#bullhead:/ $ which su
/system/xbin/su
shell#bullhead:/ $ ls -Z /system/xbin/su
-rwsr-x--- root shell u:object_r:system_file:s0 su
But still:
shell#bullhead:/ $ su
su: setgid failed: Operation not permitted
I also tried disabling selinux but:
shell#bullhead:/ $ setenforce 0
setenforce: Couldn't set enforcing status to '0': Permission denied
I am out of ideas now. Please help.
adb root with userdebug build doesn't work for me.
to get root, I had to make an eng bui. on this build, adb always lands in root shell.
Thanks #Chris for answer.
I know there are quite a few question like this around but none of them really seems to work for me.
I am writing a program that automatically updates and installs itself, however to install the update it requires user confirmation but I do not want this as the device I will deploy on will never be physically used by anyone. So to try work around this I want to root the device and use a runtime command in the code to get it to just install.
To test this out I want to try it on the (AVD) emulator first however it (obviously) needs to be rooted. So how would i go about this?
I have tried commands in the adb shell (and out of it with the adb shell) like:
mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system
push su /system/xbin/su
chmod 06755 /system
chmod 06755 /system/xbin/su
and a few others I can't find again at this moment but they will always give me errors such as cannot stat 'su' and stuff like that (will edit if i can find the commands and recreate again) or they just don't say anything and it doesn't appear to work.
If it helps i'm using xamarin in visual studio.
When working with android emulators, just do:
adb.exe root - restart adbd with root permissions
adb.exe unroot - restart adbd without root permissions
You can find adb.exe at: android_sdk\platform-tools\
You can confirm if the device is rooted by doing:
adb.exe shell
Inside the shell type: whoami. Then type exit to exit the shell
Example
P:\Android\sdk\platform-tools>adb.exe shell
generic_x86:/ $ whoami
shell
generic_x86:/ $ exit
P:\Android\sdk\platform-tools>adb.exe root
P:\Android\sdk\platform-tools>adb.exe shell
generic_x86:/ # whoami
root
generic_x86:/ # exit
P:\Android\sdk\platform-tools>adb.exe unroot
P:\Android\sdk\platform-tools>adb.exe shell
generic_x86:/ $ whoami
shell
generic_x86:/ $ exit
You can use https://www.genymotion.com/. All devices created are rooted by default. For example start a device then type adb shell command. It will open a rooted shell.
I am unable to pull a the database from the device even after changing the permission. I have a rooted phone.
It used to work. I could pull before. For some unknown reason now I cannot.
The error I receive is
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
Does anybody know why this is happening?
Below is what I did in command window.
C:\users\thupten>adb shell
shell#android:/ $ su
su
root#android:/ # cd /data/data/com.thuptencho.transitbus/databases/
cd /data/data/com.thuptencho.transitbus/databases/
root#android:/data/data/com.thuptencho.transitbus/databases # ls
ls
ttc.db
ttc.db-journal
webview.db
webview.db-journal
webviewCookiesChromium.db
webviewCookiesChromiumPrivate.db
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 755 ttc.db
5 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # chmod 777 ttc.db
7 ttc.db <
root#android:/data/data/com.thuptencho.transitbus/databases # exit
exit
shell#android:/ $ exit
exit
C:\users\thupten>adb pull /data/data/com.thuptencho.transitbus/databases/ttc.db
remote object '/data/data/com.thuptencho.transitbus/databases/ttc.db' does not exist
I using these commands to get data from /data/data folders, no changing permission required
adb kill-server
adb root
I figured it out.
I had to chmod the databases folder as well and then the file.
The problem is that you need permission not just to the file, but also to its parent directories.
(That permission should not be 777 though!)
Rather than trying to change the permission, what you probably want to do is get adb running as root if that is supported, (ie, if you have an engineering build, rather than an aftermarket "rooting" of a secured device) or else use your root access (or the app itself, or the stock run-as command if you have a debug apk) to copy the file of interest somewhere accessible and then adb pull the copy.
My preferred solution was:
Install Chainfire's adbd insecure app
From within the adbd insecure app, select "Enable Insecure adbd"
adb pull /data/data/com.package.name/databases/database.db
Caution - adb insecure means adb is running as root on your device.
for i in `adb shell ls /data/ -1`;do adb pull /data/$i data; done
I have created a script to mount partitions and do some stuff in my Android system. I saved the script as install.sh in the /bin folder of Android.
I want to call the script from ADB, which is itself called from a batch file on Windows, but it needs to be executed as root.
The first solution I tried was to call the script using
adb shell "su -c sh /bin/script.sh"
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
I also tried to call
adb root "sh /bin/script.sh"
but I got the following error
adbd cannot run as root in production builds
I then tried to write
su -c "command"
for all the commands which need a root access in my script, but I have the same problem.
When I run the script I only obtain a root shell and nothing is executed.
If I use the first solution by hand (e.g. I call adb shell su, then my script), it works. However the whole point is to automate the process, so that adb shell can be called from another script.
Do you have any idea of how I could achieve this ?
Thanks !
This works for me:
Create myscript.bat and put into it (note the single quotes around the commands to be executed in superuser mode):
adb shell "su -c 'command1; command2; command3'"
then run myscript.bat from a DOS shell.
Note: it doesn't appear that the the DOS line continuation character (^) works in this situation. In other words, the following doesn't work for me:
adb shell "su -c '^
command1; ^
command2; ^
command3'"
This results in "Syntax error: Unterminated quoted string"
This works :
adb shell echo command which needs root privileges \| su
If you need redirection:
adb shell echo 'echo anytext > /data/data/aforbiddenfolder/file' \| su
For "copying" a local file to an android path needing root privileges (but alocalfile must not contain '):
cat alocalfile | adb shell echo "echo '`cat`' > /data/data/aforbiddenfolder/file" \| su
If you have a better way (even for su versions which don't have -c), I am interested.
This works for me:
adb shell "su -c ./data/local/tcpdump-arm -s 0 -v -w /data/local/appxpress_dump.pcap"
I am not sure if I provided a solution or asked for a better one.
I wanted to run some 200 command in batch mode to be sent to adb
I followed this approach
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
and I saved them in a batch file
This command
adb shell "su -c 'command1; command2; command3'"
will not work beyond a certain max size . It did not work
error: service name too long
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
How do you know that you are given root permissions? I assume you are attempting to execute the script on a device? Has your device been rooted?
You may need to give execute permissions via chmod to the file.
chmod ugo=rwx /bin/script.sh
It appears that I was using a very simple version of su which did not accept the -c argument.
I copied another su which did work. AndyD is totally right though, so I am accepting his answer instead of mine :)