[Nexus 6  General] danarama:
Please note, I can only speak with any degree of certainty about devices bought from Play / Moto. I cannot attest to the accuracy of this information for US carrier versions etc. Anything you do is at your own risk

Contents / Thread overview

Introduction

What is Fastboot?

What is adb?

How to install adb and fastboot

How to test adb and fastboot work

OK Gimme some useful fastboot commands please!

OK Gimme some useful adb commands please!

A little more about using Windows command prompt

Myth Busters

Introduction

adb and fastboot are very useful command line tools. They can be used from Windows, Linux or Mac to carry out tasks on your android device, such as moving and backing up files, rooting and restoring your phone to it's factory state. Understanding how to use these tools could save your phone when you get yourself in trouble. This is especially true of rooted users. Particularly those of you who are "new to the scene". You definitely should read and understand this thread before you do ANYTHING root related.

This thread is not intended to be a non-exhausted reference. It is merely here to give an overview of the most basic of basics

What is fastboot?

Fastboot comprises of 2 components.

1) Fastboot mode on the phone (The Bootloader)

2) Fastboot tool on your computer

Fastboot is a small command line tool that you can use from your computer whilst the phone is connected via USB and you are booted into the bootloader. The most common uses for fastboot are:

Unlocking the bootloader - needed as part of the rooting process

Flashing a custom recovery to the device - needed as part of the rooting process

Flashing factory images - used for saving / trestoring your device back to stock

Being able to do these 3 things are essential before rooting. Many new users skip learning these and use a toolkit to root. As a result, when they mess up and we try to explain what they need to do to fix their issues, it becomes very difficult for us to help as fastboot is not understood. It is YOUR responsibility to understand these things BEFORE you mess up.

What is adb?

adb is another small command line tool that stands for "Android Debugging Bridge". Again, it can be used from a computer connected via USB to your android device. It can be used whilst the device is booted into Android or (if you have a custom recovery), it can be used in recovery too, unlike fastboot (yes, adb and fastboot are NOT the same thing) which can only be used in the bootloader.

adb can be used to push files to (or pull files from) your phone. It can also be used to execute many of the commands available in Linux terminals (Or Android terminal emulators) on the device itself. We're not here to cover all these commands however. We just want to cover the basics.

How to install adb and fastboot

adb and fastboot are very easy to install and can be installed on Windows, Linux and MAC computers. The Windows install can be a little bit more complicated than the other 2 and may need additional drivers installing too.

Windows.

There is a very handy tool that can install adb and fastboot in 15 seconds. It is recommended that you use this to install adb and fastboot. Please see the link immediately below for that tool:

ADB, Fastboot and Drivers - 15 seconds ADB Installer - Really quick and easy way to install adb and fastboot (by [MENTION=4638083]Snoop05[/MENTION]). Download links are at the bottom of post 1.

This tool asks if you want to install adb and fastboot (to which you should answer Y) and then creates c:\adb\adb.exe and c:\adb\fastboot.exe

It then asks if you want to install it system wide .. This is asking to install for all windows users. < 15 second installer needs updating to SDK 23, which is required for latest Android versions.

Download the latest SDK (adb and fastboot) versions here: https://developer.android.com/sdk/index.html (Scroll down to SDK tools only) then download the Windows *Installer*.

Open the installer and select "Platform-tools" and install the packages. This should create "C:\Program Files (x86)\Android\android-sdk\platform-tools"

Now we want to set this path as a Windows Environment variable PATH to make the executables work system wide:

right-click computer > properties > advanced > environment variables.

under system variables click "path" and click "edit"

at the end of the line, add the below:

;C:\Program Files (x86)\Android\android-sdk\platform-tools

Please note, the semi-colon ; is VERY important.

You may also need to install drivers.

Here is a link to the Google USB Driver: DOWNLOAD THIS

To install on Windows 7:
- Ensure existing drivers are uninstalled first*
- Extract the zip to c:\adb (created earlier by the installer)
- Right-click "Computer" > Manage in windows and choose "Device Manager"
- Boot the Nexus 6 to the bootloader (Volume down + Power) and connect the USB Cable
- Watch for any new devices with exclamation marks appearing
- Right-Click the new device > Update driver software
- Choose the "browse" method and browse to c:\adb, find teh folder you extracted then follow the wizard to the end - using amd6 64 if you're on a 64 bit system and i386 if you're on a 32 bit system.

*To uninstall existing drivers, boot into Android and connect the USB cable. Monitor device manager for the device showing up. To uninstall the device, right-click it to uninstall it. At the prompt, ensure you also choose to delete the driver. Repeat this for bootloader and recovery.

To Install on Windows 8, you may need to additionally disable driver enforcement

- 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.

Once that is done, your Windows computer is configured for adb and fastboot.

In device manager, the device should show up as below, depending whether you are booted into recovery or bootloader...

Recovery - Android Device > Google Nexus 4 ADB Interface

Bootloader - Android Device > Google Nexus 4 Bootloader Interface

If it shows as something different, either you have existing drivers in the way or something went wrong.

Linux and Mac

Here is a really simple tool to install adb and fastboot on the above OS. The only expectation is you know how to open and run a terminal command. Please see the link immediately below:

Nexus Tools 2.2 (Featured by XDA) - adb and fastboot installer for Linux and Mac (by [MENTION=4516295]corbin052198[/MENTION])

Once you have installed adb and fastboot from the above link, you're ready to go.

How to test adb and fastboot work

As previously mentioned, adb and fastboot are both command line tools. That means you must run these tools from command prompt (cmd in Windows) or Terminal (Linux and Mac).

Remember earlier, I mentioned that fastboot can only be used in bootloader? and adb can only be used in Android (or custom recovery - lets cover that later)? We can use the command "fastboot devices" and "adb devices to see if we have adb and fastboot working correctly.

Lets try it.

Boot your phone into android

Connect it to your computer via USB

Open cmd (start > type "cmd" on Windows) or Terminal (Mac/ Linux

Type in the windows "adb devices" and press enter

Here is what we don't want to see:

Notice how there is nothing underneath where it says "List of attached devices" That means it cannot see any device

Here is what we DO want to see:

We can see that there is now a device listed.

OK lets test fastboot. Unplug the USB and turn off the phone. When it is off, hold down Volume down + power until you feel the vibrate. You will now be in the bootloader. Reconnect the USB cable.

In the same window (cmd or terminal) we're going to now type "fastboot devices".

Again, here is an example of what we don't and do want to see:

If in both modes, you can see your devices "Serial Number", then you know they are both working.

Please note that if you cannot get adb and fastboot to work "system wide", you can open the command prompt to the location of the adb and fastboot executables exist and try from there.

OK Gimme some useful fastboot commands please!

Here are some of the most useful fastboot commands you will come across. Fastboot is used mostly for flashing images to the devices partitions on the internal memory.

fastboot oem unlock

This unlocks your bootloader and allows you to flash a recovery to root. WARNING, this will wipe your device. Rooting the N6 is essentially unlocking the bootloader, flashing a recovery and then putting the SuperSU zip on your sdcard and flashing it via the recovery. This thread covers rooting: [HOW-TO] The Nexus 6 All-In-One Beginner's Guide by [MENTION=4945572]xBeerdroiDx[/MENTION]

fastboot flash recovery recovery.img

This will flash a recovery.img to the recovery partition. The command is broken down into "fastboot flash" (what to do) "recovery" (where to flash to) "recovery.img" what to flash there. In the terminal or command prompt, you cannot just type "recovery.img" though. It has to be the path to where the recovery image is. For example, if my recovery image is on my desktop, I would have to type:

fastboot flash recovery c:\users\rootsu\desktop\recovery.img

It is worth noting, that it IS case sensitive, meaning if your file is called Recovery.img, you must type the capital R...

Other things you would flash:

fastboot flash system system.img
fastboot flash boot boot.img

These will flash the system image (ROM) and boot image (kernel) as you would if you were returning to stock.

A full guide to returning to stock can be found here: [TUTORIAL][GUIDE][HOW TO] Flash Factory Images || Unroot || Relock bootloader by [MENTION=5697318]Mr hOaX[/MENTION]

You can also boot into a recovery.img without flashing it...

fastboot boot c:\users\rootsu\desktop\recovery.img

which is "fastboot boot" (what to do) "c:\users\rootsu\desktop\recovery.img" what to do it with. As you may have noticed, we did not define the recovery partition in this command, that's because we're not flashing it....

OK Gimme some useful adb commands please!

At the moment, we are going to assume you have a custom recovery and you have booted into recovery. The reason for this is using adb in recovery can be much simpler.

Here are some useful scenarios for using adb.

Backup your sdcard to your PC

adb shell
mount data
exit
adb pull data/media/0 c:\MyBackup

**Please note, some recoveries may "mount data" automatically on boot, so don't be disheartened if you get an error stating device or resource busy. This probably just means you can't mount what is already mounted**

/data/media/0 is the real location of /sdcard for your information. Also referred to as "The mount point". What we have done here is "adb pull" (what to do) "data/media/0" (what to move) "c:\MyBackup" (where to move it to)

Push a zip file from your PC to your sdcard (useful if you wiped your sdcard and rom)

adb shell
mount data
exit
adb push c:\rom.zip data/media/0

What we have done here is "adb push" (what to do) "c:\rom.zip" (what to move) "data/media/0" (where to move it to)

You can of course also use adb to push and pull files to and from /system too. You just need to:

adb shell
mount system
exit

I mentioned earlier that using custom recovery is much easier for adb than whilst booted into Android. You need to ensure you have a kernel that allows insecure adb before you do anything with system and data partitions. You also need to ensure that USB debugging has been enabled in developer options.

For example, to mount system to pull files whilst android is running you have to:

adb root
adb shell
mount -o rw,remount /dev/block/platform/msm_sdcc.1/by-name/system /system

...which is clearly a little bit more involved, so I recommend you use recovery for adb push and pull. You can find more detailed information on adb here: http://developer.android.com/tools/help/adb.html

A little more about using Windows command prompt

One thing to understand is that like Windows, command prompt (cmd.exe) works with directories (or folders if you like). The Linux and Mac terminals are the same, but most linux users, we expect you would already know this.

Here you will see I have downloaded a recovery image that I want to flash using fastboot.

As you can see, the recovery.img is located in C:\users\rootSU\Desktop

Usually when you open the command prompt from the start menu, or run command, the command prompt will default to your user location as seen below:

So lets try and fastboot flash recovery recovery.img...

It fails with a not-too-accurate error message. It has failed because you have not told it where the recovery image is. It assumes it is in the directory as listed in the prompt

So, how do we deal with this? Well, there are 3 ways.

1) We tell the command prompt where the recovery.img actully is in the command itself

