Android Run adb shell as root

Is there a way for me to run Adb shell as root without typing in su? I want to be able to have root access without going into the shell.

If I'm understanding your question correctly, you're asking how to get root access automatically when you run adb shell, so that you don't have to go into the shell and type su to execute a command as root on your phone.

This is controlled by a flag in your boot partition, which most custom ROMs have modified to allow root permission by default. If you get dropped to a $ when you use adb shell then you have two options:

  1. Flash a ROM that includes the modification
  2. Create a custom boot.img and flash it to your phone

Number 2 is actually not that difficult, but it can be somewhat dangerous if you're careless. There is a wiki article here which explains the process and includes a couple of Perl scripts to help you. These instructions assume a Linux/Unix environment. I have personally used these instructions on Fedora Linux and can tell you that they work, but I do not know about other *nix environments like Macs. I also do not know of any similar Windows instructions, but I could try to track some down if you are on Windows. The exact commands will vary somewhat from phone to phone since different devices use different partition tables.

Generally speaking, though, you need to pull your current boot.img from your phone, unpack it, extract the ramdisk, and find the default.prop file. This is a plaintext file, which you need to open in a text editor and then find the line that contains the value ro.secure. If the line says ro.secure=1 then you need to change it to ro.secure=0. After that you can re-pack the ramdisk and boot.img, then flash it to your phone. Once you reboot, you will be greeted with a # prompt whenever you perform adb shell without having to run su.

Alternatively, if you are using a custom ROM but it doesn't have this modification, you can just unzip the ROM and modify the boot.img that is included with it using the above steps. Then you can zip up the ROM with the newly modified boot.img and flash the zip file as you normally would.

This probably goes without saying, but be careful when doing this. Messing with your boot partition can quite easily wreck your phone and force you to recover via HBoot. I would highly recommend testing Fastboot to makes sure you can use extended Fastboot commands and perform a recovery. This varies a bit based on your model, but most phones have some sort of desktop software that can be run to reflash the phone as well.

Published 11 Feb 2011
Read more - asked Feb 11 2011 by Hank - answered Feb 11 2011 by eldarerathis