目 录CONTENT

文章目录

小米路由开机启动

过客
2025-07-07 / 0 评论 / 0 点赞 / 16 阅读 / 0 字

小米路由器的小强系统是定制版的OpenWRT,修改配置 /etc/rc.local,每次重启都会还原。最后可以基于防火墙启动脚 /etc/config/firewall 来实现。

一、创建脚本

创建 /data/startup_script.sh 脚本,把需要启动代码或脚本放到 startup_script 函数中就可以了。

#!/bin/sh
install() {
        # Add script to system autostart docker
        uci set firewall.startup_script=include
        uci set firewall.startup_script.type='script'
        uci set firewall.startup_script.path="/data/startup_script.sh"
        uci set firewall.startup_script.enabled='1'
        uci commit firewall
        echo -e "\033[32m  startup_script complete. \033[0m"
}
uninstall() {
    # Remove scripts from system autostart
    uci delete firewall.startup_script
    uci commit firewall
    echo -e "\033[33m startup_script  has been removed. \033[0m"
}

startup_script() {
        # 这里是开机启动时要运行的代码
        echo "Starting custom scripts..."
}

main() {
    [ -z "$1" ] && startup_script && return
    case "$1" in
    install)
        install
        ;;
    uninstall)
        uninstall
        ;;
    *)
        echo -e "\033[31m Unknown parameter: $1 \033[0m"
        return 1
        ;;
    esac
}


main "$@"

二、给予脚本执行权限

chmod +x /data/startup_script.sh

三、安装脚本

/data/startup_script.sh install

执行完这句install命令,你会发现/etc/config/firewall最后会添加这样一段内容

config include 'startup_script'
        option type 'script'
        option path '/data/startup_script.sh'
        option enabled '1'
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区