Success! As you can see, we have told the command that the location for the file is Desktop\recovery.img

2) We can change the directory in command prompt to the directory where the file is. In this example, we change directory to "Desktop". The change directory command is "cd " or in this case "cd Desktop"

3) ...and possibly the simplest method. We hold shift whilst we right-click on the folder we want to change directory to, and directly open a command prompt there:

Another point to make with command prompt or terminals, is if you do a particular command, it is "pre-programmed" to "expect" a particular format of that command.

For example, we know that adb push as a command expects after it . This means the command is actually

adb push

BUT if you put something AFTER , for example -

adb push somethingelse

, it will assume that the "somethingelse" is a bad parameter, and the command will fail. It will probably display (or "print" which is the technical term in a terminal) a helpful guide of how the command should be used instead of trying to run the command which it does not understand.

You're probably wondering why I am telling you this. Well quite simply, it is a warning about folder names. Imagine you have c:\users\rootSU\My Documents as a folder. You assume the command is then

adb pull /data/media/0 c:\users\rootSU\My Documents

but it is not... There is a space in between My and Documents. What you have actually done is

adb pull Documents

because it uses a space to signify the end of a command or parameter. It is best to avoid using folders with spaces in them. Avoid as much as you can. In the event it is unavoidable (Although when is it ever>) then please surround the path with quotation marks,

adb pull /data/media/0 "c:\users\rootSU\My Documents"

so that way, it sees everything between the " " as a single parameter.

Myth Busters

Myth 1: You need USB debugging on to use adb and fastboot

If you cannot boot into Android, it doesn't matter. You DO NOT need USB Debugging turned on to use adb outside of android. USB Debugging is an Android ONLY setting. Fastboot obviously also does not need debugging either as this too is outside of Android

Myth 2: to adb push or fastboot flash files, they must be in the same folder as adb or fastboot executables. Sorry but this is rubbish. You can pass the full path of the image you're flashing or file you're pushing in the command and fastboot / adb can be called system wide if you've set them as an environment variable or used the 15 second installer