前 提:
有root权限
备份恢复boot/system分区为例
先查看分区信息:
方法一 :
命令:ls -l /dev/block/platform/mtk-msdc.0/by-name/
root@GiONEE_GBL7319:/ # ls -l /dev/block/platform/mtk-msdc.0/by-name/
lrwxrwxrwx root root 2022-05-20 21:16 boot -> /dev/block/mmcblk0p7
lrwxrwxrwx root root 2022-05-20 21:16 cache -> /dev/block/mmcblk0p21
lrwxrwxrwx root root 2022-05-20 21:16 expdb -> /dev/block/mmcblk0p10
lrwxrwxrwx root root 2022-05-20 21:16 flashinfo -> /dev/block/mmcblk0p23
lrwxrwxrwx root root 2022-05-20 21:16 frp -> /dev/block/mmcblk0p17
lrwxrwxrwx root root 2022-05-20 21:16 keystore -> /dev/block/mmcblk0p14
lrwxrwxrwx root root 2022-05-20 21:16 lk -> /dev/block/mmcblk0p5
lrwxrwxrwx root root 2022-05-20 21:16 logo -> /dev/block/mmcblk0p9
lrwxrwxrwx root root 2022-05-20 21:16 metadata -> /dev/block/mmcblk0p19
lrwxrwxrwx root root 2022-05-20 21:16 nvdata -> /dev/block/mmcblk0p18
lrwxrwxrwx root root 2022-05-20 21:16 nvram -> /dev/block/mmcblk0p2
lrwxrwxrwx root root 2022-05-20 21:16 oemkeystore -> /dev/block/mmcblk0p12
lrwxrwxrwx root root 2022-05-20 21:16 para -> /dev/block/mmcblk0p6
lrwxrwxrwx root root 2022-05-20 21:16 proinfo -> /dev/block/mmcblk0p1
lrwxrwxrwx root root 2022-05-20 21:16 protect1 -> /dev/block/mmcblk0p3
lrwxrwxrwx root root 2022-05-20 21:16 protect2 -> /dev/block/mmcblk0p4
lrwxrwxrwx root root 2022-05-20 21:16 recovery -> /dev/block/mmcblk0p8
lrwxrwxrwx root root 2022-05-20 21:16 seccfg -> /dev/block/mmcblk0p11
lrwxrwxrwx root root 2022-05-20 21:16 secro -> /dev/block/mmcblk0p13
lrwxrwxrwx root root 2022-05-20 21:16 system -> /dev/block/mmcblk0p20
lrwxrwxrwx root root 2022-05-20 21:16 tee1 -> /dev/block/mmcblk0p15
lrwxrwxrwx root root 2022-05-20 21:16 tee2 -> /dev/block/mmcblk0p16
lrwxrwxrwx root root 2022-05-20 21:16 userdata -> /dev/block/mmcblk0p22
boot分区对应实际的目录是/dev/block/mmcblk0p7
方法二:
根目录/下的fstab.xxx和/dev/recovery.fstab也可查相关信息
备 份:
方法一:cat
命令:cat /dev/block/mmcblk0p7 > /sdcard/bootBAK.img
root@GiONEE_GBL7319:/ # cat /dev/block/mmcblk0p7 > /sdcard/bootBAK.img
查看结果:
root@GiONEE_GBL7319:/ # ls -l /sdcard/boot*
-rw-rw---- root sdcard_r 7145472 2015-06-30 07:04 boot.img
-rw-rw---- root sdcard_r 16777216 2022-05-20 21:45 bootBAK.img
-rw-rw---- root sdcard_r 7485440 2022-02-28 08:22 bootF103_magisk.img
bootBAK.img大小是16777216字节
对比一下:
先查看分区大小
命令:cat /proc/partitions
root@GiONEE_GBL7319:/ # cat /proc/partitions
major minor #blocks name
254 0 491520 zram0
7 0 18944 loop0
179 0 15267840 mmcblk0
179 1 3072 mmcblk0p1
179 2 5120 mmcblk0p2
179 3 10240 mmcblk0p3
179 4 10240 mmcblk0p4
179 5 512 mmcblk0p5
179 6 512 mmcblk0p6
179 7 16384 mmcblk0p7 对应boot分区
179 8 16384 mmcblk0p8
179 9 8192 mmcblk0p9
179 10 10240 mmcblk0p10
179 11 512 mmcblk0p11
179 12 2048 mmcblk0p12
179 13 6144 mmcblk0p13
179 14 8192 mmcblk0p14
179 15 5120 mmcblk0p15
179 16 5120 mmcblk0p16
179 17 1024 mmcblk0p17
179 18 32768 mmcblk0p18
179 19 37888 mmcblk0p19
179 20 2097152 mmcblk0p20
179 21 409600 mmcblk0p21
179 22 12563968 mmcblk0p22
179 23 16384 mmcblk0p23
179 96 4096 mmcblk0rpmb
179 64 4096 mmcblk0boot1
179 32 4096 mmcblk0boot0
mmcblk0p7的blocks是16384块,每块大小1024字节
boot大小 = 16384 * 1024 = 16777216字节,与备份出来的大小一样。
方法二:dd
命令:dd if=/dev/block/mmcblk0p7 of=/sdcard/bootBAK2.img
1|root@GiONEE_GBL7319:/ # dd if=/dev/block/mmcblk0p7 of=/sdcard/bootBAK2.img
32768+0 records in
32768+0 records out
16777216 bytes transferred in 2.001 secs (8384415 bytes/sec)
或者:
dd if=/dev/block/mmcblk0p7 of=/sdcard/bootBAK2.img bs=1024 count=16384
命令说明 :
- if 表示输入(数据源)
- of 表示输出(备份到哪)
- bs 即blocks
- count 是多少个bs
结果:
root@GiONEE_GBL7319:/ # ls -l /sdcard/boot*
-rw-rw---- root sdcard_r 7145472 2015-06-30 07:04 boot.img
-rw-rw---- root sdcard_r 16777216 2022-05-20 21:45 bootBAK.img
-rw-rw---- root sdcard_r 16777216 2022-05-20 21:56 bootBAK2.img
-rw-rw---- root sdcard_r 7485440 2022-02-28 08:22 bootF103_magisk.img
方法三:cpio
命令:find /system -print | cpio -ovd -H newc > /sdcard/system.cpio
root@GiONEE_GBL7319:/ # find /system -print | busybox cpio -ovd -H newc > /sdcard/system.cpio
root@GiONEE_GBL7319:/ # ls -l /sdcard/system*
-rw-rw---- root sdcard_r 1916820332 2022-05-25 23:11 system.cpio
root@GiONEE_GBL7319:/ # file /sdcard/system.cpio
/sdcard/system.cpio: ASCII cpio archive (SVR4 with no CRC)
方法四:tar
命令:tar cvzpf system-bak0526.tar.gz --exclude=/system/lost+found --exclude=/system/recovery-from-boot.bak /system
备份/system时排除掉./lost+found , recovery-from-boot.bak
先查看/system数据:
c:\tmp\fastboot>adb shell
shell@GiONEE_GBL7319:/ $ su
root@GiONEE_GBL7319:/ # ls /system
app
bin
build.prop
data
etc
fonts
framework
lib
lib64
lost+found
media
plugin
priv-app
recovery-from-boot.bak
res
tts
usr
vendor
xbin
执行备份:
root@GiONEE_GBL7319:/ # cd /sdcard
root@GiONEE_GBL7319:/sdcard # busybox tar cvzpf system-bak0526.tar.gz --exclude=/system/lost+found --exclude=/system/recovery-from-boot.bak /system
参数说明:
- -c 建立压缩文件
- -x 解开压缩文件
- -v 显示列表
- -z 用gzip进行压缩
- -p 保留原来的属性
- -f 指定压缩文档名
- –exclude 排除的文件或目录
查看结果:
root@GiONEE_GBL7319:/sdcard # ll sys*
-rw-rw---- root sdcard_r 1132545851 2022-05-26 16:04 system-bak0526.tar.gz
130|root@GiONEE_GBL7319:/sdcard # busybox tar -tf system-bak0526.tar.gz|grep flash_image
system/xbin/flash_image
===========================
恢 复 分 区/数据:
方法一:dd
命令:dd if=/sdcard/bootBAK2.img of=/dev/block/mmcblk0p7
root@GiONEE_GBL7319:/ # dd if=/sdcard/bootBAK2.img of=/dev/block/mmcblk0p7
方法二:fastboot flash
命令:fastboot flash boot bootBAK2.img
c:\tmp\fastboot>adb reboot bootloader
c:\tmp\fastboot>fastboot devices
8T8HBIZSBU9PCM4S fastboot
c:\tmp\fastboot>fastboot flash boot bootBAK2.img
方法三:flash_image
命令:flash_image partition file.img
有时候partition不识别boot, 则改为/dev/block/mmcblk0p7试试
root@GiONEE_GBL7319:/ # flash_image boot /sdcard/bootBAK2.img
failed with error: -1
root@GiONEE_GBL7319:/ # flash_image /dev/block/mmcblk0p7 /sdcard/bootBAK2.img
方法四:cpio
命令:cpio -iuvd < /sdcard/system.cpio
参数说明:
- -i 将数据文件复制到系统中,copy-in
- -o 将系统数据复制成文件,copy-out
- -u 自动将较新文件覆盖旧文件
- -v 显示清单
- -d 自动建立目录
- -p 原版备份,不进行额外处理
- -H format
format有如下格式:
bin : The obsolete binary format. (2147483647 bytes)
odc : The old (POSIX.1) portable format. (8589934591 bytes)
newc : The new (SVR4) portable format, which supports file systems having more than 65536 i-nodes. (4294967295 bytes)
另外说明 :
dd命令可备份 :文件、分区、磁盘、光盘等
用法说明:文章来源:https://www.toymoban.com/news/detail-500463.html
Usage: dd [if=FILE] [of=FILE] [ibs=N obs=N/bs=N] [count=N] [skip=N] [seek=N]
[conv=notrunc|noerror|sync|fsync]
[iflag=skip_bytes|fullblock] [oflag=seek_bytes|append]
Copy a file with converting and formatting
if=FILE Read from FILE instead of stdin
of=FILE Write to FILE instead of stdout
bs=N Read and write N bytes at a time
ibs=N Read N bytes at a time
obs=N Write N bytes at a time
count=N Copy only N input blocks
skip=N Skip N input blocks
seek=N Skip N output blocks
conv=notrunc Don't truncate output file
conv=noerror Continue after read errors
conv=sync Pad blocks with zeros
conv=fsync Physically write data out before finishing
conv=swab Swap every pair of bytes
iflag=skip_bytes skip=N is in bytes
iflag=fullblock Read full blocks
oflag=seek_bytes seek=N is in bytes
oflag=append Open output file in append mode
status=noxfer Suppress rate output
status=none Suppress all output
N may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G
/dev/null : 回收站
/dev/zero :生成0字符文章来源地址https://www.toymoban.com/news/detail-500463.html
到了这里,关于手机备份/恢复分区(boot/system/userdata)、数据的几种方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!