android 虽然是linux 系统,可以通过adb shell 登录执行一些linux命令;但是毕竟它是一个精简版的linux。很多常规linux 系统内置命令都没有带。恰好有个叫busybox的套件,打包了一些常用的linux命令,让我们更加方便的使用命令行操作android
本文使用的手机的是 google nexus 5 手机,这个手机非常适合用来真机调试源码。建议大家使用这个,网上400元可以淘一个
一、先要把手机Root
这个可以参考我另外一篇android nexus 5 手机解锁-刷机-root教程
二、下载BusyBox 安装包
下载地址为。有很多版本可以选择最新版本。
一般真机都是arm 芯片,但是arm包也有好几个。到底选择哪一个呢。
先查一下我们真机的cpu指令架构
-
stevenrao@~$ adb shell
-
-
shell@hammerhead:/ $
-
-
1|shell@hammerhead:/ $ cat /proc/cpuinfo
-
-
Processor : ARMv7 Processor rev 0 (v7l)
-
-
processor : 0
-
-
BogoMIPS : 38.40
-
-
processor : 1
-
-
BogoMIPS : 38.40
-
-
processor : 2
-
-
BogoMIPS : 38.40
-
-
processor : 3
-
-
BogoMIPS : 38.40
-
-
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt
-
-
CPU implementer : 0x51
-
-
CPU architecture: 7
-
-
CPU variant : 0x2
-
-
CPU part : 0x06f
-
-
CPU revision : 0
-
-
Hardware : Qualcomm MSM 8974 HAMMERHEAD (Flattened Device Tree)
-
-
Revision : 000b
-
-
Serial : 0000000000000000
这里我就选择 busybox-armv6l 吧,这个向下兼容的。下载
wget 'https://busybox.net/downloads/binaries/1.26.2-defconfig-multiarch/busybox-armv6l
三、安装BusyBox
1、把下载包copy到真机上
-
a、先登录真机上创建一个临时目录
-
stevenrao@~$ adb shell
-
shell@hammerhead:/ $ su
-
root@hammerhead:/
-
root@hammerhead:/ # cd /data/
-
root@hammerhead:/data # mkdir tmp
-
root@hammerhead:/data # chmod 777 tmp
-
root@hammerhead:/data # exit
-
shell@hammerhead:/ $ exit
-
b、copy文件到临时目录
-
stevenrao@~$ adb push busybox-armv6l /data/tmp/
-
busybox-armv6l: 1 file pushed. 6.0 MB/s (1107664 bytes in 0.175s)
-
stevenrao@~$ adb shell ls /data/tmp
-
busybox-armv6l
2、安装到系统目录/system/xbin/
/system/xbin/ 目录是没有读写权限的,这里需要修改权限,直接用root用户chmod是不行的
-
root@hammerhead:/data/tmp # chmod 777 /system/xbin/
-
Unable to chmod /system/xbin/: Read-only file system
是因为mout的时候就是只读的。我们需要重新mount,先查看system mount是那个设备
-
1|root@hammerhead:/data/tmp # ll /dev/block/platform/msm_sdcc.1/by-name/
-
lrwxrwxrwx root root 1970-04-06 09:13 DDR -> /dev/block/mmcblk0p24
-
lrwxrwxrwx root root 1970-04-06 09:13 aboot -> /dev/block/mmcblk0p6
-
lrwxrwxrwx root root 1970-04-06 09:13 abootb -> /dev/block/mmcblk0p11
-
lrwxrwxrwx root root 1970-04-06 09:13 boot -> /dev/block/mmcblk0p19
-
lrwxrwxrwx root root 1970-04-06 09:13 cache -> /dev/block/mmcblk0p27
-
lrwxrwxrwx root root 1970-04-06 09:13 crypto -> /dev/block/mmcblk0p26
-
lrwxrwxrwx root root 1970-04-06 09:13 fsc -> /dev/block/mmcblk0p22
-
lrwxrwxrwx root root 1970-04-06 09:13 fsg -> /dev/block/mmcblk0p21
-
lrwxrwxrwx root root 1970-04-06 09:13 grow -> /dev/block/mmcblk0p29
-
lrwxrwxrwx root root 1970-04-06 09:13 imgdata -> /dev/block/mmcblk0p17
-
lrwxrwxrwx root root 1970-04-06 09:13 laf -> /dev/block/mmcblk0p18
-
lrwxrwxrwx root root 1970-04-06 09:13 metadata -> /dev/block/mmcblk0p14
-
lrwxrwxrwx root root 1970-04-06 09:13 misc -> /dev/block/mmcblk0p15
-
lrwxrwxrwx root root 1970-04-06 09:13 modem -> /dev/block/mmcblk0p1
-
lrwxrwxrwx root root 1970-04-06 09:13 modemst1 -> /dev/block/mmcblk0p12
-
lrwxrwxrwx root root 1970-04-06 09:13 modemst2 -> /dev/block/mmcblk0p13
-
lrwxrwxrwx root root 1970-04-06 09:13 pad -> /dev/block/mmcblk0p7
-
lrwxrwxrwx root root 1970-04-06 09:13 persist -> /dev/block/mmcblk0p16
-
lrwxrwxrwx root root 1970-04-06 09:13 recovery -> /dev/block/mmcblk0p20
-
lrwxrwxrwx root root 1970-04-06 09:13 rpm -> /dev/block/mmcblk0p3
-
lrwxrwxrwx root root 1970-04-06 09:13 rpmb -> /dev/block/mmcblk0p10
-
lrwxrwxrwx root root 1970-04-06 09:13 sbl1 -> /dev/block/mmcblk0p2
-
lrwxrwxrwx root root 1970-04-06 09:13 sbl1b -> /dev/block/mmcblk0p8
-
lrwxrwxrwx root root 1970-04-06 09:13 sdi -> /dev/block/mmcblk0p5
-
lrwxrwxrwx root root 1970-04-06 09:13 ssd -> /dev/block/mmcblk0p23
-
lrwxrwxrwx root root 1970-04-06 09:13 system -> /dev/block/mmcblk0p25
-
lrwxrwxrwx root root 1970-04-06 09:13 tz -> /dev/block/mmcblk0p4
-
lrwxrwxrwx root root 1970-04-06 09:13 tzb -> /dev/block/mmcblk0p9
-
lrwxrwxrwx root root 1970-04-06 09:13 userdata -> /dev/block/mmcblk0p28
重新mount, 修改权限
-
stevenrao@~$ adb shell
-
shell@hammerhead:/ $ su
-
root@hammerhead:/ # mount -o remount,rw /dev/block/mmcblk0p25 /system
-
root@hammerhead:/ # chmod 777 /system
-
root@hammerhead:/ # chmod 777 /system/xbin
-
root@hammerhead:/data/tmp # ./busybox-armv6l --install /system/xbin/
-
busybox-armv6l: /system/xbin/[: Invalid cross-device link
-
busybox-armv6l: /system/xbin/[[: Invalid cross-device link
-
busybox-armv6l: /system/xbin/acpid: Invalid cross-device link
-
busybox-armv6l: /system/xbin/add-shell: Invalid cross-device link
-
busybox-armv6l: /system/xbin/addgroup: Invalid cross-device link
-
busybox-armv6l: /system/xbin/adduser: Invalid cross-device link
出现错误。 是跨设备存储问题。copy到 /system/xbin/ 下重新执行吧
-
root@hammerhead:/data/tmp # cd /system/xbin
-
root@hammerhead:/system/xbin # cp /data/tmp/busybox-armv6l ./
-
root@hammerhead:/system/xbin # ./busybox-armv6l --install .
安装成功
四、测试
-
root@hammerhead:/data/tmp # md5sum busybox-armv6l
-
af177e4a17185a5235f9c1a0ea15e1f8 busybox-armv6l
md5sum 这个命令系统之前是没有的
阅读(5395) | 评论(0) | 转发(0) |