[Nexus 4 General] DJBhardwaj:
Nexus 4 Guide-Unlock Bootloader, Root, Install Custom Recoveries & Custom ROMs/Kernel

​

Greetings XDA Members and Guests

We are honored to have an addition of a bunch of new members every day, of which a decent lot is new to our Android custom world. So, if you're viewing this thread, it is because you need guidance in context to Root, Install Custom ROM/Kernels & Custom Recoveries on your LG branded Google Nexus 4. I may have spent tons of hours at this N4 section but I also have my history with Android, going way back when I was also a noob (new comer). Though, I was lucky enough because my fellow community members imparted me with sufficient knowledge to bring on to the basics of the Android custom world i.e Rooting the device, Installing Custom ROMs and Mods. Here I am to give out an helping hand and I want our new entries to feel the way I felt in the beginning; never ignored and forever helped.

So if you’re a noob and you’re reading this, don’t you worry at all, I will take care and hit all the basics inside your head, step by step. I have already done this at the Nexus S section (look here).

I’m sure you’re more curious to get into the Android Development section and flash your desired ROM, I have felt that curiosity but I would advise you to stay calm and give these things some time and little bit of importance too, as then this knowledge will defend you from messing up your devices in the future. Please do not be in a haste, understand the steps or information carefully and then only care to process it. Remember, haste makes waste (someone told me the very same and trust me, I could be the most experienced in making a practical example of this).

Terminology

What is Bootloader and Why do we need to Unlock?

A bootloader is a boot initializing component which is generally locked by the device manufacturer to avoid any messing around with the OS. We need to unlock it for the same reason. Once unlocked it will allow us to change the boot sequence and modify the OS in accordance of our needs.

What is Rooting?

It is a process of gaining root privileges over an Android subsystem. Rooting an Android device is easy in most cases. If you will to Install custom ROMs, kernels, other patches or addons to your Android device, rooting is what you will need. It can be achieved in two ways; either by manual method (using Recoveries) or by automatic method (using toolkit or software) . Here, I am going to follow the manual method.

ClockworkMod & TWRP, what are these?

These are secondary recovery systems created by Koush (Koushik Dutta) & TeamWin, respectively. These add enormous features like wiping partitions, flashing flash-able .zip files like ROMs, kernels, patches etc to the stock AOSP recovery. Visit ClockworkMod website & TeamWin website for more detailed information.

What is a Custom ROM?

These are the aftermarket Android firmware which are not official supported by the OEM (Original Equipment Manufacturer). They are made available to the Android public by Android developers and contributors all around the world. Custom ROMs are either built from Google’s source code i.e AOSP (Android Open Source Project) or are modified versions of the device manufacturer’s ROM (Stock ROMs or Factory ROMs) with additional tweaks and extend functions which are not delivered with the Stock ROMs. Some of the popular Custom ROMs include CyanogenMod (CM), Android Open Kang Project (AOKP), MIUI, Codename Android (CNA), Oxygen, ParanoidAndroid and many more.

What is Custom Kernel?

A Kernel is a bridge between the applications and the actual data processing done at the hardware level, In simple words, it is the communication between the hardware and software of an Operating System. In Android world, Custom Kernels play a vital role since they provide the users with several features including changing CPU frequencies, modifying the boot sequence and boot scripts and other features too.

What are Google Apps (GApps)?

The name speaks for itself. Gapps are Google apps for Android available in flash-able zip format. Most of these applications can now be found and updated via the Google Play Store.Some of the apps include the Google Play Store itself, Google Talk, Google Sync (for adding and synchronizing Google accounts), Google Backup Transport, Car Home, Gmail, Google Maps, YouTube, Google Search, Google Voice Search, Google Music, and Google Docs. In some Custom ROMs, the Google Apps are included. These are usually stock ROMs, smaller or less-common ROMs, or those from areas where intellectual property laws are less commonly obeyed. But many AOSP ROMs, most famously CyanogenMod and AOKP, do not include the Google Apps due to licensing issues. They are after all proprietary code owned by Google and not included in the Android Open Source Project.

Now, lets begin. The first thing we’ll be doing here, is to unlock the bootloader of your Nexus 4, followed by Installing a Custom Recovery, so that later on you can root and Install Custom ROMs/Kernels/Mods easily.

Prerequisites

