The Nexus 5 is not only the most powerful Nexus phone to date, but arguably the first Nexus phone to have top-of-the-line, cutting edge specifications. So clearly, you're not going to leave it stock, right? See, the beauty of hacking a Nexus is threefold. First, it's ridiculously simple if you have a moderate understanding of fastboot, adb, and common hackery terms. Second, the next person to actually brick a Nexus will be the first. And finally, the "exit plan" for the Nexus line is unrivaled--just flash stock images and have a drink. No worries about finding a RUU executable or using some polytheistic downloader.
So if you really want to get down and dirty with the Nexus, the absolute first thing you should do before you even sign-in to your Google account is unlock the bootloader.
Unlocking the Nexus 5's Bootloader
The bootloader is the key to flashing "images" on the Nexus. These images can be recoveries (further used for hackery), kernels (the piece of software that controls hardware/software interaction), radios/basebands (the software that connects you to networks), and other system images. Unfortunately, unlocking the bootloader completely erases everything on your device--including stuff on the faux "SDcard" partition. So if you have saved 600 pictures of cats from Reddit, say goodbye to them. Because of this, I recommend unlocking the bootloader as soon as you have the device in hand.
To unlock the bootloader, you generally have two options--use a toolkit or use fastboot. Fastboot requires having the fastboot.exe (included in the Android SDK) on your machine as well as device drivers so that your phone can communicate with a computer via the USB port. If you have a Mac, all you need is the fastboot.exe--no drivers necessary.
Once you have the drivers and fastboot.exe, simply boot your Nexus 5 to the bootloader screen (from SCREEN OFF, hold down the POWER BUTTON AND VOLUME DOWN BUTTON SIMULTANEOUSLY), plug it into the computer, open a Command Prompt or Terminal, change the directory to the fastboot.exe location, and enter the following command:
$ fastboot oem unlock
This command will prompt a screen asking if you would like to unlock; use the volume keys to navigate to your option (which should be yes ), then use the power button to select.
Now, as stated earlier, this will wipe your device. Everything. Pictures, accounts, downloaded apps. The whole nine, so to speak. So it is best to do this as early as possible.
Once unlocked, simply reboot the device and sign-in. Market Restore should work fairly quickly, and soon enough you will have all of your apps, contacts, and the like.
Flashing Images with Fastboot
Unlocking your Nexus 5's bootloader gave you the veritable "keys to the kingdom." Now, you can use your shiny new unlocked bootloader, a USB cable, and Command Prompt/Terminal to make some magic.
The most popular use for fastboot, at least for the amateur ROM enthusiast, is arguably the installation of a custom recovery. Custom recoveries allow you to flash (i.e. install) zip packages (usually in the form of roms, themes, and other goodies). For the past 2 years or so, two recoveries have dominated the Android scene: ClockworkMod Recovery ("CWM") and Team Win Recovery Project ("TWRP").
Before we get to the recovery, let me explain some fastboot concepts:
- First, fastboot acts as a link between device and computer. The device, however, must be in "fastboot mode." For the Nexus, this mode is the bootloader. Therefore, before you contemplate using fastboot, make sure you reboot your device into the bootloader.
- Second, make sure you have your fastboot drivers downloaded and ready (if you're on a Windows machine). While drivers are somewhat outside the scope of this guide, the best way to check is to get to fastboot mode, connect your device to a computer via USB, cd to the fastboot directory, and type:
$ fastboot devicesPress enter (as with any and every command in Command Prompt/Terminal). If a string of numbers shows up, huzzah, you are ready to rock! If not, you must reinstall (or install) the device drivers.
- Third, fastboot commands follow a similar structure. Generally, the structure is as follows:
$ fastboot [ <option> ] <command>Therefore, you always use the fastboot "prefix" when entering a fastboot command. "Options" like "-w" (wipe) are less frequently used than the commands, so for our purposes, we will only focus on the commands. Accordingly, the most frequent command is the "flash" command, or:
flash <partition> [ <filename> ]Therefore, putting it all together, the most frequent fastboot command used is this:
$ fastboot flash <partition> [ <filename> ]Here, the "partition" may be, among other things, the "recovery" (for the custom recoveries) or "boot" (the kernel). Thus, you want to "point" fastboot to where you are installing, and then use the filename (including the .img file extension) to define what you are installing.
- Fourth, make it easy on yourself and put all fastboot items into the folder in which the fastboot.exe is located. Therefore, you only need to change directory ("cd") once and everything is neat and organized.
Once you understand flashing images with fastboot, you're ready to install a recovery. As stated above, the two prime recoveries are CWM and TWRP. While you can install these recoveries through alternate methods (GooManager will install TWRP, ROM Manager will install CWM), fastbooting the images is a piece of cake.
- Download the recovery image. Be sure to only download a recovery explicitly for the Nexus 5--which should be "Hammerhead" if purchased through Google Play.
- Place the recovery image in the folder that contains your fastboot.exe.
- OPTIONAL: Some folks rename the recover image's filename. You can; or, alternatively, you can just use it as is.
- Reboot the Nexus 5 into the bootloader.
- Connect the Nexus 5 via USB cable to your computer.
- Open Command Prompt/Terminal, and then change directory to the fastboot folder. Use this command:
$ cd [ <location> ]For example, if it's C:\AwesomeAndroidFolder . . .
$ cd C:\AwesomeAndroidFolder
- Make sure your device is recognized by fastboot:
$ fastboot devices
- Enter the fastboot command:
$ fastboot flash recovery [ <filename> ]For example, it should look like this:
$ fastboot flash recovery CWMrecoveryfilename.img
- Now, once installed, you will have full use of the custom recovery. You can boot into it at this point to look around, or you can reboot your system. To get to the recovery, go through the bootloader--reboot into it and scroll to "recovery," press power, and the recovery should load. You may also get there with adb using the following command when your phone is on and USB debugging is enabled:
$ adb reboot recovery
Flashing a ROM is one of the great joys Apple users will never enjoy. See, when they want to mess with their phone, they are constrained by the fact that iOS is completely closed source. They can change some things, like adding settings and changing the look with themes, but in large part, "jailbreaking" only gets you so far. Because Android is open source, the code is just floating out there in the stars waiting for eager minds to pull it down and bring it to users like you.
Generally, a ROM changes your OS. It may change your Android version, e.g. from Android 4.3 (Jelly Bean) to Android 4.4 (KitKat). But usually, it's built from the latest available Android version and includes custom options, tweaks, and optimizations. In the Nexus community, there are a few big ROMs/developer groups--Paranoid Android, Android Open Kang Project ("AOKP"), and CyanogenMod ("CM"). Depsite those, there are dozens of custom-built ROMs by smaller groups and individual developers. On a Nexus, the choice of ROM could literally be endless.
ROMs come in two general packages. The first, and now less common package, is a single zip package containing the ROM and the necessary Google Applications ("GAPPS"). The second and most prominent package is actually two zips, the ROM and the GAPPs. If you enjoy using Google Play services with your device, you must have GAPPs.
ROM installation is ridiculously easy. Generally, there are two methods. The first method--which uses a full wipe--is recommended for any ROM that (i) you are unsure of; (ii) is completely new to you, and not just an iterative update of your present ROM (i.e. it is not a "nightly" build of your current ROM); (iii) requires extensive testing; (iv) is a new Android version; and (v) is recommended by the developer to be flashed with a full, clean wipe. The general rule of thumb for full wiping is this:
When in doubt, wipe the entire bloody thing.
Full Wipe/Clean Flash
- Download the ROM and GAPPs packages. Please, please, please make sure these files are for your device--Hammerhead. Also, be sure to verify the MD5s of the downloads to ensure that you did not inadvertently download a corrupt or inappropriate file.
- Transfer the ROM and GAPPs packages to your internal storage. I usually use a folder named "GLORIOUS ROMAGE," because flashing is awesome.
- Reboot into the recovery.
- Create a backup of your current ROM or setup, using the options and prompts available to you in recovery. I highly recommend having one verified working backup (also called a "nandroid") on my device at any given moment, just in case.
- Perform a "factory reset" wipe. This means you must wipe the data, cache, system, and dalvik cache. Please note that most--if not all--ROMs will wipe the system for you. Do not wipe internal storage. If you really like wiping (and really, who doesn't?), wipe 3-7 times. I do it because I'm paranoid and I have anxiety levels that rival many small-time tyrants.
- Once wiped, locate the "install from SDcard" or "install zip" option in recovery.
- Find the ROM zip and install the ROM. Do not install GAPPs first, for the ROMs install script will wipe the system partition, and thus wipe the GAPPs.
- Find the GAPPs zip and install the GAPPs. Note that if you use TWRP, you can create an "install queue" where you can stack multiple zips for installation. Just like the above, make sure you install the ROM first.
- OPTIONAL: some people like wiping the cache and dalvik cache after the installation procedure. Depending on the given levels of caffeine, adrenaline, and anxiety coursing through my veins, I do too. It is, however, your call.
- Reboot the system, sign in to Google, and set up your device.
Now, if you are simply installing an iterative update (nightly), you can get away with a partial wipe or a dirty flash. This procedure is slightly different, although the warnings and advice stated above still apply.
Partial Wipe/Dirty Flash
- Download the ROM and GAPPs packages. Because this is an iterative update, you may already have the latest GAPPs package on your phone. If that's the case, there's no reason to download another.
- Transfer the ROM and GAPPs packages to your internal storage.
- Reboot into the recovery.
- Create a backup of your current ROM or setup.
- Perform a partial wipe. This means you must wipe the cache, system, and dalvik cache. Do not wipe internal storage.
- Once wiped, locate the "install from SDcard" or "install zip" option in recovery.
- Find the ROM zip and install the ROM.
- Find the GAPPs zip and install the GAPPs.
- OPTIONAL: post-install cache and dalvik cache wipes.
- Reboot the system and your data and apps will remain as it was before.
Remember though--if you have any doubt, perform a full wipe. Usually, if issues or bugs or force closes creep up after a ROM install, such issues are first attributed to not performing a full wipe. As a matter of general courtesy, do not report minor bugs to developers if such bugs are encountered after a dirty flash.
For now, the above tools should help you to customize your Nexus extensively. The Nexus has--and always will have--incredible ROM and kernel developer support. Its ease of access and malleability arguably makes it the most customizable phone in existence, and folks the world over take advantage of that. Be sure to enjoy this experience, but as always, be careful and double check each and every step along the way. Before you know it, you'll be wiping dalvik and fastbooting with ease and confidence.