collapse

Author Topic: Guide/tutorial: What can you do with "fastboot" and "adb" commands?  (Read 4184 times)

Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
This thread will be dedicated to learning about and teaching our members about fastboot and adb commands.  It is a work in progress.  If you have any specific questions, please don't hesitate to ask or PM.  This is a guide specific to the Nexus 7 running fastboot commands from a Windows PC.

Lesson One
What is fastboot and how do I use it?

Fastboot is a tool used by the Android development platform, mainly for diagnostic and flashing partitions, over a USB interface.   There is a driver seperate from your USB device drivers that allows the communication protocol.  I will assume that the normal device drivers are installed before proceeding to fastboot commands.  The fastboot tool is device specific.  The tool is available in the Android SDK and must be compiled.  Most toolkits for your device have the drivers already compiled for you and are contained in the root of the tool folder. 

In order to use the fastboot tool, your device must be in the fastboot mode.  The simplest way to get there is to hold both volume buttons while powering on.

I will assume that this lesson is redundant if you are using an Android SDK.  For those who are not, you must execute the fastboot commands from a command prompt within the directory that the tool is located, unless the tool binary is in your PATH. It is easy to add the tool binaries to your PATH, but you must have a folder that is stationary containing the tools and binaries.  on a windows computer, clicck START>right click My Computer>Properties>Advanced>Environment Variables>System Variables>double click Path.  Add the full path to your tools folder. 

If this seems too complicated, close all windows on your PC. Click Start>Run>cmd [hit enter].
This should bring up a command window.  This will be where the fastboot commands are executed.  There should be a command prompt with a file path.  You need to place the fastboot file in this file path.  Once the files are placed in this path, boot into fastboot mode, open a command window and type "fastboot devices" you should see this.

Code: [Select]
fastboot devices
list of devices attached
[device serial number]         device

If this is not what you see, double check the path that you entered or make sure that the files are placed at your command prompt path. 
If you see the serial number you have already begun sucessfully using fastboot commands.


What is "adb" and how do I use it?

Adb is what is known as Android Debugging Bridge.  It is another communication protocol that functions inside the Android operating system. There are three portions of the protocol: client, server, and daemon. The client is run from the computer, the server is also on the computer, but only manages the communication, and the daemon runs on the device. This protocol can move files and perform functions with your data inside the OS.  With Android version 4.2.2 there has been a security feature added requiring one to unlock the device and allow the connection upon the first connection to a new client. 

Adb is used through a command prompt as well.  USB debugging is required.  Go to Settings>Developer Options>Android Debugging.  Make sure this option is checked.  If you extract the contents of the download folder and add it to your path, there should be no further setup.  If you were not able to setup your path, follow the same procedure mentioned above by manually moving the files.  You should be able to begin adb commands. Open a command window while connected to USB with debugging enabled (you should have a notification icon, windows may also install new drivers on first connection) type "adb devices." you should see the following. 

Code: [Select]
adb devices
* daemon not running. starting it now on port 5037 *
* daemon started sucessfully *
List of devices attached
[device serial number]          device



download link for Nexus 7 platform-tools
download here
« Last Edit: March 02, 2013, 09:06:01 PM by loociddreemr »



Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
Re: What can you do with "fastboot" and "adb" commands?
« Reply #1 on: March 02, 2013, 02:17:22 PM »
Lesson 2
Part 1: Fastboot command basics

Some of the most basic commads perform the most critical operations.  The first step in rooting a Nexus or installing a custom ROM is to unlock the bootloader.  Most users will use a toolkit to do this for them.  Fastboot commands will do the trick.  Use "fastboot oem unlock."  the command window should appear as below.

Code: [Select]
C:\Users\Username>fastboot oem unlock...
(bootloader) erasing userdata...
(bootloader) erasing userdata done
(bootloader) erasing cache...
(bootloader) erasing cache done
(bootloader) unlocking...
(bootloader) Bootloader is unlocked now.
OKAY [ 18.421s]
finished. total time: 18.423s

This process can also be reversed in the event a warranty exchange is in order.  Use "fastboot oem lock" to relock the bootloader.  You may notice that the process of unlocking the bootloader also erases the userdata.  It is possible to perform an adb backup to preserve this data, but more on that later.  There is another method to erasing the userdata on the device.  The unlocking method requires the use of the thouchscreen to accept the process.  The "fastboot -w" command does not. It also reformats the entire partition, cleaning up unnecessary folders and junk.

Code: [Select]
C:\Users\Username>fastboot -w
< waiting for device >
erasing 'userdata'...
OKAY [ 26.568s]
formatting 'userdata' partition...
Creating filesystem with parameters:
    Size: 30080499712
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8160
    Inode size: 256
    Journal blocks: 32768
    Label:
    Blocks: 7343872
    Block groups: 225
    Reserved block group size: 1024
Created filesystem with 11/1836000 inodes and 159268/7343872 blocks
sending 'userdata' (139157 KB)...
writing 'userdata'...
OKAY [ 34.029s]
erasing 'cache'...
OKAY [  0.169s]
formatting 'cache' partition...
Creating filesystem with parameters:
    Size: 464519168
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7088
    Inode size: 256
    Journal blocks: 1772
    Label:
    Blocks: 113408
    Block groups: 4
    Reserved block group size: 31
Created filesystem with 11/28352 inodes and 3654/113408 blocks
sending 'cache' (9052 KB)...
writing 'cache'...
OKAY [  1.799s]
finished. total time: 62.576s

The next thing I do after unlocking the bootloader is install a custom recovery.  You can download any compatible recovery and flash with the fastboot command "fastboot flash recovery [local recovery path/filename]" I place the recovery file in the folder of the command propt path and rename to recovery.img.

Code: [Select]
C:\Users\Username>fastboot flash recovery recovery.img
    sending 'recovery' <3684KB>...OKAY  [    1.065s]
                      writing 'recovery' ...OKAY  [    1.265s]
finished. total time: 2.350s

From here its off to adb commands, so proceed with "fastboot reboot" and proceed as usual or boot into recovery. Use the volume rocker to select recovery mode and press power.  But since this is a fastboot guide, I though I would throw that command in there. 
 
« Last Edit: March 02, 2013, 08:21:03 PM by loociddreemr »

Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
Re: What can you do with "fastboot" and "adb" commands?
« Reply #2 on: March 02, 2013, 02:17:46 PM »
Lesson 2
Part 2: adb commands

Adb commands can be given to the device while booted normally, or in most recoveries.  Adb debugging is enabled by default in almost all custom recoveries, so theres no need to boot up, enter your info, and enable debugging. 

The most common adb commands are the push/pull commands.  Here is the syntax.

adb push [local path/filename] [device path]

adb pull [device path/filename] [local path]

In a recent case I used these commands to pull a Nandroid before wiping my device that had a broken screen.  I used the command to pull an entire folder.

Code: [Select]
C:\Users\Username>adb pull /sdcard/clockworkmod/ \clockworkmod\

This created a parent folder at C:\Users\Username\clockworkmod\ and included all subsequent files and folders. 

Once many users become comfortable pushing the limits of their device, they opt into rooting.  With the Nexus 7, the easiest method of obtaining root is a flashable zip that can be flashed in any custom recovery.  So download the zip UPDATE-SuperSU-v1.04.zip from here move to the command promt path and use:

Code: [Select]
adb push UPDATE-SuperSU-v1.04.zip /sdcard/
Install the zip through recovery and you're rooted!


A useful trick for those more seasoned adroid users.
Code: [Select]
adb pull /system/build.prop build.prop
use a text editor to make changes
Code: [Select]
adb remount
adb push build.prop /system/build.prop

Notice the use of the "adb remount" command.  This mounts the /system/ as read/write.  There are other ways to do this, but that gets into the adb shell commands.  Shell commands are not exactly adb commands, but linux terminal commands.  They are more advanced, so we'll get into that later as well.

Heres a useful, but less common command: "adb install [local path/filename.apk]" You can install apps from recovery or fully booted with this process.  This is another method of sideloading.
« Last Edit: March 02, 2013, 08:37:25 PM by loociddreemr »

Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
Re: What can you do with "fastboot" and "adb" commands?
« Reply #3 on: March 02, 2013, 07:34:12 PM »
Just as an example, heres why it was easier for me to use the commands and not an app or toolbox.  I wanted to restore my Nandroid to a completely reformatted stock device.  If you use wugfresh, it installs TWRP.  My Nandroids are the CWM blobs/dup version.  So either way I would have to set up the account profile and wifi password on the device and enable the usb debugging to install the proper binaries for SU and go to the play store and dowload an app just to flash a compatible recovery.  Or I can use [fastboot oem unlock] (unlocks the bootloader) then [fastboot flash recovery recovery.img](flash CWM) then [fastboot reboot-recovery]. From here its [adb push clockworkmod/ mmt/shell/emulated/clockworkmod] to push the Nandroid to the device. Once that completes, while still in recovery I can restore my already rooted Nandroid with all my apps and settings, all without booting the device and reentering the info. 

Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
Re: What can you do with "fastboot" and "adb" commands?
« Reply #4 on: March 02, 2013, 08:41:51 PM »
I've guided you through the process of taking a stock device, unlocking the bootloader, flashing custom recovery, and rooting. 

