Nexus 5 - Root, Remove Ads & Extend Battery Life under Ubuntu



If you want to root your Google Nexus 5, a lot of stuff is available on the net from different sites and forums.


But most of the guides you get are using some tools running under Windows and focus on a specific goal : root the phone, optimize battery life or tweak usage.

This article explains all the steps needed to :
 * Setup udev to properly recognise your Nexus 5
 * OEM unlock it
 * Install TWRP custom Recovery
 * Root the phone
 * Install an ads blocker
 * Extend its battery life


The complete procedure has been tested with a Google Nexus 5 running Kitkat 4.4.2 from a Ubuntu Saucy 13.10 computer.

As a pre-requisite, you must have latest Android SDK or latest ADB package installed on your computer. An installation guide is available for Ubuntu computers.

You have to understand that rooting your phone is always a little bit risky, even if on Google ones everything is smooth.
So, if you go further, do it at your own risk !

1. Create Udev rule for Nexus 5

To be able to detect the Nexus 5 phone under Ubuntu, first thing is to create the proper udev rules that will allow the system to detect the phone.

These udev rules should be able to handle 4 different cases:

  • phone connected in MTP mode (USB debug on or off)
  • phone connected in PTP mode (USB debug on or off)
  • phone connected in Fastboot mode
  • phone connected in Recovery mode

They will be declared in /etc/udev/rules.d/99-android.rules. If file already exists, just append the content at the end of it.

# sudo gedit /etc/udev/rules.d/99-android.rules


# Google Nexus Products range (including Nexus 5)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", OWNER="your-login"

your-login should be your normal Ubuntu session login.

Once done, udev service has to be restarted.

# sudo service udev restart

2. OEM Unlock your phone

Next step suppose that you have installed latest android-tools package.
If you are using Android SDK, you should be in ./android-sdk-linux/platform-tools directory.
You also have to issue commands from local directory ( fastboot becomes ./fastboot ).

First main step it to unlock your boot loader. This standard process, as a safety feature, will wipe all your data.

If you have already done it before, no need to do it again. You can jump to next step.

To unlock your bootloader, you need to enter bootloader mode by switching off your phone and pressing Vol Down and Power buttons at the same time while restarting it.

Once you get the bootloader screen, if not already done, connect your phone to your computer with a USB cable.

You then have to type this command :

# sudo fastboot oem unlock
sudo fastboot oem unlock
OKAY [145.008s]
finished. total time: 145.008s

Your phone data will be fully erased.
All your data will be lost.

Your phone will ask for a confirmation. Hit the Volume Up button once to select Yes and then the Power button to validate and unlock your Nexus 4.

android-nexus5-oem-unlock  android-nexus5-oem-unlocked

Your screen should go back to bootloader and finally display LOCK STATE – UNLOCKED.

3. Reboot in the Stock ROM

You should now switch off your phone and reboot in the stock ROM till the end of the boot process.

This first reboot is very important as during this first boot the userdata and cache partition will be reformated.

At the end of the boot process, declare your gmail account and if needed wait for a system update notification.

If proposed, update the system. It will reboot into stock recovery, update the stock ROM and reboot it.

4. TWRP recovery

4.1. android-nexus5-twrpInstall it

Now that your phone is unlocked and updated to latest stock ROM, you can install a custom recovery to root it.

TWRP Recovery is a new generation of recovery, which main advantage is to be usable straight from the touch screen.

You don't need anymore to use Volume or Power keys. You can do all the job from the comfort of your touch screen !

Latest version of TWRP recovery image for Nexus 5 is available from TWRP Site.

Switch off your phone and enter bootloader mode again by pressing Vol Down and Power buttons at the same time while restarting it.

You can now flash TWRP recovery :

# wget
# sudo fastboot flash recovery openrecovery-twrp-
sending 'recovery' (13272 KB)...
OKAY [  0.615s]
writing 'recovery'...
OKAY [  1.043s]
finished. total time: 1.658s

After the flash, you need to reboot again in bootloader mode for TWRP Recovery to be recognised and accessible.

# sudo fastboot reboot-bootloader
rebooting into bootloader...
OKAY [ 0.001s]
finished. total time: 0.001s

4.2. Protect it

By default, stock ROM rewrites OEM recovery at every shutdown. That means that at next boot your newly flashed TWRP recovey will be gone !

This removal is done by a specific file named /system/recovery-from-boot.p.

The good news is that you just need to rename that file to block the recovery removal mecanism. We will do it straight from TWRP Recovery.

From bootloader menu, select Recovery mode with Vol down and hit Power. You will reboot and enter TWRP Recovery.

From TWRP Recovery, select menu Mount and tick the option System. The /system filesystem is now mounted.

Go back to main menu and select menu Advanced / File Manager.

Go in /system, select recovery-from-boot.p and rename it to recovery-from-boot.p.bak

The recovery removal process is removed.

When you will update your stock ROM, your custom recovery will surely be erased.
You will then only need to redo the install and protect recovery steps to get back a fully working custom recovery.

5. Root the phone

android-icon-supersuTo root the phone you will have to download latest SuperSU and to flash it on your phone to allow the super user privilege elevation.

At the time of this article the latest file is  SuperSU v1.91.

We will need to download the archive and to copy it to the Nexus 5.

While in TWRP recovery, run these command :

# sudo adb devices
List of devices attached
xxxxxxxxxxxxxxxx sideload
# wget -O
# sudo adb push /sdcard
1322 KB/s (1324669 bytes in 0.977s)

From TWRP recovery follow these steps :

  1. select Install
  2. move thru directory structure to sdcard
  3. select
  4. confirm the operation


You're done, your Nexus 5 is rooted !

From TWRP Recovery, select menu Reboot / System.

Once you've rebooted, you should get the SuperSU icon in your applications list. If not, install it from Google Play.

When you first launch this application, it may ask to upgrade su binary. Accept it and select CWMR/TWRP method.

Your phone will reboot in recovery mode and upgrade su.

6. Enable ADB and Allow Trusted Connexion

android-icon-adbFrom Jelly Bean 4.2 onward, you need to enable Developer Options menu :

  1. go to Settings
  2. select About phone
  3. at the bottom tap 7 times on Build number

This will enable a new menu Settings / Developer options.

From this new menu, you are now able to enable USB debugging option.

You can now connect your phone to your Ubuntu workstation.

When you'll connect your Nexus 5, it will display on the phone a message asking you to allow connexion to your computer as a trusted computer.


Validate the message while selecting the permanent checkbox.

7. After rooting tweaks

Now that your Nexus 5 is fully rooted, you can follow these additional procedures :


You now have a fully rooted Nexus 5 that will be able to give it's maximum during maximum time.

All sorts of tweaks are opened to you !

Hope it helps !

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus