编译技巧

# 自用编译的镜像, 不要使用root帐户
docker pull jcleng/buildopenwrt:20.04
#根据需要选插件
make menuconfig
#记得在Target Images适当扩大系统分区和镜像大小
#系统分区,驱动或插件多的话需要适当扩大这个分区
#(128) Kernel partition size (in MB)
#文件系统分区,基本可以理解为安装后默认的/overlay分区大小
#(512) Root filesystem partition size (in MB)


#看看有没有没下完整的包,这是查看dl目录下有没有1k以下的文件,有的话建议删除重新下,很可能没下完整
find dl -size -1024c -exec ls -l {} \;
#删除
find dl -size -1024c -exec rm -f {} \;


# 压目录
7za a -m0=lzma -mx=9 -ms=on lede.7z lede/ &
/openwrt/bin/targets
# 如果要更换架构,例如要从 x86_64 换到 MediaTek Ralink MIPS 建议执行以下命令深度清理
rm -rf ./bin ./build_dir ./tmp ./staging_dir
make clean
make dirclean
# 如果分支变更,需要删除feeds
rm -rf feeds

# 如果需要对组件重新调整,则建议先删除旧配置

rm -rf .config

make -j$(nproc) || make -j1 || make -j1 V=s

# 编译插件

make package/luci-theme-rosy/luci-theme-rosy/compile V=99

# 注:V=99 表示输出详细的 de­bug 信息

# 我这里是 x86_64 架构,编译完成插件包默认存放路径:~/openwrt/bin/packages/x86_64/base 目录下

- 成功一次

```shell

du ./ -hd 1
16M     ./.git
8.0K    ./.github
56K     ./LICENSES
64K     ./config
376K    ./include
24M     ./package
2.2M    ./scripts
52M     ./target
2.7M    ./tools
514M    ./feeds
756M    ./dl
652K    ./toolchain
177M    ./tmp
1.9G    ./staging_dir
12G     ./build_dir
67M     ./bin
15G     ./

┌💁  jcleng @ 💻  nixos in 📁  immortalwrt on 🌿  openwrt-21-02 •1 ✗
└❯ docker ps
CONTAINER ID   IMAGE                      COMMAND   CREATED        STATUS             PORTS                                     NAMES
2a0f00b6227a   p3terx/openwrt-build-env   "/init"   25 hours ago   Up About an hour   0.0.0.0:10022->22/tcp, :::10022->22/tcp   openwrt-build-env
  • dl目录的文件进行手动下载,如果下载失败,可以手动下载重新编译

# push @mirrors, 'https://mirror01.download.immortalwrt.eu.org';
# push @mirrors, 'https://mirror2.immortalwrt.org/sources';
# push @mirrors, 'https://mirror.immortalwrt.org/sources';
# push @mirrors, 'https://sources.immortalwrt.org';
# push @mirrors, 'https://sources.cdn.immortalwrt.org';
push @mirrors, 'https://sources.cdn.openwrt.org';
push @mirrors, 'https://sources.openwrt.org';
# push @mirrors, 'https://mirror2.openwrt.org/sources';
  • openwrt_buildroot https://github.com/noonien/docker-openwrt-buildroot

# 构建命令
# docker build -t openwrt_buildroot .
FROM ubuntu:20.04
# 腾讯云,源
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.cloud.tencent.com\/ubuntu@g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.cloud.tencent.com\/ubuntu/g' /etc/apt/sources.list

RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC \
    apt-get install -y \
        sudo time git-core subversion build-essential gcc-multilib \
        libncurses5-dev zlib1g-dev gawk flex gettext wget unzip \
        grep rsync python3 python3-distutils && \
    apt-get clean

RUN useradd -m openwrt && \
    echo 'openwrt ALL=NOPASSWD: ALL' > /etc/sudoers.d/openwrt

USER openwrt
WORKDIR /home/openwrt

RUN bash
  • 在docker使用rootfs文件运行openwrt

# 还是存在一些问题,luci的web无法访问/ubus,还是用libvirt来操作能ok
docker image import immortalwrt-x86-64-generic-rootfs.tar.gz immortalwrt:latest
docker run -itd --name=immortalwrt immortalwrt:latest /sbin/init
docker ps|grep immortalwrt
docker exec -it immortalwrt bash

docker restart immortalwrt
  • JCG Q30 Pro刷写openwrt

# 过渡固件/底包: 在原始管理界面进行升级刷入, 获得uboot
wget https://firmware.download.immortalwrt.eu.org/237176253/mediatek/filogic/immortalwrt-mediatek-mt7981-mt7981-spim-nand-rfb-squashfs-sysupgrade.bin
# sha256sum
446d8766c079357367f647ef28587ec050ea2bf865980e54a2f29134c5fd5ede  immortalwrt-mediatek-mt7981-mt7981-spim-nand-rfb-squashfs-sysupgrade.bin

# 上一步刷完固件之后,等待大约两分钟,然后断电,按住机身背部的 Reset 按键,上电开机。等待不到 10s 左右,红灯闪烁三下然后变成蓝灯,代表已进入 U-Boot 的恢复模式 WebUI。需要设置192.168.1.2段IP, 然后访问192.168.1.1
# 固件包, Factory 映像, 记得下载之后检查sha256sum
https://firmware-selector.immortalwrt.org/?version=23.05-SNAPSHOT&target=mediatek%2Ffilogic&id=jcg_q30-ubootmod
# 进入系统后有一些其他事情可以优化。目前固件默认没完全开启 WiFi 硬件转发加速,天灵修改这个配置之前,可能需要手动开启。SSH 或 TTYD 连接到路由器并执行:
opkg update && opkg install bridger
echo 'mt7915e wed_enable=Y' > /etc/modules.d/mt7915e
  • 源地址

https://github.com/hanwckf/immortalwrt-mt798x

# 或者使用
https://github.com/x-wrt/x-wrt
# JCG Q30 Pro
https://downloads.x-wrt.com/rom/
  • busybox

# mips ar300m
https://www.busybox.net/downloads/binaries/1.21.1/busybox-mips
  • 自建包使用构建完成的bin目录(带有targets和packages目录)

cat /etc/opkg/distfeeds.conf

src/gz immortalwrt_core https://cdn.leng2011.icu/bin/21.02/targets/ath79/nand/packages
src/gz immortalwrt_base https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/base
src/gz immortalwrt_luci https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/luci
src/gz immortalwrt_pack https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/packages
src/gz immortalwrt_rout https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/routing
src/gz immortalwrt_tele https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/telephony
src/gz immortalwrt_tele https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/small
src/gz immortalwrt_tele https://cdn.leng2011.icu/bin/21.02/packages/mips_24kc/kenzo
  • 编译加速,修改文件的下载地址

# golang国内加速
export GO111MODULE=on
export GOPROXY=https://goproxy.cn

# 软件包加速
feeds.conf.default
# 修改为国内github加速地址: https://hub.njuu.cf/
  • 定时重启crontab

# 增加到文件
crontab -e
# 凌晨3点重启
0 3 * * * /sbin/reboot

# 查看开启的任务
crontab -l