USB drivers configured properly. You may either use these amazing toolkits [WugFresh?s tookit | mskip’s toolkit] or do it manually using the Google USB drivers delivered with Android SDK (Do it the way you find it easy). Remember, USB drivers in this case doesn’t mean only the drivers to mount the device storage but rather the fastboot and adb drivers too.

Compatible USB data cable.

Android SDK configured (Follow this guide to setup Android SDK and thus it itself configures ADB and all other SDK components)

USB Debugging enabled (Don’t know how? Take a look here)

Backup Device Storage, Messages, Contacts, Calendars etc.

60% or above battery life (This is a recommendation to avoid any uncertain shutdowns during the mentioned process, it might cause issues)

Fastboot binary (Put the file in <sdk_directory>/platform-tools)

Once you have filled in all the requirements, you shall follow further. If you have problem with setting up the prerequisites, please comment and get your issue resolved. Always remember, the more you ask, the more put up to your knowledge and the more you learn.

Unlock Bootloader

Don't want to lose your data after unlocking? Read this.

Reboot your device into bootloader mode. Either manually, by powering off and then pressing Volume Down + Power buttons simultaneously or using the following command in CMD/Terminal.

adb reboot bootloader

Connect the device to your PC using USB data cable.

Open CMD/Terminal and confirm that the drivers are properly installed and the device is detected by entering the following command

fastboot devices

The device ID shall be displayed as the output in your shell. If it is so then the response is positive but in case it shows something else, please make sure to properly install the drivers using a different method than that you used earlier.

Type in the following in CMD/Terminal to initiate the unlocking process

fastboot oem unlock

You will now be prompted with a warning message, use the volume keys to highlight Yes and select it using the power button. Then within a matter of seconds, your device shall be unlocked.

To confirm that it is unlocked, look over to the text in front of Lock State and it should be unlocked.

You’ve successfully unlocked.

What? Too easy? Yes, indeed. The following is as easy too.

Install Custom Recovery

We’ve 2 custom recoveries available yet for our Nexus 4 viz ClockworkMod and TWRP. ClockworkMod or CWM (in short) comes in 2 variants (Touch UI based & Non-Touch UI based). Below I have mentioned on how to flash each one of them using fastboot. For more info about these two recoveries, visit ClockworkMod and TeamWin websites.

Reboot your device into bootloader mode. Either manually, by powering off and then pressing Volume Down + Power buttons simultaneously or using the following command in CMD/Terminal.

adb reboot bootloader

Download the latest build of your desired recovery [CWM | TWRP]

Place the downloaded recovery image (.img) file on your desktop.

If in Windows, open CMD and cd it to the desktop using the following command

cd Desktop

If in OS X or Linux, open terminal and cd it to the desktop using the following command

cd ~/Desktop

To flash ClockworkMod Non-Touch, type in the following command:

fastboot flash recovery recovery-clockwork-x.x.x.x-mako.img

Replace x.x.x.x with the recovery build no. that you downloaded.

To flash ClockworkMod Touch, type in the following command:

fastboot flash recovery recovery-clockwork-touch-x.x.x.x-mako.img

Replace x.x.x.x with the recovery build no. that you downloaded.

To flash TWRP, type in the following command:

fastboot flash recovery openrecovery-twrp-x.x.x.x-mako.img

Replace x.x.x.x with the recovery build no. that you downloaded.

Once flashed, you will prompted on the CMD/Terminal itself.

Now, either reboot your device by using volume keys to highlight Reboot and select using Power button or reboot into the recovery by selecting Recovery mode.

Voila! The next to follow is to root or directly flash a Custom ROM, which is already rooted.

Rooting

Not everyone and each one of us like Custom ROMs. Some users might prefer high stock stability over the features offered by Custom ROMs. and that’s completely normal. But, what if you have an App that requires Root privileges or may be, you need to access the System partition of your device to make certain modifications of your own? This is where the process of Rooting enters. Now when you already know what Rooting is, we shall head further and follow another set of very-simple instructions to root your Nexus 4.

