Wednesday, November 27, 2013

Using ADB and fastboot With Your Android Device

If you have found this page you are probably frantically looking for some fastboot or adb command and that's what I will give you - scroll to the end of the post and you'll find examples. For all you other people who are not freaking out about their bricked or non-booting phone...continue on. haha. 


What Are fastboot And ADB

fastboot and adb are two programs found in the Android development SDK that allow you to transfer files, install programs, flash images, and run commands on your Android phone. Another thing to note: ADB can only connect to your phone while it is in recovery or booted into the OS. fastboot can only be used when your device is in bootloader mode. Finally, one of the most important things (i think) in terms of android is to access the bootloader: turn off your device and hold Power and Volume Down at the same time. 


Where Can I Get Them?

This SDK (download here) contains all the stuff you need to develop programs for android and is a fairly large file accordingly. Luckily, someone has taken just adb and fastboot and packaged them into a "minimal" installer which can be found here. I would recommend installing it to the root of your hard drive (C:\ most likely) because it greatly simplifies using the command prompt. 

I must also note that these tools can mess up your phone if used improperly, so, make sure you have the correct file or know what you are doing. Not to take away from that, but most times the incorrect rom or apk etc will just crash and you can easily remove it and then flash again.


Prep

1. adb or fastboot?
      a. For fastboot: Power Off your phone and get to the bootloader (Power and Volume Down for most phones) and select fastboot. If power/volume down doesnt work, you could use adb to reboot into the bootloader (See the adb example section)
      b. For adb: boot into recovery mode or stay inside the android OS and enable USB Debugging.
2. Connect your device via the USB port to your computer.
3. First thing for the computer side you need is an open a command prompt. Open the start menu and search for cmd. You can also press Windows Key and 'R', type cmd and press enter
4. Then we'll need to change to the directory where we installed the minimal fast boot and ADB. For example:  
cd "C:\Minimal ADB and Fastboot"
5. Now we are in the directory where adb and fastboot are stored so all we need to do is type fastboot or adb and then the rest of the command.

An alternative is to simply click on the Minimal ADB and fastboot icon that the installer makes on your desktop. it will open a command prompt and get you to the correct directory. If you are a cmd "noob" this is the way to go. Again, i must warn you, if you are smart enough to see yourself as a "noob" i'd think that you are smart enough not to try this unless you know exactly what you are getting into and their repercussions.


fastboot Examples

Check to see if your device is recognized 

fastboot devices

It can reboot your device and reboot it into the bootloader or recovery etc

fastboot reboot
fastboot reboot bootloader
fastboot reboot recovery

Using fastboot to flash a new recovery, system, radio, or kernel etc firmware file. 

fastboot flash recovery C:\path\to\MyRecoveryFirmware.img

Using fastboot to erase some partition on the device. This example will erase the system partition on your android device. This can also be used on the recovery, boot, or radio partitions for example.

fastboot erase system

To wipe system, data, and the cache at the same time (would be used before a new rom for example)

fastboot erase system -w

fastboot can be used to reboot your device:

fastboot reboot

Using fastboot to lock / unlock your bootloader (note: to unlock your bootloader you'll most likely need a file from your devices' manufacture. look up how to unlock your specific device on google.)

fastboot oem lock
fastboot oem unlock

For using RUU's you'll need to lock the boot loader and then reboot into RUU mode

fastboot oem rebootRUU

To find all commands your particular phone supports
fastboot oem ?
or
fastboot

adb Examples

Similar to fastboot, adb also has a devices command which will list the found compatible devices connected

adb devices

It can also, like fastboot, reboot your device and reboot it into the bootloader or recovery etc

adb reboot
adb reboot bootloader
adb reboot recovery

Getting logcats for diagnostics

adb logcat > logcat.txt
or
adb logcat -v long > logcat.txt

Install an application (apk format) from your hard drive to the device

adb install "C:\path\to\apk.apk"

Using push to move a file or directory from your computer to the device

adb push C:\path\to\file /path/on/device

Copying a file or directory from your device to your computer

adb pull /path/on/device C:\path\on\computer

ADB can also be used to access the terminal shell on your device

adb shell

Then you can run standard linux shell commands from your computer on your device. Here are a few that you'll probably need

su: root privileges
du: Shows file folders and size
ls: Shows list of directory
cd: Changes directory
rm: Removes a file or directory
cp: copy file or folder

Sometimes you'll get an error about read/write or access denied. this is because the file system isn't mounted as read/write. Use this command to remount the file system:

mount -o rw,remount /

Note: these are basic guidelines or references to using adb and fastboot, and is not a guide to unlocking, rooting, or flashing a rom.

5 comments:

  1. preety good commands. but i have a problem, when i try these command i encounter an error saying that "error:device not found" i connecten my mobile and went into recovery mode... after that a menu came in that i choosed update frm adb something and still my device is not found

    ReplyDelete
  2. please help me.
    I try this command but it always say error:close
    please help me.

    ReplyDelete
  3. My Problem is .. No Command. Dead Android logo with red ! Plese help..

    ReplyDelete
    Replies
    1. More details. where does this thing appear? what are you doing at that time?

      Delete