ADB
ADB mode of an android phone means that the usb debugging enabled mode.
FASTBOOT
Fastboot is a protocol that can be used to re-flash partitions on your device (update the flash file system in Android devices).
COMMON COMMANDS
On PC run Command Prompt as Administrator.
UNLOCK BOOTLOADER
NOTE: Some newer devices don't allow unlocking of bootloader directly to ensure more security. Instead an official method is provided to unlock BL using PC.
Read here to know about the risks of BL unlocking.
To check the bootloader status:
“True” on unlocked status.
If "false", run the following to unlock:
FORMAT DATA PARTITION
This will erase your data.
It can be performed on other flash partitions as well. A general syntax is 'fastboot format:FS PARTITION'
FLASH RECOVERY
Download recovery.img (specific for your device) to adb folder.
To test the recovery without permanently flashing, run the following:
On next reboot, recovery will be overwritten by previous recovery.
Or to permanently flash recovery, run:
Stock ROM's often tend to replace custom recovery with stock one
on first reboot. That's why, booting into recovery is recommended before
booting into ROM.
FLASH KERNEL
Download boot.img (specific for your device) to adb folder and run following:
FLASH ROM
Download ROM.zip (for your device) created for fastboot i.e. with android-info.txt and android-product.txt.
To wipe your device and then to flash .zip:
GAIN ROOT (Not recommended method. Better flash directly through custom recovery).
Root is required to modify the contents of /system. You can read here further.
Download (flashable) supersu.zip and custom or modified recovery.img (having support to flash .zip files) to adb folder and run the following:
Now once you are in recovery, adb will work instead of fastboot.
To copy files from PC to device and then to extract files, run the following:
BACKUP / RESTORE APPS & DATA (From/To PC)
To backup and restore all apps and their data:
Read here for details.
COPY WHOLE PARTITION IMAGE (within device)
This method can be used to backup whole device e.g. to backup /data/ including /data/media/ i.e. Internal SD Card which isn't backed up by custom recovery (TWRP). Or you can get any partition image for development purpose. This method retains complete directory structure as well as file permissions, attributes and contexts.
COPY WHOLE FOLDER (within device)
This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).
To jump from windows command prompt to android device shell:
These commands can also be given from Recovery Terminal.
To get SuperUser access (in ROM):
To copy from Internal Memory to SD Card:
Or if you don't have SU permission:
To copy from SD Card to Internal Memory:
However, if you are copying to an SD card with FAT32 file system, android permissions of files won't be retained and you would have to fix permissions yourself. In this case, you can use tar command to create archive of files along with their attributes ( permissions: mode & ownership + time-stamps) and security
contexts etc. But FAT32 FS has also a limitations of 4GB maximum file
size. You may use "split" command along with "tar" to split the archive
in smaller blocks. Or use exFat or Ext4 filesystem for larger file
support. Ext4 would give higher writing speed in Android but not
supported in Windows i.e. SD card can't be mounted in Windows. MTP
however works.
To jump from windows command prompt to android device shell:
To get SuperUser access (in ROM):
To copy from Internal Memory to SD Card:
To extract from SD Card to Internal Memory (along with path):
To extract from SD Card to some other location, use "-C":
COPY WHOLE FOLDER (From/To PC)
This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).
To copy from PC to device:
To copy from device to PC:
After copying from PC to device's Internal Memory (/data/media/),
you might get Permission Denied error e.g. apps can't write or even read
from Internal Memory. It's because Android (Linux) and Windows have
different file permissions system. To FIX PERMISSIONS, boot into recovery and run following commands:
To take ownership of whole "media" directory:
To fix permissions of directories:
To fix permissions of files:
PASSING FASTBOOT ARGUMENTS
Fastboot supports passing options. For example, while booting a modified kernel image with FramBuffer Console support, console device and its font can be provided as option:
SOURCE : XDA DEVELOPERS FORUM
ADB mode of an android phone means that the usb debugging enabled mode.
FASTBOOT
Fastboot is a protocol that can be used to re-flash partitions on your device (update the flash file system in Android devices).
COMMON COMMANDS
On PC run Command Prompt as Administrator.
- To check connected devices when ROM is running on phone: Code:
adb devices
- To boot into bootloader mode: Code:
adb reboot bootloader
- To check connected devices when in bootloader mode: Code:
fastboot devices
- To boot into ROM: Code:
fastboot reboot
- To boot into recovery: Code:
fastboot reboot recovery
UNLOCK BOOTLOADER
NOTE: Some newer devices don't allow unlocking of bootloader directly to ensure more security. Instead an official method is provided to unlock BL using PC.
Read here to know about the risks of BL unlocking.
To check the bootloader status:
Code:
fastboot oem device-info
If "false", run the following to unlock:
Code:
fastboot oem unlock
This will erase your data.
Code:
fastboot format:ext4 userdata
FLASH RECOVERY
Download recovery.img (specific for your device) to adb folder.
To test the recovery without permanently flashing, run the following:
Code:
fastboot boot recovery.img
Or to permanently flash recovery, run:
Code:
fastboot flash recovery recovery.img fastboot reboot recovery
FLASH KERNEL
Download boot.img (specific for your device) to adb folder and run following:
Code:
fastboot flash boot boot.img
Download ROM.zip (for your device) created for fastboot i.e. with android-info.txt and android-product.txt.
To wipe your device and then to flash .zip:
Code:
fastboot -w fastboot update </path/to/your/Rom.zip>
Root is required to modify the contents of /system. You can read here further.
Download (flashable) supersu.zip and custom or modified recovery.img (having support to flash .zip files) to adb folder and run the following:
Code:
fastboot boot recovery.img
To copy files from PC to device and then to extract files, run the following:
Code:
adb push supersu.zip /tmp adb shell /sbin/recovery --update_package=/tmp/supersu.zip
To backup and restore all apps and their data:
Code:
adb backup -apk -shared -all -system -f C:\backup.ab adb restore C:\backup.ab
COPY WHOLE PARTITION IMAGE (within device)
This method can be used to backup whole device e.g. to backup /data/ including /data/media/ i.e. Internal SD Card which isn't backed up by custom recovery (TWRP). Or you can get any partition image for development purpose. This method retains complete directory structure as well as file permissions, attributes and contexts.
- To jump from windows command prompt to android device shell: Code:
adb shell
- To get SuperUser access (in ROM): Code:
su
- To list all available partitions or mount points on device: Code:
cat /proc/partitions
Code:ls -al /dev/block/platform/*/by-name
To confirm:
Code:readlink /dev/block/bootdevice/by-name/userdata
- Run the following to copy partition: Code:
dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
Code:cat /dev/block/mmcblk0p25 > /sdcard/data.img
Code:dd if=/dev/block/bootdevice/by-name/userdata of=/sdcard/data.img
It also works inversely (restore):
Code:dd if=/sdcard/data.img of=/dev/block/mmcblk0p25
Similarly you can copy system.img, boot.img or any other partition. However boot.img and other partitions may not be copied in ROM but in recovery mode only. So better use recovery for dd except if you're going to dd recovery partition itself. You can read here more about android partitions.
COPY WHOLE FOLDER (within device)
This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).
To jump from windows command prompt to android device shell:
Code:
adb shell
To get SuperUser access (in ROM):
Code:
su
Code:
cp -a /data/media/0/. /external_sd/internal_backup/
Code:
cp -a /external_sd/. /sdcard/
Code:
cp -a /external_sd/internal_backup/. /data/media/0/
To jump from windows command prompt to android device shell:
Code:
adb shell
Code:
su
Code:
tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
Code:
tar -xvf /external_sd/internal_backup/media.tar
Code:
tar -xvf /external_sd/internal_backup/media.tar -C /data/media/0/extracted_archive/
This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).
To copy from PC to device:
Code:
adb push \path\to\folder\on\PC\ /path/to/folder/on/device/
Code:
adb pull /path/to/folder/on/device/ \path\to\folder\on\PC\
Code:
adb shell
Code:
chown -R media_rw:media_rw /data/media/
Code:
find /data/media/ -type d -exec chmod 775 '{}' ';'
Code:
find /data/media/ -type f -exec chmod 664 '{}' ';'
Fastboot supports passing options. For example, while booting a modified kernel image with FramBuffer Console support, console device and its font can be provided as option:
Code:
fastboot boot -c "console=tty0,115200 fbcon=font:VGA8x8" boot-fbcon.img
SOURCE : XDA DEVELOPERS FORUM