Download the latest SuperSU flash-able root package. [Chainfire's SuperSU Thread]

Connect your device to the PC via USB cable.

Transfer the downloaded file to a suitable location in the device.

Do not disconnect the device.

Open CMD/Terminal and type in the following command:

adb reboot recovery

This will boot your device directly into recovery mode.

You may now disconnect the device.

If you are using CWM, tap on install zip from sdcard > choose zip from sdcard and select the CWM-SuperSU-v0.93.zip. When prompted select Yes to start the flashing process.

If you are using TWRP, tap on Install and select the CWM-SuperSU-v0.93.zip. Slide the circular button to start the flashing process.

When the flashing process has finished, select reboot system now (In CWM) or Reboot > System (In TWRP) to reboot your device.

Congrats! You have successfully rooted your device. Go ahead and use any App that requires Root permissions.

Installing Custom ROM

Its simple, very much simple. All you got to do, is to choose a Custom ROM and simply flash it via your custom recovery.

The very first step is to choose a Custom ROM that fits all your needs and serves you with your desires. When chosen, download the ROM file (flashable zip).

NOTE: Every ROM here at this section is worth and is a result of hardwork of developers/team. Please do not criticize any ROM for any reason. Maintain the forum spirit by encouraging people.

Download the suitable GApps package corresponding to the Android version of your ROM [Link]

In case, the developer has provided specific modified GApps package, download that. Then there is no need to download the GApps package from step #2

Connect your device to the PC via USB data cable.

Transfer the ROM & GApps zip to the device. Its is recommended to put the files in the root of your device storage for convenience.

Disconnect the device,

Power off. Press the Volume Down and Power keys together to boot into the Bootloader mode.

Use the volume keys to highlight Recovery mode and select it using the Power button. Your device will then boot itself into Recovery mode.

Flash using CWM

wipe data/factory reset

wipe cache partition

Go to "mounts and storage" > "format /system" "format /boot"

Go to "install zip from sdcard" > "choose zip from sdcard" > select your ROM .zip file that you placed in step #6. Flash it.

Gapps are the next to be flashed just after flashing the ROM. So, flash Gapps following the same way as the ROM. further if your are provided any add-on in a flash able zip format you can flash it the same way after flashing the ROM and GApps successfully.

Once everything has flashed successfully, select "reboot system now".

Flash using TWRP

Go to "Wipe" > "Advanced" and "Factory Reset".

Go to "Install" > choose the ROM .zip file and flash it.

Gapps are the next to be flashed just after flashing the ROM. So, flash Gapps following the same way as the ROM. further if your are provided any add-on in a flash able zip format you can flash it the same way after flashing the ROM and Gapps successfully.

When flashed, go to "Reboot" > "System".

Your phone will now boot into the custom ROM.

Install Custom Kernel

People often prefer using a Custom Kernel rather than that already delivered with the ROM. For the available kernels, head over to Nexus 4 Original Development section. Every kernel is unique in its own terms, so make a choice. If you’re not satisfied with the combination, move on and try some other kernel.

Choose a custom Kernel and download its flashable zip.

Connect your device to the PC via USB data cable.

Transfer the Kernel flashable zip to the device. Its is recommended to put the file in the root of your device storage for convenience.

Disconnect the device.

Power off. Press the Volume Down and Power keys together to boot into the Bootloader mode.

While on the Bootloader screen, use the volume keys to highlight Recovery mode and select it using the Power button. Your device will then boot itself into Recovery mode.

Flash using CWM

- Select "wipe cache partition"

- Tap on "advanced" and select "Wipe Dalvik Cache"

- Tap on "install zip from sdcard" > "choose zip from sdcard". Now browse and select the kernel zip package that you placed in your storage root during step #3.

- Select "Yes" when prompted to start the flashing process.

- Your Kernel will now flash to your OS and replace your current kernel.

- When it has successfully flashed, select "reboot system now".

Flash using TWRP

- Tap "Wipe" > "Advanced Wipe" and tick "Dalvik Cache" & "Cache".

- Slide the button at the end of the screen to start the wiping process.

- Tap on "Install" > now browse and select the kernel zip package that you placed in your storage root during step #3.

- Slide the button at the end of the screen to start the flashing process.

- Your Kernel will now flash to your OS and replace your current kernel.

- When it has successfully flashed, tap to "Reboot" and select "System".

You now have Custom Kernel installed on your Nexus 4.

NOTE: Before choosing and flashing any Custom Kernel, make sure its compatible with your present Android version.

I hope this guide has helped you. I would be proud, if anyone has received any kind of fruitful knowledge/guidance from this thread.

In case you get stuck anywhere, feel free to comment and ask. Or if I've missed something or may if I am wrong somewhere, please do let me know.

:good:Good Luck with going custom on your Nexus 4:good: