在OpenHarmony中使用busybox
下載busybox
頁面:https://busybox.net/downloads/binaries/
地址:https://busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-armv7r
獲取讀寫權限
hdc smode
hdc shell mount -oremount,rw /
安裝busybox
hdc file send busybox-armv7r /system/bin/busybox
hdc shell chmod a+x /system/bin/busybox
hdc shell mkdir /system/busybox
hdc shell busybox --install -s /system/busybox
使用busybox環境
hdc shell
export PATH="$PATH:/system/busybox"
現在你可以盡情的使用常見的linux命令
# 如以下命令
ifconfig -a
ping 127.0.0.1
vi /etc/prop.default
訪問網路
-
推送udhcpc.script到開發板
hdc smode hdc shell mount -oremount,rw / hdc file send udhcpc.script /system/busybox/udhcpc.script hdc shell chmod a+x /system/busybox/udhcpc.scriptudhcpc.script內容如下
#!/system/bin/sh # file: udhcpc.script case $1 in bound|renew) [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" [ -n "$subnet" ] && NETMASK="netmask $subnet" ifconfig $interface $ip $BROADCAST $NETMASK ? if [ -n "$router" ]; then ip route del default >/dev/null ip route add default via $router fi ? if [ -n "$dns" ]; then rm /data/local/tmp/busybox-resolv.conf -f for i in $dns; do echo "nameserver $i" >> /data/local/tmp/busybox-resolv.conf done ln -sf /data/local/tmp/busybox-resolv.conf /etc/resolv.conf fi esac -
將開發板的網線插在路由器上
hdc shell export PATH="$PATH:/system/busybox" # 使能eth0 ifconfig eth0 up udhcpc -i eth0 -s /system/busybox/udhcpc.script # 檢查網路連通 ping www.baidu.com -c 4 # 獲取公網IP地址 wget -O- http://checkip.amazonaws.com 2>/dev/null
其他說明
注意:本篇文章中提供的busybox使用musl作為C庫,所以nameserver需要用到/etc/resolv.conf檔案,但openharmony標準系統并不需要用到這個檔案,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/286734.html
標籤:其他
