ADB & Fastboot

  • Android Debug Bridge, aka ADB, is a command line with which you can explore, perform actions and make changes to an Android or a KaiOS device. The adbd daemon runs on the device, and the adb client starts a background server to multiplex commands sent to devices.

  • Fastboot is a diagnostic protocol primarily used to modify the flash filesystem via USB connection from the host computer. It requires the device be booted into boot loader mode or fastboot mode or secondary program loader mode.

Install ADB and Fastboot on Windows 7 / 8 / 8.1 / 10

1. ADB and Fastboot are part of the Android SDK package. You can download the official release from the developer.android.com website, by selecting Android Studio > RELEASE NOTES > SDK platform tools:

2. Extract the contents of this ZIP file into an easily accessible folder);

3. Open Windows explorer and browse to where you extracted the contents of this ZIP file;

4. Open up a Command Prompt from the same directory as this ADB binary (hold Shift and Right-clicking within the folder then click the “open command prompt here” option, on Windows 10 users may see “PowerShell” instead of “command prompt”);

5. Connect your phone to your PC with a USB cable;

6. Dial the debug code *#*#33284#*#* or use a different way to enable ADB (take a look to the KaiOS devices);

7. In the Command Prompt window, enter the following command to launch the ADB daemon: adb devices

8. If everything was successful, you should now see your device’s serial number in the command prompt.

NOTE: from the Command Prompt you can normally use "adb", as in all the guides on this site. If you use PowerShell you must specify the path using "./". For example the adb devices command of the Command Prompt becomes ./adb devices in PowerShell.

Install ADB and Fastboot on macOS and Linux

1. ADB and Fastboot are part of the Android SDK package. Download the official release for your platform from the developer.android.com website, by selecting Android Studio > RELEASE NOTES > SDK platform tools:

2. Open the Terminal.

3. To browse to the folder you extracted ADB into, enter the following command: cd /path/to/extracted/folder/ or just drag and drop the folder on the terminal;

4. Connect your phone to your Mac/PC with a USB cable. On Mac, change the USB connection mode to “file transfer (MTP)” mode;

5. Dial the debug code *#*#33284#*#* or use a different way to enable ADB (take a look to the KaiOS devices);

6. Once the Terminal is in the same folder your ADB tools are in, you can execute the following command to launch the ADB daemon: adb devices

7. If everything was successful, you should now see your device’s serial number in the Terminal.

Install ADB and Fastboot on Linux from the main repositories

  • On Debian-based, users can type the following command to install ADB and (if needed) Fastboot:

sudo apt install adb fastboot

  • On Fedora-based, users can type the following command to install ADB:

sudo dnf install android-tools

  • On Arch-based, users can type the following command to install ADB:

sudo pacman -S android-tools or just sudo pacman -S adb

  • On Gentoo-based, users can type the following command to install ADB:

