reRoot Android using GNU/Linux, SDK tools and TWRP

  • You just updated your Android device with last OTA update.

  • You lost root and your custom recovery mode is broken.

  • You want to be root and have your custom recovery (TRWP) working again.

  • You like to understand how things work and not to use all-in-one tools that do stuff that you have no idea about.

  • And of course, you are a GNU/Linux user.

  • Well, let me tell you that you're in the good place :)

    But before, you understand that rooting your device is always a little bit risky. So, if you go further, do it at your own risk.

0) Prerequisites

  • Android device is connected to your PC with a USB cable.
  • USB debugging is set to ON.
  • Bootloader is already unlocked
  • The proper udev rules that allow the system to detect your device is setup. Here is mine (/etc/udev/rules.d/51-android.rules) :
# a very permissive udev rule that will work for all your devices
SUBSYSTEM=="usb", MODE="0666"
~/bin/android-sdk-linux/platform-tools$ ./adb devices # test
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
015d21d938081602        device # < if a device appears like this, it works!

1) Download binaries

# In this example I download last TWRP image for my nexus 5
~/Downloads$ wget
~/Downloads$ wget

2) Enter bootloader mode

~/bin/android-sdk-linux/platform-tools$ ./adb reboot bootloader
~/bin/android-sdk-linux/platform-tools$ # If the daemon was already running, you have no output for this command.

3) Flash 'TWRP' as the custom recovery image

While being in bootloader, you will now use fastboot commands to flash the new custom recovery image.

~/bin/android-sdk-linux/platform-tools$ ./fastboot flash recovery ~/Downloads/openrecovery-twrp-
sending 'recovery' (7462 KB)...
OKAY [  0.891s]
writing 'recovery'...
OKAY [  1.762s]
finished. total time: 2.652s

4) Reboot the bootloader

~/bin/android-sdk-linux/platform-tools$ ./fastboot reboot-bootloader
rebooting into bootloader...
OKAY [  0.020s]
finished. total time: 0.020s

At this time, you can boot on your freshly updated TWRP recovery mode.

5) Boot in recovery mode

From the bootloader menu, use the volume buttons of your device to switch into the recovery mode. TWRP should boot just fine....

6) Push 'superuser' to your device

While in recovery mode, adb commands are working fine and so you can push your superuser binary to your device like this :

~/bin/android-sdk-linux/platform-tools$ ./adb push ~/Downloads/ /sdcard/Download/
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
1325 KB/s (1192075 bytes in 0.878s)

7) Install 'superuser'

We're almost there!

  • Go to Install
  • Install

8) Reboot to System

Now, enjoy :)