由于BE6500PRO开机会重置文件,因此使用脚本实现Overlay挂载和软件源更换

一、挂载Overlay

  1. 在/data/scripts文件夹下创建脚本
vi /data/scripts/auto_overlay.sh

粘贴以下内容

#!/bin/sh
script_dir="/data/scripts"
overlay_dir="/data/other/overlay"
overlay_mount_point="/overlay"

mount_overlay() {
    # Check and create overlay directory and its subdirectories
    [ -e overlay_dir ] || mkdir -poverlay_dir
    [ -e overlay_dir/upper ] || mkdir -poverlay_dir/upper
    [ -e overlay_dir/work ] || mkdir -poverlay_dir/work
    # Bind the overlay directory to the mount point
    mount --bind overlay_diroverlay_mount_point
    # Source functions from the preinit script
    . /lib/functions/preinit.sh
    # Use fopivot to combine upper and work directories with /rom
    fopivot overlay_mount_point/upperoverlay_mount_point/work /rom 1
    # Move and mount various directories to new locations
    /bin/mount -o noatime,move /rom/data /data 2>&-
    /bin/mount -o noatime,move /rom/etc /etc 2>&-
    /bin/mount -o noatime,move /rom/ini /ini 2>&-
    /bin/mount -o noatime,move /rom/userdisk /userdisk 2>&-
    echo -e "\033[32m Overlay mount complete. \033[0m"
}

install() {
    # Install overlay mount
    mount_overlay
    # Set firewall rules to include the auto mount script
    uci set firewall.auto_overlay=include
    uci set firewall.auto_overlay.type='script'
    uci set firewall.auto_overlay.path="{script_dir}/auto_overlay.sh"
    uci set firewall.auto_overlay.enabled='1'
    uci commit firewall
    echo -e "\033[32m Overlay auto-mount installed. \033[0m"
}

uninstall() {
    # Delete the auto mount firewall rule
    uci delete firewall.auto_overlay
    uci commit firewall
    echo -e "\033[33m Overlay auto-mount uninstalled. \033[0m"
}

main() {
    # If no parameter is provided, mount the overlay
    [ -z "1" ] && mount_overlay && return
    case "1" in
    install)
        install
        ;;
    uninstall)
        uninstall
        ;;
    *)
        # Handle unknown parameters
        echo -e "\033[31m Unknown parameter:1 \033[0m"
        return 1
        ;;
    esac
}

main "$@"

:wq保存退出

BE6500PRO的/data/other_vol和/data/other分区较大,此处选择了/data/other作为/overlay的挂载点

  1. 添加脚本运行权限
chmod +x /data/scripts/auto_overlay.sh

3.安装自动挂载服务

/data/scripts/auto_overlay.sh install

如果要卸载服务:

/data/scripts/auto_overlay.sh uninstall

二、更换软件源

小米官方固件内的软件源并不存在,我们需要更换他
同样使用脚本实现自动更换
1、在/data/scripts文件夹下创建脚本

vi /data/scripts/change_opkg_sources.sh

右键粘贴以下内容

#!/bin/sh
script_dir="/data/scripts"

change_sources() {
    # Modify Architecture Arguments
    cp /etc/opkg.conf /etc/opkg.conf.bak
    echo -e "arch all 100\narch aarch64_cortex-a53_neon-vfpv4 200\narch aarch64_cortex-a53 300" >> /etc/opkg.conf
    # Change opkg sources
    mv /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf.bak
    echo -e "src/gz openwrt_base http://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/base" >> /etc/opkg/distfeeds.conf
    echo -e "src/gz openwrt_luci http://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/luci" >> /etc/opkg/distfeeds.conf
    echo -e "src/gz openwrt_packages http://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/packages" >> /etc/opkg/distfeeds.conf
    echo -e "src/gz openwrt_routing http://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/routing" >> /etc/opkg/distfeeds.conf
    echo -e "src/gz openwrt_telephony http://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/telephony" >> /etc/opkg/distfeeds.conf
}

install() {
    change_sources

    #Auto Start Using Firewall
    uci set firewall.change_opkg_sources=include
    uci set firewall.change_opkg_sources.type='script'
    uci set firewall.change_opkg_sources.path="{script_dir}/change_opkg_sources.sh"
    uci set firewall.change_opkg_sources.enabled='1'
    uci commit firewall
    echo -e "\033[32m Auto Opkg Source Change installed. \033[0m"
}

uninstall() {
    # Remove firewall rules
    uci delete change_opkg_sources
    uci commit firewall
    mv /etc/opkg/distfeeds.conf.bak /etc/opkg/distfeeds.conf
    mv /etc/opkg.conf.bak /etc/opkg.conf
    echo -e "\033[33m Auto Opkg Source Change uninstalled. \033[0m"
}

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

main "$@"

:wq保存退出

  1. 添加脚本运行权限
chmod +x /data/scripts/change_opkg_sources.sh

3.安装自动挂载服务

/data/scripts/change_opkg_sources.sh install

如果要卸载服务:

/data/scripts/change_opkg_sources.sh uninstall

4、更新软件包列表

opkg update

然后就可以安装一些openwrt软件了,比如要按安装sftp

opkg install openssh-sftp-server