The definitive guide on hacking the Nexus 4, part 2
This is part 2 of an 8 part series of articles on the Nexus 4. This guide assumes that you have already successfully installed the ADB drivers for the Nexus 4. This guide will describe how to unlock the bootloader, root and install ClockworkMod custom recovery.
Legal disclaimer: We are not responsible for any damage or loss to your device or computer system. Therefore, should you decide to follow these steps, you do so at your own risk and peril and agree to hold us harmless from any damage or loss you may experience. Should you disagree with the foregoing, please do not read any further.
Why do I want to unlock the bootloader of my device?
To avoid any confusion, this has nothing to do with unlocking your phone so that it can work on another carrier (the Nexus 4 is carrier unlocked by default anyways). When we mention unlocking, we mean unlocking the bootloader. This is usually the first step that is required before attempting to do any modification to an Android phone. A bootloader is a piece of software that runs before an operating system. When you turn on your device, the bootloader loads and then it instructs the phone to load the kernel and the Android OS. If the bootloader is locked, it is very difficult (nigh impossible) to install a custom ROM or Kernel. Please note that once you unlock the bootloader, it usually voids your warranty and wipes your device. However, you can always re-lock the bootloader should you need to send it back for repairs. As far as we know, all Android smartphones are shipped with a locked bootloader. The only difference between handsets is how easy the manufacturer allows its users to unlock the bootloader. Google/LG makes it incredibly easy to unlock the bootloader on a Nexus 4. In contrast, Motorola has a reputation for making it very difficult for users to unlock the bootloader on its phone (although they are becoming less stringent). You can read more about Android bootloaders here.
Can I unlock the bootloader without wiping the device?
Sort of. If you unlock the bootloader using traditional methods (i.e. Fastboot, the method that we will use), your device will be wiped. However, there is a relatively new app that will do a quasi-unlock of your bootloader without wiping your device (or requiring Fastboot). It’s free, it requires root and it’s called BootUnlocker for Nexus Devices. In general, a device with an unlocked bootloader is less secure than a device with a locked bootloader (in regards to malware or physical forced extraction of the data in your phone). When you unlock your phone using Fastboot, all of the partitions in the phone are exposed. BootUnlocker exploits a bug in the bootloader to keep the bootloader locked, but modifies a certain partition in order to allow users to install a custom recovery–all without wiping your phone. We won’t be using the BootUnlocker app in our example below, but we wanted to mention that it was an option. You can read more about BootUnlocker here, here and here.
What is Fastboot?
Fastboot is a protocol that allows users to flash a new file system in an Android phone over a USB connection. Typically, when someone mentions fastboot, they are referring to a mode that an Android phone is in. If you turn off your Nexus 4, push and hold volume up, volume down and the power button (all at the same time), you will enter “fastboot mode”. For more information, please read this.
What is root?
Root is the most powerful user in a linux environment. “Root” is to Linux as “Administrator” is to Windows. The primary difference between root and a regular user is that root has more file permissions. Root can read, write or execute certain files that regular users cannot touch or access. Root is all powerful, therefore some Root users have unfortunately developed god complexes.
Why do I want to root my device?
Rooting allows you to install powerful software that otherwise wouldn’t be possible. For example, it allows you to flash custom ROMs, you can make better backups of your phone, you can disable most ads in Android apps (by modifying the HOST file), you can tweak the kernel, the voltages and set the processor speeds for your phone. Rooting your device usually voids your warranty, however you can unroot your device at anytime. For more reasons why you may want to root your device, read this, this and this.
Why do I need a custom recovery, such as ClockworkMod?
Typically, if you intend to install a custom ROM or a kernel, you would do so in the custom recovery. You enter custom recovery mode by entering into fastboot mode and then loading the custom recovery. There are many different custom recoveries (such as TWRP), but ClockworkMod is by far the most popular. That’s what we’ll be using in this tutorial. Android comes with its own recovery method, but you can’t install custom software with it.
What is busybox?
We will also be installing busy box below. Busy box is a set of basic Linux command line tools. The scripts that we will be using are dependent on these commands to work. Android is based on Linux, but it doesn’t come with many of the common Linux commands, such as chmod (change file permissions), wget (download command), cp (copy), mv (move), ls (list contents of a directory), gzip (uncompress archives), etc.
Why aren’t you using WugFresh’s Nexus Toolkit that you made us install in part1?
I hear great things about WugFresh’s GUI toolkit, but I’m used to using mskip’s command line toolkit (as it has been around for years), so I’m just going to go with what I’m familiar with. Feel free to use WugFresh’s toolkit if you like.
Step-by-step guide on how to unlock, root and install a custom recovery on a Nexus 4
1) Download the latest version of the Nexus 4 Toolkit from here. The current version is v.1.3.0 (direct link). Install the Toolkit at the default location (i.e. C:\Google Nexus 4 ToolKit)
2) Download this patch (direct link) and extract it to any folder. Copy all of the extracted files and paste them in this directory “C:\Google Nexus 4 ToolKit\”. We’ll be overwriting 4 files in step 1 with the newer files in the patch. Click “Yes” when Windows asks you if you wish to replace and overwrite the files.
3) Turn off the Nexus 4 and enter Fastboot mode. To enter into Fastboot mode (while the phone is off), push and hold volume up and volume down and the power button (hold all three together) for a few seconds. Once the phone vibrates and you see a little android man, as seen below, you can let go of all 3 buttons. You can tell from the image below that we’re in Fastboot mode and that the bootloader is LOCKED (for now).
4) Now that your phone is in Fastboot mode, you can connect the Nexus 4 to your PC with a mini USB to standard USB cable.
5) Execute Toolkit.exe found in ”C:\Google Nexus 4 ToolKit\”
6) When it asks you to check for an Update, type “No” (it won’t let you update anyways as that’s a paid feature). When it asks for your device version, type “1″ for Android 4.2 (it’s the only option in any event). You should now see the screen below. Type “8” and it will run a script to automatically unlock the bootloader, root, install busy box and a custom recovery.
7) It will now ask you which Superuser method you would like to use. Type “2“ for SuperSU. Afterwards, it will ask you select your choice of Custom Recovery, type “1” for ClockworkMod.
8) Read the warning below. The Toolkit will now attempt to Unlock the bootloader. This will wipe your phone (even the internal SD card). If you agree with this, type “yes” and it will be begin.
9) The following screen should now appear on your phone. Navigate to“Yes” with the volume buttons and select it by pushing the power button. Your phone will now reboot and start Android OS.
10) While your phone is starting, you will see the following in the toolkit. The Toolkit says that it is waiting for you to enable USB debugging. You can skip through the Android OS setup (e.g. Wifi, Google Account, etc.), it’s not necessary at this point. Just go enable USB debugging. If you don’t remember how to enable USB debugging, please see steps 9 to 12 in part 1 here.
11) Once you enable USB debugging, the Toolkit should start running again by itself. It will now attempt to root your device, install busybox and ClockworkMod. Your phone will reboot a few times. You’ll see the following screens.
14) Once the Toolkit is finished installing everything, you should see a SuperSU icon in your app drawer. Congratulations, you should have root now!
Once you’re ready, move on to part 3 to install a custom ROM.