一、Recovery预制busybox
如何预制自行查找
二、进入recovery连接adb 调试DHCP
命令:busybox udhcpc -s /cache/simple.script
看是否会报错,获取IP并设置IP
我遇到的错误
udhcpc: exec /usr/share/udhcpc/default.script: No such file or directory
recovery 模式默认没有这个脚本,需要自己预制脚本加 -s参数指定脚本
udhcpc: exec /cache/simple.script: No such file or directory
这个问题排查好久,起初以为是脚本开头#!/bin/sh的bin/sh不存在导致,修改为/sbin/sh后还是报错。
删除该行后不报这个错误,又报udhcpc: exec /cache/simple.script: Exec format error
这就奇怪了,将脚本删除仅剩一行echo 1111调试语句还是报错。单独执行这个脚本没有问题。
最后网上看到这个脚本是来自busybox 的源代码,想着会不会是复制粘贴过程导致编码等格式导致的?
换用源码中的simple.script后并修改为/sbin/sh执行
/sbin/sh simple.script deconfig
Setting IP address 0.0.0.0 on
simple.script[50]: ifconfig: not found
# /sbin/sh simple.script bound
Setting IP address on
simple.script[50]: ifconfig: not found
Recreating /etc/resolv.conf
simple.script[50]: mv: not found
# /sbin/sh udhcpc.sh
好了,只报命令找不到,然后修改脚本在命令前加 busybox 完美解决!!
注:原生脚本不修改/sbin/sh也是报No such file or directory
总结:脚本文件还是用原生的,尽量在Linux下写,否则遇到编码格式类错误很难排查,走很多弯路
三、调试成功,将命令写入init.rc自动运行
但需注意selinux的问题,虽然不开selinux仍然需要打标签的
service dhcp /sbin/busybox udhcpc -s /cache/simple.script
disabled
user root
oneshot
seclabel u:r:shell:s0
附修改后脚本,注意在Linux下粘贴!!!!
#!/sbin/sh
# udhcpc script edited by Tim Riker <[email protected]>
RESOLV_CONF="/etc/resolv.conf"
[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
case "$1" in
deconfig)
echo "Setting IP address 0.0.0.0 on $interface"
busybox ifconfig $interface 0.0.0.0
;;
renew|bound)
echo "Setting IP address $ip on $interface"
busybox ifconfig $interface $ip $NETMASK $BROADCAST
if [ -n "$router" ] ; then
echo "Deleting routers"
while busybox route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
echo "Adding router $i"
busybox route add default gw $i dev $interface metric $metric
: $(( metric += 1 ))
done
fi
echo "Recreating $RESOLV_CONF"
# If the file is a symlink somewhere (like /etc/resolv.conf
# pointing to /run/resolv.conf), make sure things work.
realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
tmpfile="$realconf-$$"
> "$tmpfile"
[ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
for i in $dns ; do
echo " Adding DNS server $i"
echo "nameserver $i" >> "$tmpfile"
done
busybox mv "$tmpfile" "$realconf"
;;
esac
exit 0