使用 adb fastboot 全新安装 Nexus 设备
Last updated on 4 年前 by ueaner
系统环境:
- "takju" for Galaxy Nexus "maguro"
- adb v1.0.31
题外话:如果仅仅需要升级一下系统的话,可以查看此篇文章 使用 adb sideload 手动更新 android 4.3。
安装 fastboot
如果没有 adb 和 fastboot 命令,请移步:Linux 下使用 adb 和 fastboot 命令。
下载 Android 工厂镜像
到 Factory Images for Nexus Devices 下载你喜欢的 Android 工厂镜像文件。
我的 Android 设备是 "takju" for Galaxy Nexus,下载最新的 4.3 (JWR66V) 版本:
> wget -c https://dl.google.com/dl/android/aosp/takju-jwr66v-factory-c2ef855e.tgz --no-check-certificate
> tar xf takju-jwr66v-factory-c2ef855e.tgz
> cd takju-jwr66v
约 286M 的包,我们可以先备份数据等待下载完成。
备份数据
备份 APK:
> adb backup -apk -all -nosystem -f backup.ab
Now unlock your device and confirm the backup operation.
此时手机会弹出 完全备份
的提示,输入密码(记住这个密码还原时用),点击备份我的数据即可。手机上会实时显示正在备份的数据。
大概 5 分钟(视手机安装的应用数量及大小而定)备份完成,手机会提示备份已完成,电脑上会产生 backup.ab
文件,用于恢复。
不建议使用 -shared 参数备份 SD 卡数据,如果你的 SD 卡存放过多数据的话,恢复的时候会有一个漫长的时间等待。
备份 SD 卡其他数据,如:图片,文档,思维导图,视频等:
> mkdir backup_data
> adb pull /sdcard/will_backup_data/ backup_data/
全新安装
> adb reboot bootloader
> fastboot devices
no permissions fastboot
如果出现 no permissions fastboot
:使用 sudo -s
切换到 root 账户。
> sudo -s
[sudo] password for ueaner:
# fastboot devices
0146A14F07012020 fastboot
可以看到我们的设备了,之后我们只需两步即可完成:
1) 进入 bootloader 模式
2) 执行 ./flash-all.sh
注意:你的 fastboot 是需要在环境变量 $PATH 的范围内,我们上边已经做了软链,现在直接运行:
# fastboot reboot-bootloader
rebooting into bootloader...
OKAY [ 0.006s]
finished. total time: 0.037s
# ./flash-all.sh
sending 'bootloader' (2308 KB)...
OKAY [ 0.310s]
writing 'bootloader'...
OKAY [ 0.538s]
finished. total time: 0.848s
rebooting into bootloader...
OKAY [ 0.006s]
finished. total time: 0.006s
< waiting for device >
sending 'radio' (12288 KB)...
OKAY [ 1.625s]
writing 'radio'...
OKAY [ 1.624s]
finished. total time: 3.249s
rebooting into bootloader...
OKAY [ 0.006s]
finished. total time: 0.006s
< waiting for device >
archive does not contain 'boot.sig'
archive does not contain 'recovery.sig'
archive does not contain 'system.sig'
--------------------------------------------
Bootloader Version...: PRIMEMD04
Baseband Version.....: I9250XXLJ1
Serial Number........: 0146A14F07012020
--------------------------------------------
checking product...
OKAY [ 0.007s]
checking version-bootloader...
OKAY [ 0.007s]
checking version-baseband...
OKAY [ 0.007s]
sending 'boot' (4376 KB)...
OKAY [ 0.586s]
writing 'boot'...
OKAY [ 0.460s]
sending 'recovery' (4924 KB)...
OKAY [ 0.658s]
writing 'recovery'...
OKAY [ 0.707s]
erasing 'system'...
OKAY [ 0.065s]
sending 'system' (479244 KB)...
OKAY [ 63.371s]
writing 'system'...
OKAY [ 47.852s]
erasing 'userdata'...
OKAY [ 1.367s]
formatting 'userdata' partition...
Creating filesystem with parameters:
Size: 14539534336
Block size: 4096
Blocks per group: 32768
Inodes per group: 8144
Inode size: 256
Journal blocks: 32768
Label:
Blocks: 3549691
Block groups: 109
Reserved block group size: 871
Created filesystem with 11/887696 inodes and 97200/3549691 blocks
sending 'userdata' (137559 KB)...
writing 'userdata'...
OKAY [ 29.944s]
erasing 'cache'...
OKAY [ 0.036s]
formatting 'cache' partition...
Creating filesystem with parameters:
Size: 452984832
Block size: 4096
Blocks per group: 32768
Inodes per group: 6912
Inode size: 256
Journal blocks: 1728
Label:
Blocks: 110592
Block groups: 4
Reserved block group size: 31
Created filesystem with 11/27648 inodes and 3566/110592 blocks
sending 'cache' (8832 KB)...
writing 'cache'...
OKAY [ 3.367s]
rebooting...
finished. total time: 148.469s
我们只需要等待手机启动,可以看到 欢迎使用
选择语言了。
恢复数据
当然第一步要做的就是启用开发者模式跟 4.2.x 版本一样,到:设置 -> 关于手机 -> 狂点版本号(直到看到已开启开发者选项)
返回,点击开发者选项:打开 USB 调试。
恢复APK:
adb restore backup.ab
Now unlock your device and confirm the restore operation.
手机会提示 完全还原
输入备份时的密码,点击恢复我的数据即可。
大约 15 分钟终于恢复完了,是备份时的 3 倍啊。不过恢复的效果不错,游戏数据都在。
恢复其他数据:
> adb push backup_data/ /sdcard/will_restore_data/
至此我们整个刷机过程完成。
附:简析 flash-all.sh
现在我们看一下 flash-all.sh
都写了些什么呢?
> cat flash-all.sh
#!/bin/sh
# 注释部分略
fastboot flash bootloader bootloader-maguro-primemd04.img
fastboot reboot-bootloader
sleep 5
fastboot flash radio radio-maguro-i9250xxlj1.img
fastboot reboot-bootloader
sleep 5
fastboot -w update image-takju-jwr66v.zip
对比一下 takju-jwr66v
目录下的文件:
> ls
bootloader-maguro-primemd04.img [+]
flash-all.bat
flash-all.sh [+]
flash-base.sh
image-takju-jwr66v.zip [+]
radio-maguro-i9250xxlj1.img [+]
再从输出到终端的信息又可以知道 fastboot -w update image-takju-jwr66v.zip
做了这么几件事:
- writing 'boot'...
- writing 'recovery'...
- writing 'system'...
- writing 'userdata'...
- (erasing 'cache'...) writing 'cache'...
解压 image-takju-jwr66v.zip
文件,看一下:
> unzip image-takju-jwr66v.zip
Archive: image-takju-jwr66v.zip
inflating: boot.img
inflating: recovery.img
inflating: system.img
inflating: userdata.img
inflating: android-info.txt
所以如果想一步一步刷的话:
1. adb reboot-bootloaders
2. fastboot flash bootloader bootloader-maguro-primemd04.img
3. fastboot reboot-bootloader
4. fastboot flash radio radio-maguro-i9250xxlj1.img
5. fastboot reboot-bootloader
6. fastboot flash boot boot.img
7. fastboot flash recovery recovery.img
8. fastboot flash system system.img
9. fastboot flash userdata userdata.img
10.fastboot erase cache
11.fastboot reboot
Good Luck!
转载请注明出处。
本文地址:http://blog.aboutc.net/post/linux/android-adb-fastboot