Friday, February 28, 2014

Nexus 4 - Unlock & Root


Warning: Unlocking the bootloader will wipe your entire device, including the internal sdcard. You will lose everything that you do not backup to your computer before you begin. Keep that in mind before you proceed.
I am not responsible for anything that happens to your device. Unlocking and rooting always has the possibility of bringing about softbricks, voided warranties, global thermonuclear war, and soiled undergarments. You and you alone assume all risk if you choose to proceed. [/WARN]
Are we clear? Good. The instructions in the following tabs are not difficult, but please, please, PLEASE read them fully and carefully. It is equally important for you to understand the process in addition to getting it right. Ready to roll...

[/TAB][TAB=Setup and Files]A few items you will need before we begin..
1. ADB and fastboot files If you have installed the Android SDK these will be located in your Android SDK /platform-tools directory, or wherever you downloaded them to before. Make sure you know where they are. If you need to grab them again, I totally stole these from smarter people than me (namely PaulOBrien) and just took out stuff we don't need, and renamed it to avoid confusion for you guys. Download from here:https://dl.dropbox.com/u/47300967/ne...b-fastboot.zip
Stick that on your desktop and unzip it so you will have a folder called nexus4-adb-fastboot on the desktop containing the files.

2. Drivers If you are on a Windows system (linux and mac need not bother with these): Universal Naked Driver 0.72.zip
Warning: Uninstall any previous driver package's you may have installed and also manually remove drivers by attaching your phone and going to Windows device manager and right click the entry for your phone and select "Uninstall" on the next prompt make sure to select "Delete the driver software for this device" then hit OK and reboot before installing these drivers
HUGE thanks to 1wayjonny at xda for these drivers and instructions!!
[TIP]*Windows 8 users: You probably will need to disable Driver Signature Enforcement. Instructions:
From the Metro Start Screen, open Settings (move your mouse to the bottom-right-corner of the screen and wait for the pop-out bar to appear, then click the Gear icon).
Click ‘More PC Settings’.
Click ‘General’.
Scroll down, and click ‘Restart now’ under ‘Advanced startup’.
Wait a bit.
Click ‘Troubleshoot’.
Click ‘Advanced Options’
Click ‘Windows Startup Settings’
Click Restart.[/TIP]

3. TWRP Recovery This will be our custom recovery that we use to gain root (and later, flash ROMs and such if you choose). It is a fast, smooth, intuitive and open-source recovery. Download directly here: Techerrata Downloads - Downloading openrecovery-twrp-2.4.1.0-mako.img
It's also good to check TWRP's site and make sure you're getting the latest version, Link provided here: TeamWin Projects - TWRP 2.4 - Nexus 4 | TeamWin
Rename the file to recovery.img and place it inside the folder that contains your fastboot and adb files.
Credit Team Win for their awesome efforts on TWRP!

If you really prefer CWM Recovery, you may use that as well, but be advised I will be using TWRP on my device and won't be able to advise as well if anything goes wrong with CWM. Download from here:http://download2.clockworkmod.com/re...0.2.3-mako.img
Rename the file to recovery.img and place it inside the folder that contains your fastboot and adb files.
Credit as always to Koush!

4. Superuser.zip This will grant us root access after we flash it in recovery. Download here: http://download.clockworkmod.com/sup.../superuser.zip
Place this .zip file inside the folder that contains your fastboot and adb files.
Credit goes to Koush!
[/TAB][TAB=Re: PC/MAC/LINUX]
What appears as commands in the following tabs are GENERAL INSTRUCTIONS TO UNLOCK, FLASH RECOVERY, AND ROOT. Make sure you know how to do it for your computer/setup and that ADB and fastboot is set up on your computer. Know the exact folder containing the fastboot files you will be using.

[NOTE]Throughout these instructions I will be entering our commands in the format:

Code:
fastboot … … …
However, you must remember to modify just the beginning part to reference the appropriate file for your system. 
For Windows this should look like:
Code:
fastboot-windows … … …
For Linux (note that sudo may be required before entering fastboot commands):
Code:
sudo fastboot-linux … … …
For Mac (note that ./ is required before entering the commands on a Mac):
Code:
./fastboot-mac … … …
[/NOTE]