I'll try to get into more of the advanced commands soon, but heres a good start.  Next possibly changing permissions... uninstalling system apps... not sure. Any suggestions? Questions?

Offline bjs229

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2682
  • Popularity: 47
    • View Profile
Re: Guide/tutorial: What can you do with "fastboot" and "adb" commands?
« Reply #5 on: March 02, 2013, 09:29:24 PM »
This is great !Really a step above relying on toolkits. A lot of info and knowledge here. Appreciate it.

Sent from my Nexus 7 using Tapatalk HD

Offline S.Prime

  • PM if You have a Forum Issue
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2017
  • Popularity: 80
  • Galaxy S3-TPT-HTC Flyer-Nexus 7 & 10-Rooted 100%
    • View Profile
Loociddreemr, your effort is greatly appreciated.

Sent from my Nexus 10 using Tapatalk HD
IT Service Professional - I just want a device to be productive.

Offline matt

  • Hero Member
  • *****
  • Posts: 936
  • Popularity: 28
    • View Profile
Re: Guide/tutorial: What can you do with "fastboot" and "adb" commands?
« Reply #7 on: March 03, 2013, 01:49:50 AM »
Is there a syntax for the available commands, like adb /? , or fastboot /help           ?

Offline S.Prime

  • PM if You have a Forum Issue
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2017
  • Popularity: 80
  • Galaxy S3-TPT-HTC Flyer-Nexus 7 & 10-Rooted 100%
    • View Profile
Re: Guide/tutorial: What can you do with "fastboot" and "adb" commands?
« Reply #8 on: March 03, 2013, 02:06:02 PM »
Loociddreemr, are you planning to include a section on loading an insecure boot.img for using adb commands with the secured folders, like during the rooting process?
IT Service Professional - I just want a device to be productive.

Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
I can definitely provide some more information regarding the insecure boot, but it requires shell commands and changing ownership/permissions. I'll get into that later, and combine it with a manual root instead of a flashable zip. There will be another section for options.
 
In the meantime, there is a syntax guide available from the command prompt. Using "abd" without the command will pull up the help guide. "Adb help" also works. The same goes with "fastboot" and "fastboot help"

Sent From my Razr Maxx(stock .211, waiting for the MFN soak test) via Tapatalk 2

Offline commodore128

  • Newbie
  • *
  • Posts: 41
  • Popularity: 0
    • View Profile
Re: Guide/tutorial: What can you do with "fastboot" and "adb" commands?
« Reply #10 on: March 03, 2013, 02:55:56 PM »
i have been playing with adb on my revlinux distro(an offshoot of ubuntu), since i installed adb and fastboot it is now available in the repostories. primarily for ubuntu. works realy well. although i have only used push and pull to backup my nandroid and apps. it is nice to have an alternative and one for linux.

Offline engineer

  • Full Member
  • ***
  • Posts: 112
  • Popularity: 0
    • View Profile
I've been surfing trying to learn what I can about android. This is very helpful. Thank you.

A comment from someone who has only been in this os for a week: it was not always clear to me when you were in the android device and when you were issuing commands on the PC. I'll have to go over it again. Might be helpful to clearly indicate when you are downloading files (sdk) and issuing commands on the PC or the android device.

Learned a lot. Owe you a beer! Where are you located?

Sent from my Nexus 7 using Tapatalk 2


Offline loociddreemr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 708
  • Popularity: 25
  • OG Droid-Razr MAXX-Nexus 7
    • View Profile
I'm glad that you found this helpful. This is a learning process for all of us and I'm happy to share my experience and findings.

You can thank me with a simple thumbs up or PM me if you want to buy me a drink.

Sent From my Razr Maxx(W.K.Y.A.98.72.16.XT912.v4.5-R3Ds) via Tapatalk 2


 


* Top Boards

* 'Like' And 'Follow' Us!

* Top Posters

bjs229 bjs229
2682 Posts
JayJ JayJ
2100 Posts
S.Prime S.Prime
2017 Posts
Babyfacemagee Babyfacemagee
1260 Posts
matt matt
936 Posts
birdastrompgman birdastrompgman
840 Posts
loociddreemr loociddreemr
708 Posts