Monday, April 22, 2013

[How to] Root your Android device in Linux

How to root your Android device if you use Linux

¿De qué está hablando? Versión en español

You can adapt this tutorial to your device.

Introduction and motivation


When I was looking for a tutorial that will show me how to root my device in Linux I didn't find a post that will show me exactly how it was going to be, that's why I decided to do this post.

I have a HTC Desire C, which has Ice Cream Sandwich (Android 4.0.3).

First steps


Usually if you bought your device in a retail store, your "Bootloader" should be blocked. The Bootloader is what allows you to install new operating systems in your Android device.

For any HTC device, you need to follow the tutorial in the developer website of HTC. The tutorial explains how to unlock the Bootloader in Windows actually, so I'm going to show you how to do it with your Linux machine:

Go to the HTC site: http://www.htcdev.com and choose "Unlock Bootloader".


After you clicked in "Get Started" you will see a list of devices that are supported. If your device isn't supported you can choose the "All Other Supported Models" option.
Note: you need to create an account in HTCdev, you will receive a mail afterwards with a binary that you will need to unlock the Bootloader. Also you need to accept some conditions.

Now we can see the tutorial made by HTC. Basically we are going to do the same thing but in Linux!! (yeah awesome)
  1. Remove the battery and before you turn ON your device again you need to press the Volume Down Key and then the Power Button. Hold them until your device boots again.
  2. You will see a different screen, and some options will be displayed: "Fastboot", "Recovery", "Factory Reset" and "Simlock". To choose an option you need to use the Volume Keys.
  3. Choose "Fastboot" and press the Power Button.
  4. Plug in your device to your computer. You will see that the title "FASTBOOT" will change to "FASTBOOT USB".

Download the Android tools (adb, fastboot)


For the Ubuntu users: with all the developing that is happening with Ubuntu Touch the "Phablet" team released a PPA in order to download and install adb and fastboot (if your release doesn't have them in the default packages). Just run the following commands:

sudo add-apt-repository ppa:phablet-team/tools
sudo apt-get update
sudo apt-get install android-tools-adb android-tools-fastboot

If you don't use Ubuntu you need to search for the tools in the Google website. Again maybe your distro has uploaded the tools to your packages.

Unlock the Bootloader


Once you have fastboot installed, the next step is to use this command:

sudo fastboot oem get_identifier_token

This will generate a token and the output must look like this:


Then in the tutorial of HTCdev you need to copy (Ctrl + Shift + C in the Terminal) and paste this token in the box of the website.


After you hit the "Submit" button you will receive a mail with a binary that you will execute to unlock the Bootloader.



After you received the mail, you will see a link with the rest of the instructions. Download the attached file "Unlock_code.bin" and put it in a strategic place, "~" (<- your home) seems good to me. Again from a Terminal you use this command:

sudo fastboot flash unlocktoken Unlock_code.bin


Then in your device you will see the following screen. It will ask you if you are sure of what you are doing. After you select "Yes" your phone will have its Bootloader unlocked.

Note: if you want to lock the Bootloader again, just use:
 
sudo fastboot oem lock

Downloading the super user


The next step is to download the super user, this little program will give you all the privileges in your Android device, that way you can do whatever you want with your phone. For example you can erase all the apps that you don't want but that are installed by default. Or you can install a new ROM into your phone.

You need to go to this website and download the file "Superboot r1".

Put the file where you want and extract it, you need to give the permission to execute the script:

chmod +x install-superboot-linux.sh

Then you need to plug in your phone, again in "FASTBOOT USB" mode.
You can do that without removing the battery with abd. But your device has to have the USB Debugging option activated. Go to "Settings">"Developer options"



sudo adb reboot-bootloader


Install the super user


Once your phone is connected and after you are in the good folder in your terminal, you will just need to run the script:

sudo ./install-superboot-linux.sh

Once you did that your phone will restart and the super user (SU) will be installed.

Did you like this post? Here you can see what I'm going to write about in this blog (for the moment). Don't forget to add me to your G+ circles or follow me on Twitter: @RobertoXMed

2 comments:

  1. does the root part also work with an htc desire x?

    ReplyDelete
  2. how long should it take to reboot at the end? I've been waiting for a few minutes and finally just pulled the battery because the power button did not work. My device (MyTouch 4g) finally rebooted but superuser was not installed. Any ideas where I went wrong?

    ReplyDelete