fastboot命令

fastboot是配合手机的fastboot模式使用的一种工具。
可以在手机系统损坏(非砖)的情况下不依赖手机软件,而是使用本地的镜像操作手机。

下面列举常用的用法:

fastboot devices 查看是否有设备

fastboot boot boot.img|recovery.img ——用当前目录下的boot.img或者recovery.img启动手机,具体如下
fastboot boot boot.img ——用当前目录下的boot.img启动手机,在手机boot分区损坏的情况下可以用这个正常进入系统
fastboot boot recovery.img ——用当前目录下的recovery.img启动手机到recovery模式,
这个和手机上现有的系统完全无关,只要本地的 recovery.img是以前能正常进rec的,那就绝对没问题。
那些官升或者刷rom后无法进入rec的其实都可以通过这种方式进入recovery 环境进行刷机、刷rec,刷各种zip……

上面介绍两种操作都是临时的,也就是说重启之后手机还是原来的状态,没有任何变动。
典型的应用场景是修改boot.img,可以用fastboot boot bootnew.img来测试新的boot.img,不对的话只需要重启手机。

下面这个的话就是真正改变了手机的boot分区,改写成了当前目录下 boot.img的内容。
fastboot flash boot boot.img ——把当前目录下的boot.img刷入手机的boot分区。

fastboot flash recovery recovery.img ——把当前目录下的recovery.img刷入手机的recovery分区。
**fastboot flash system system.img ** ——把当前目录下的system.img刷入手机的system分区。

fastboot flash userdata userdata.img ——把当前目录下的userdata.img刷入手机的data分区。

fastboot erase system
fastboot erase cache
fastboot erase config
fastboot erase data
fastboot erase logs
fastboot erase factory

fastboot reboot —— 重启手机

Android系统的分区为:

boot分区对应 /boot
recovery分区对应 /recovery
system分区对应的目录 /system
userdata分区对应 /data
cache分区对应 /cache

Let’s move forward to the useful commands:

Commands Use
Basic ADB Commands
adb devices Shows a list of devices attached to the computer.
adb reboot Reboots a device connected to the PC.
adb reboot recovery Reboots a device into recovery mode.
adb reboot download Reboots the connected device into download mode. E.G Download mode on Samsung Galaxy devices.
adb reboot bootloader Reboots a device into Bootloader. Once in Bootloader, you can make further selections here.
adb reboot fastboot Reboots a connected device into Fastboot mode.
Installing / Uninstalling / Updating Apps with ADB.
adb install .apk ADB install let’s you install APK files directly to your phone. To use this command type adb install application path, as shown in the commands part and hit enter key and it will start installing the app on your phone. e.g adb install C:/Users/UsamaM/Desktop/CandyCrushSaga.apk. If process succeeds it will show you “Success” in the command window.
adb install -r <AplicationpathPackagename>.apk If you have already installed an app, and you just want to update it then this command will let you do so. e.g adb install -r C:/Users/UsamaM/Desktop/CandyCrushSaga.apk
adb unistall package_name e.g adb uninstall com.android.chrome Uninstalls and application from your device. The easiest way to find a package name is, install Package Name Viewer from the play store and find the name of the package under the App Name. If process succeeds it will show you “Success” in the command window.
adb uninstall -K package_name e.g a db uninstall -K com.android.chrome Uninstall an app but keeps it’s data and cache directories. If process succeeds it will show you “Success” in the command window.
Push and Pull files
adb root adb push > e.g adb push c:\users\UsamaM\desktop\Song.mp3 \system\media adb push filepathonPC/filename.extension path.on.phone.toplace.the.file the adb push commands let’s you transfer any files to your phone from your PC. You simply need to provide the path of file on your PC and path where to place this file on your phone.
adb root adb pull> e.g adb pull \system\media\Song.mp C:\users\UsamaM\desktop adb pull [Path of file on phone] [Path on PC where to place the file] Similar to the adb push command. Using adb pull, you can simply pull any files from your phone.
Backing up system and installed apps. Before doing this, in your adb folder create a folder Backup and under the backup folder create two folders named SystemApps and InstalledApps. These folders are necessary as you’ll be pushing the backed up apps to these folders.
adb pull /system/app backup/systemapps backs up all the system apps of your phone to the Systemapps folder that you created in the ADB folder.
adb pull /system/app backup/installedapps backs up all the installed apps of your phone to the installedapps folder that you created in the ADB folder.
Background Terminal
adb shell starts the background terminal.
exit exits the background terminal.
adb shell e.g adb shell su switches to the root of your phone. Please make sure that you’re rooted in case you wish to use adb shell su.
Fastboot commandsTo flash files using fastboot, place the desired files in Fastboot folder or Platform-tools folder that you obtained after installation of Android SDK tools.
Fastboot Flash File.zip Flashes a .zip file to your phone, when your phone is connected in Fastboot mode.
Fastboot Flash recovery recoveryname.img Flashes a recovery to your phone when it’s connected in Fastboot mode.
Fastboot flash boot bootname.img Flashes a boot or kernel image when your phone is connected in Fastboot mode.
Fastboot getvar cid shows you the CID of your phone.
Fastboot oem writeCID xxxxx writes the super CID.
**fastboot erase system ** **fastboot erase data ** fastboot erase cache In case you want to restore a nandroid backup, you’ll have to delete the current system/data/cache of your phone first. Before doing this, it is always recommended to have backed up your system using a custom recovery>backup option and copy the backed up .img files to Fastboot or Platform-tools folder in Android SDK folder. Then performing these commands will erase everything.
**fastboot flash system system.img ** **fastboot flash data data.img ** fastboot flash cache cache.img These commands will restore the backup that you made using a custom recovery on your phone and placed in the Fastboot folder under Android SDK tools.
**fastboot oem get_unlock_data fastboot oem unlock UNIQUE_KEY fastboot oem get_identifier_token ** fastboot oem flash Unlock_code.bin ** ** fastboot oem lock These commands help you to get the identifier token of your phone that can be used for unlocking the bootloader. The second command helps your to flash the bootloader unlock code, and the 3rd commands helps you to lock your phone’s bootloader once again if locking it is actually allowed.
Logcat
adb logcat Shows you the real time logs of your phone, these logs represent the ongoing process on your device.It is recommended that you run this command while your device boots up to check what’s going on.
adb logcat > logcat.txt Creates a .txt file containing the logs in the Platform-tools folder or Fastboot folder in Android SDK tools directory.