sudo emerge --ask dev-util/android-tools

  • For all Linux distributions it is possible (and not necessary if you're already using the repositories) to use the same steps indicated in the paragraph dedicated to macOS.

Setting up USB access (Linux only)

Since the USB drivers for these peripherals are in many cases not recognized on Linux, we can rely on this manual configuration (from developer.kaios.com):

  1. Download and install the Android rules using this long command:

wget -S -O - https://raw.githubusercontent.com/cm-b2g/B2G/1230463/tools/51-android.rules | sudo tee >/dev/null /etc/udev/rules.d/51-android.rules; sudo udevadm control --reload-rules

  1. Plug the device to your computer using a USB cable and use the command lsusb to get the Vendor ID, from the terminal, in my case on Qualcomm (Nokia 8110 4G) the output is:

"Bus 001 Device 007: ID 05c6:f003 Qualcomm, Inc. Nokia 8110 4G"

so my vendor ID is 0506;

  1. Check the new /etc/udev/rules.d/51-android.rules file, if the line for your ID vendor is not available, just add it as this:

#Qualcomm

SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0664", GROUP="plugdev"

obviously for Spreadtrum and Mediatek the value from the lsusb output will be different;

  1. Run the command:

sudo chmod a+r /etc/udev/rules.d/51-android.rules

  1. Create the file /.android/adb_usb.ini in your HOME directory (not as root) ant put the value of vendor ID on this file using hex format. In my example the value is 0x0506, where 0506 is the vendor ID that we got before, for Nokia 8110 4G. Here are some screenshots of what it must look like:

6. Use the command 'adb devices' on the terminal to list all devices connected on your PC. Your device should be listed and is ready to receive Gaia apps or use it on WebIDE.

ADB commands list


(source, enriched by Ivan)

Global options

-a (listens on all network interfaces, not just localhost) -d (uses USB device, error if multiple devices connected) -e (uses TCP/IP device, error if multiple TCP/IP devices available) -s SERIAL (uses device with given serial, overrides $ANDROID_SERIAL) -t ID (uses device with given transport id) -H (name of adb server host, default=localhost) -P (port of adb server) -L SOCKET (listens on the given socket for adb server)
  • adb help

This command prints a list of all the available adb commands.Syntax: adb help
  • adb version

This command shows the version of adb installed on your PC.Syntax: adb version
  • adb devices

This command prints a list of all attached devices. In response, it returns the serial number and state of the device.Syntax: adb devicesResponse: 210048b device
  • adb reboot

This command reboots the device (defaults to booting the system image, but supports also bootloader|fastboot|recovery|sideload|sideload-auto-reboot.Syntax: adb reboot or adb reboot <option>Response: adb reboot recovery
  • adb forward

This command forwards the socket connections. It required USB Debugging enabled.Syntax: adb forward <local> <remote>Example: adb forward tcp:6000 localfilesystem:/data/local/debugger-socketSet up forwarding of host port 6000 to emulator/device port /data/local/debugger-socket
  • adb kill-server

It terminates the adb server process. Sometimes you might want to terminate the adb server and restart it to resolve the problems.Syntax: adb kill-server
  • adb connect

This command allows using adb over Wi-Fi. This requires the host and the device connected to the same Wi-Fi network.Syntax: adb connect <host>[:<port>]Not very useful in KaiOS. To use ADB over Wi-Fi, firstly connect the device to PC and set tcp ip port to 5555 using “adb tcpip 5555” command. You should find your IP by connecting the browser of your phone on a website like this (on Android you can get this info from Settings). Now you can use adb connect command to use ADB over Wi-Fi.Example: adb connect 192.168.x.x:5555
  • adb usb

Restarts ADB in USB mode.Syntax: adb usb
  • adb install

Pushes an Android application (.apk) from host to an emulator or the device (not useful on KaiOS).Syntax: adb install [option] <path to .apk>Example: adb install test.apk
  • adb uninstall

Uninstalls or removes the package (.apk) from the emulator or Android device (not useful on KaiOS).Syntax: adb uninstall [option] <PACKAGE>Example: adb uninstall com.test.app
  • adb shell pm list packages

Prints all packages installed on the device/emulator (not useful on KaiOS).Syntax: adb shell pm list packages [options] <FILTER>Example: adb shell pm list packages
  • adb shell

This command opens the shell. All the commands in whose examples contain the word "shell" can be used individually only after running this command.Syntax: adb shellTo exit the shell.Example: exit
  • adb shell start

This command can be used to start a daemon or a script.Syntax: adb shell start <daemon>Example: adb shell start b2gThis allows you to start b2g from a previous stop or another mode (example FFBM).
  • adb shell stop

This command can be used to stop a service.Syntax: adb shell stop <daemon>Example: adb shell stop b2gThis allows you to stop b2g.
  • adb shell pm path

Prints the path to the APK of the given package (not useful on KaiOS).Syntax: adb shell pm path <PACKAGE>Example: adb shell pm path com.android.phone
  • adb shell pm clear

This command deletes all the data associated with the package (clears app data and cache - not useful on KaiOS).Syntax: adb shell pm clear <PACKAGE>Example: adb shell pm clear com.test.app
  • adb pull

Downloads or pulls a specified file from an emulator/device to your computer (host).Syntax: adb pull <remote> [local]Example: adb pull /system/b2g/webappsTo download the webapps folder from /system/b2g to your home folder.
  • adb push

This command is used to upload or push or copy a file from the host (computer) to an emulator or the device.Syntax: adb push <local> <remote>Example: adb push my-script.sh /data/local/tmpTo push a my-script.sh file to /data/local/tmp.
  • adb shell ls

Lists directory contents.Syntax: ls [options] <directory>Example: adb shell lsThis allows you to watch all the files and directory on the mountpoint /.
  • adb shell cd

Change the directory or folder.Syntax: cd <directory>Example: adb shell cd /system
  • adb shell rm

Removes files or directories.Syntax: rm [options] <files or directory>Example: adb shell rm /sdcard/my-file.txtThis removes the file my-file.txt on your sdcard.
  • adb shell mkdir

Make a directory or create a folder.Syntax: mkdir [options] <directory name>Example: adb shell mkdir /sdcard/test
  • adb shell touch

Create an empty file or change file timestamps.Syntax: touch [options] <file>Example: adb shell touch /sdcard/my-file.txt
  • adb shell pwd

Prints current working directory location.Syntax: pwdExample: adb shell pwd
  • adb shell cp

Copy files and directories.Syntax: cp [options] <source> <destination>Example: adb shell cp /sdcard/my-file.txt /sdcard/folder/
  • adb shell mv

Move or rename files.Syntax: mv [options] <source> <destination>Example: adb shell mv /sdcard/tmp /system/tmp
  • adb shell netstat

Shows network statistics.Syntax: netstatExample: adb shell netstat
  • adb shell ping

Test the connection and the latency between two network connections.Syntax: ping [options] <destination>Example: adb shell ping www.android.com
  • adb shell net cfg

Manage and configure network connections via profiles.Syntax: netcfg [<interface> {dhcp|up|down}]Example: adb shell netcfg
  • adb shell ip

Show, manipulate routing, devices, policy routing, and tunnels.Syntax: ip [options] objectobject := { link | addr | addrlabel | route | rule | neigh | ntable |tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |netns | l2tp }optoins := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |-f[amily] { inet | inet6 | ipx | dnet | link } |-l[oops] { maximum-addr-flush-attempts } |-o[neline] | -t[imestamp] | -b[atch] [filename] |-rc[vbuf] [size]}Example: adb shell ip -f inet addr show wlan0
  • adb logcat

Prints log data on the screen.Syntax: adb logcat
  • adb shell dumpsys

Dumps system data.Syntax: adb shell dumpsys [options]Examples: adb shell dumpsys / adb shell dumpsys batterystats
  • adb shell dumpstate

Dumps state.Syntax: adb shell dumpstate
  • adb shell screencap

Takes a screenshot of the device’s display (on Android only - not useful on KaiOS).Syntax: adb shell screencap <filename>Example: adb shell screencap /sdcard/screenshot.png
  • adb shell screenrecord

Records the device’s screen. It requires the device to be running on Android 4.4 (API level 19) or higher (so it's not useful on KaiOS).Syntax: adb shell screenrecord [options] <filename>Example: adb shell screenrecord /sdcard/screen.mp4
  • adb root

Restarts the adbd daemon with root permissions (not useful on KaiOS).Syntax: adb root
  • adb sideload

Sideloads OTA update.zip package and other files on the device (also in Recovery Mode, if signed).Syntax: adb sideload <file.zip>Example: adb sideload update.zip
  • adb shell ps

Prints process status.Syntax: ps [options]Example: adb shell ps
  • adb shell top

Displays top CPU processes.Syntax: top [options]Example: adb shell top
  • adb shell getprop

Get property via the Android/KaiOS property service (learn more on the /system/build.prop file).Syntax: getprop [options]Example: adb shell getprop
  • adb shell setprop

This command is used to set property service (learn more on the /system/build.prop file).Syntax: setprop <key> <value>Example: adb shell setprop persist.moz.ril.1.network_types gsm,wcdma,lte

BusyBox

BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides minimalist replacements for most of the utilities you usually find in GNU coreutils, util-linux, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts.

Learn more on the official website of the project, busybox.net

Fastboot commands: functions and examples


(source)

Global options

-w Erase userdata and cache (and format if supported by partition type).-u Do not erase partition before formatting.-s <specific device> Specify a device. For USB, provide either a serial number or path to device port. For ethernet, provide an address in the form <protocol>:<hostname>[:port] where <protocol> is either tcp or udp.-c <cmdline> Override kernel commandline.-i <vendor id> Specify a custom USB vendor id.-b, --base <base_addr> Specify a custom kernel base address (default: 0x10000000).--kernel-offset Specify a custom kernel offset (default: 0x00008000).--ramdisk-offset Specify a custom ramdisk offset (default: 0x01000000).--tags-offset Specify a custom tags offset (default: 0x00000100).-n, --page-size <page size> Specify the nand page size (default: 2048).-S <size>[K|M|G] Automatically sparse files greater than 'size'. 0 to disable.--slot <slot> Specify slot name to be used if the device supports slots. All operations on partitions that support slots will be done on the slot specified: 'all' can be given to refer to all slots, 'other' can be given to refer to a non-current slot. If this flag is not used, slotted partitions will default to the current active slot.-a, --set-active[=<slot>] Sets the active slot. If no slot is provided, this will default to the value given by --slot. If slots are not supported, this does nothing. This will run after all non-reboot commands.--skip-secondary Will not flash secondary slots when performing a flashall or update. This will preserve data on other slots.--skip-reboot Will not reboot the device when performing commands that normally trigger a reboot.--disable-verity Set the disable-verity flag in the the vbmeta image being flashed.--disable-verification Set the disable-verification flag in the vbmeta image being flashed.--wipe-and-use-fbe On devices which support it, erase userdata and cache, and enable file-based encryption.--unbuffered Do not buffer input or output.--version Display version.-h, --help show this message.
  • fastboot devices

This command is similar to adb devices it prints a list of all attached devices in fastboot mode. In response, it returns the serial number of the device.Syntax: fastboot devices
  • fastboot reboot

Reboots the device to normal or standard mode. Used to exit the fastboot mode or boot loader mode.Syntax: fastboot reboot
  • fastboot reboot recovery

This commands boots the device into Recovery Mode.Syntax: fastboot reboot recovery
  • fastboot oem unlock

Unlocks bootloader on the device.Syntax: fastboot oem unlock
  • fastboot oem lock

Used to relock the bootloader on the device.Syntax: fastboot oem lock
  • fastboot oem device-info

Prints bootloader lock/unlock status.Syntax: fastboot oem device-info
  • fastboot flash recovery

Flashes recovery image to the device.Syntax: fastboot flash recovery <file-name.img>Example: fastboot flash recovery twrp.img
  • fastboot boot

Used to boot the image file without installing or flashing on the device. Can be used to boot recovery image without flashing on the device.Syntax: fastboot boot <file-name.img>Example: fastboot boot recovery.img
  • fastboot flash

Flashes flashable zip file from fastboot or bootloader mode.Syntax: fastboot flash <file.zip>Example: fastboot flash update.zip
  • fastboot getvar cid

Displays CID (Carrier ID) of the device.Syntax: fastboot getvar cid