Please make sure you understand that before moving forward..

[/TAB][TAB=Unlocking The Bootloader]Are you still with me? Great... let's get started!

As a quick intro to Unlocking it.. why not watch AC's Phil Nickinson walk you through it!


1. Power off your Nexus 4, and reboot it into fastboot mode by holding the volume down button and power. You'll see the familiar green robot, and the word "Start" at the top of the screen. Note the last line will read "Lock state - locked"

2. Open a command prompt inside the folder we have our adb and fastboot files in. On Windows this can be done by holding shift as you right-click in the folder, then select "Open command window here". On Mac or on a Linux system you want to open a terminal/command prompt and navigate to that folder using "cd" or "change directory" commands. For example, if you grabbed the zip I posted earlier and extracted it on your desktop, your folder is called "nexus4-adb-fastboot" on your desktop, and you would enter:

Code:

cd desktop


cd nexus4-adb-fastboot

Now your command prompt is ready in the correct directory for all of the following commands.

3. Plug your phone into a full speed primary USB port on your computer. If you're using Windows, you'll see the pop-up about drivers being installed and initialized.

4. Let's make sure fastboot is recognizing your device. Type this command and hit Enter:

Code:
fastboot devices
You should see "List of attached devices" Followed by a string of numbers. If you do not see this, you do not have your drivers installed correctly! You may need to remove them and try just reinstalling from the Setup tab earlier. If you got the expected response, continue..

5. Now the simple, magical code which will unlock your bootloader. In your command prompt type the following and hit Enter:

Code:
fastboot oem unlock
Look at your phone screen. You should see a dialog warning that your device will be wiped, etc. Use the Up Volume key to highlight Yes and hit the Power key to select it. You will return to the fastboot screen and the bottom line will read "Lock state - unlocked"

6. There is no step 6... You have unlocked your bootloader successfully! If you ever wish to re-lock the bootloader, just follow along just like we did here and instead enter the command:

Code:
fastboot oem lock
Alright.. that was easy wasn't it? Now let's root it![/INFO]

[/TAB][TAB=Root It!] 


[INFO]1. Boot your phone up by pressing the Power button. Bypass / skip through the activation screens. Once booted, and still connected to your computer, drag and drop the superuser.zip file we downloaded earlier on to the root of your sdcard - meaning just the base of your internal storage, not inside any folders. Now unplug and power down the phone, boot into the bootloader again just like earlier, and plug it back in.
**More astute/advanced users may want to skip this step and just push this file using adb once they get into recovery. You can do that if you like, but I've found that can work inconsistently, so for now I'm going to have people just do it this way 

2. This command will boot you into CWM, it will not flash it permanently. Type it in and press Enter.

Code:
fastboot boot recovery.img
3. Tap "Install zip from sdcard" and locate the superuser.zip file, and select it and tap Yes to install. You have now root! Go back and select the option to Reboot System.

4. After booting you will want to go into your app drawer and open Superuser. It may request that you update the binaries, and you should allow it to. Going forward it will update via the Play Store like all of your other apps, and you should launch it afterwards to update the binary as well.

5. When finished, go to your Settings > Accounts and add your Google account since we skipped activation before. Proceed as normal setting up your phone. [/INFO]

[/TAB][TAB=Troubleshooting & FAQ]Answers and Solutions to Common Issues
Q. Will this void my warranty? And can I brick my device?
A. Not necessarily. In the strictest sense, unlocking and rooting will make your warranty voidable at the discretion of Google / LG. Meaning they can choose to not honor your warranty if you try to claim damages caused by your hacking ways. In practice you will often be able to receive appropriate warranty service a defective device even if you have unlocked / rooted it, but I cannot guarantee it for you. A Nexus device is almost impossible to actually "brick". Sometimes you may do something foolish and cause a "softbrick" which is actually very easily fixable. Check out my Factory Image Restore Guide to learn how to fastboot the factory images to your device no matter what you did to it and return it to brand new, out of the box condition. The same procedure can be used if you need to claim warranty service for an actual defective device and want to return it to stock before sending it in for repair/replacement.

Q. OH CRAP.. I bricked it. I don't know what I did but it's bootlooping and I don't know how to fix it. Am I screwed???
A. No! Relax. See the above answer and check out the Factory Image Restore Guide 

Q. Will I continue to receive OTA (over-the-air) updates if I do this?
A. Yes.. my instructions are having you just boot into the custom recovery to flash SuperSU, we are leaving your stock recovery intact so that will not keep you from installing an OTA when it arrives. When you have root access you obviously have the ability to change your system files, and doing so could potentially cause an OTA to fail to install, as it needs to read your system as 100% stock. Additionally most OTA's will cause you to lose root access. You can easily re-root it following the exact same method we used here; or you can install OTA Rootkeeper and have that app backup your root access and restore it after the OTA. Which method you chose is up to you and either one will work just fine 

Q. I don't want to fastboot the recovery every time I want to go flash something.. how do I flash it permanently?
A. First, understand that having a custom recovery permanently flashed will make you unable to receive OTA updates (you can very easily reflash the stock recovery though, I'll get to that). If you want to proceed anyway, using your new root access you want a file explorer that uses root. I prefer Root Explorer, but you can use Root Browser Lite if you want a free option. Using the app, locate the file "recovery-from-boot.p" in your /system directory. Long-press it and rename the file to something like "recovery-from-boot.p.bak".. this way you can easily rename it back later if you change your mind. Alternatively you could just delete it if this doesn't concern you. Now you can make your custom recovery stick when you fastboot it like before, but this time using the command:

Code:
fastboot flash recovery recovery.img
Where 'recovery.img' might be a different filename based on which recovery you are using, of course. Also of course there are apps that will flash the recovery for you if you are too lazy to fastboot, i.e. ROM Manager for CWM and GooManager for TWRP.

Q. Well I flashed the custom recovery permanently, I deleted the recovery-from-boot.p file, and now I want to receive an OTA but it won't install because I have a custom recovery. How do I reflash the stock recovery?
A. Grab the factory image from Google (link is available in my Factory Restore Guide). Extract it and also unzip the .zip file within, and look for the file named recovery.img. Simply use fastboot to flash this from the bootloader exactly like you flashed the custom recovery earlier.

Q. When entering the commands I see the error "fastboot is not a recognized command"
A. Your command prompt just isn't looking in the correct location. Remember you had to locate the directory which contains your fastboot file, move all of the files extracted from the Factory Image to that directory, and then either tell the command prompt to look in that directory or open the command window from within that directory. Go back to Step 2 of the step-by-step and try again.

Q. What the heck are you talking about?? Can't I just use a toolkit to do all of this for me? Why do you make it so complicated???
A. Sure you can. But you don't learn that way. A Nexus device is the easiest to unlock and root, you might as well spend a few minutes doing things manually and expanding your knowledge. Not to mention that toolkits can fail you, but knowing how to fastboot can save your life (and phone!). You learn a lot more doing things manually than just clicking a big ROOT ME button 

Q. Why are we using TWRP Recovery? I thought Clockwordmod (CWM) was the best one?
A. I like it better, that's why, lol. Also it is less buggy than recent versions of CWM and the interface is nicer, IMO.

Q. But I want to use ROM Manager to flash recovery, or to flash ROMs, or .....
A. ROM Manager is buggy and I don't like it, but you can do what you want. TWRP has a similar app that will actually flash it for you if you like, check out GooManager. I still recommend people know how to flash recovery using fastboot, and know how to flash ROMs and files from within recovery, not from using an app like ROM Manager or GooManager.
[/TAB][TAB=In closing..]
Thanks to everyone whose files, verbatim and other information I used while putting this guide together. If you have any further questions, issues or suggestions just post them up and myself or another member will be around as soon as possible to help you out 

And please, if I failed to credit anyone properly, please PM me and I will be sure to rectify that!


No comments:

Post a Comment