Search

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

Contents[Hide]

dropcap-android-rooted

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

nexus4-front

But most of the guides you get are using some tools running under Windows.

Obviously, you can do the same from an Ubuntu workstation, but all the steps are not trivial.

So, this article will explain all the steps needed to :
 * Setup udev to properly recognise your Nexus 4
 * OEM unlock it
 * Install TWRP custom Recovery
 * Root the phone
 * Enable USB Debugging mode

 

The complete procedure has been tested with a Google Nexus 4 running Jelly Bean 4.2.2 or Kitkat 4.4.2 from a Ubuntu Precise LTS 12.04 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 4

To be able to detect the Nexus 4 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

/etc/udev/rules.d/99-android.rules

# Google Nexus 4 16 Gb
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee1", MODE="0666", OWNER="your-login" # MTP media (multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0666", OWNER="your-login" # MTP media with USB debug on(multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee5", MODE="0666", OWNER="your-login" # PTP media (camera)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee6", MODE="0666", OWNER="your-login" # PTP media with USB debug on (camera)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0666", OWNER="your-login" # Bootloader
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d001", MODE="0666", OWNER="your-login" # Recovery

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
...
OKAY [108.281s]
finished. total time: 108.281s

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.  

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

You can now switch off your phone.

3. Install TWRP recovery

android-twrp22-mainTWRP is a new generation of recovery, which main advantage over ClockworkMod Recovery 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 4 is available from TeamWin Recovery Project site.

The phone being still connected, boot into bootloader mode by holding Vol Down and Power till the bootloader menu appears.

We can now flash TWRP recovery into the Nexus 4 phone :

# wget http://techerrata.com/file/twrp2/mako/openrecovery-twrp-2.6.3.3-mako.img
# sudo fastboot flash recovery openrecovery-twrp-2.6.3.3-mako.img
sending 'recovery' (8294 KB)...
OKAY [ 0.520s]
writing 'recovery'...
OKAY [ 0.424s]
finished. total time: 0.945s

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

From bootloader menu, select Recovery mode with Vol down and hit Power.

You will reboot and enter TWRP Recovery.

4. Protect TWRP Recovery

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 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 broken. We can reboot.

From TWRP Recovery, select menu Reboot / System.

5. Flash SuperSU

android-icon-supersuYou 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.80.

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

From TWRP recovery, select menu Advanced / ADB Sideload.

# sudo adb devices
List of devices attached
xxxxxxxxxxxxxxxx sideload
# wget wget -O supersu.zip http://download.chainfire.eu/370/SuperSU/UPDATE-SuperSU-v1.80.zip?retrieve_file=1
# sudo adb push supersu.zip /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 supersu.zip
  4. confirm the operation

nexus7-twrp-superuser

You're done, your Nexus 4 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 Developer options

From Jelly Bean 4.2 onward, to enable USB debugging, you need to :

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

This will enable the Developer Settings where you can enable USB debugging.

7. Allow ADB trusted connexion

When you'll connect your Nexus 4 to your Ubuntu workstation, 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.

8. After rooting tweaks

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

 

You now have a fully rooted Nexus 4 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