2014-09-26

Unlocking and Rooting Your Nexus Under Kali Linux

Unlocking and Rooting Your Nexus Under Kali Linux

CREDITS: This whole post was lifted from nethunter.com (a.k.a. Kali NetHunter)

Before flashing the Kali NetHunter image to your Nexus device, it must first be unlocked and rooted. Note that unlocking your device will result in all of your data being deleted so ensure you have made a backup. Begin by installing the google-nexus-tools package on your Kali Linux system:


1
root@kali:~# apt-get update && apt-get -y install google-nexus-tools

Connect your Nexus to Kali with a USB cable. You will be prompted to allow USB debugging from the computer as shown below. Tap ‘OK’ to allow the connection.
On your Kali system, use the nexus-adb command to verify that your Nexus has been successfully attached.


1
2
3
root@kali:~# nexus-adb devices
List of devices attached
0a6088af        device

Download the correct TWRP recovery image for your Nexus device:
Next, we require the correct files needed to root the device:
In this example, we are flashing a Nexus 7 2013 LTE device so we download the necessary files for our device and unzip the CF-Auto-Root archive.


1
2
3
root@kali:~# wget -q -O twrp-recovery.img http://techerrata.com/file/twrp2/deb/openrecovery-twrp-2.8.0.1-deb.img
root@kali:~# wget -q -O cf-auto-root.zip http://download.chainfire.eu/361/CF-Root1/CF-Auto-Root-deb-razorg-nexus7.zip?retrieve_file=1
root@kali:~# unzip cf-auto-root.zip

With everything in place, we can now proceed to unlock the Nexus, install a new recovery, and root the device. First, reboot to the bootloader:


1
root@kali:~# nexus-adb reboot bootloader

Once the device has booted to the bootloader, we can unlock it with the command below. You will be prompted to confirm the unlock on the Nexus device itself. Use the volume button to select Yes and press the Power button to confirm the unlock.


1
2
3
4
5
6
7
8
9
root@kali:~# nexus-fastboot oem unlock
(bootloader) Unlocking bootloader...
(bootloader) erasing userdata...
(bootloader) erasing userdata done
(bootloader) erasing cache...
(bootloader) erasing cache done
(bootloader) Unlocking bootloader done!
OKAY [ 80.961s]
finished. total time: 80.961s

With the Nexus still in bootloader mode, we can flash the TWRP recovery downloaded previously:


1
2
3
4
5
6
root@kali:~# nexus-fastboot flash recovery openrecovery-twrp-2.8.0.1-deb.img
sending 'recovery' (7878 KB)...
OKAY [  0.673s]
writing 'recovery'...
OKAY [  0.302s]
finished. total time: 0.975s

The final step is to actually root the Nexus by making the ‘root-linux.sh’ script executable and then running it:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
root@kali:~# chmod 755 root-linux.sh
root@kali:~# ./root-linux.sh

----- CF-Auto-Root-deb-razorg-nexus7 -----

Please make sure your device is in bootloader/fastboot mode before continuing.

***WARNING*** ALL YOUR DATA *MAY* BE WIPED ! ***WARNING***

We are going to run the OEM UNLOCK command on your device. If your device
was not previously unlocked, this will wipe all your data !

After the unlock, CF-Auto-Root will boot. You should see a big red Android
on your device's screen.

You may need to enter your administrator password to continue.

Press Ctrl+C to cancel !

Press ENTER to continue

... INFOThe bootloader is already unlocked!
OKAY
downloading 'boot.img'... OKAY
booting... OKAY

It may take a minute or so for the red Android to appear. If it doesn't show up
at all, there may be a problem.

Press ENTER to continue

After your Nexus reboots, re-enable developer mode as shown above in order to proceed.

Install BusyBox Free Stephen (Stericson)

The first application to install once rooted is Busybox Free (Stephen Sericson). The NetHunter image will fail to function without a proper installation of this app. Once downloaded from the App store, open up BusyBox and grant it root privileges. Wait until the “gathering information” stage completes, and press “install”. Exit the Busybox app.

Install the TWRP Boot Manager Application

To ease the process of booting your Nexus into fastboot and recovery mode (normally done by powering down the Nexus, then booting it by pressing both the power button and volume down), we can install the TWRP boot manager application through the Google play store. This will allow us to boot into recovery mode with a single press of the touchscreen. Your Nexus device is now successfully unlocked and rooted,