使用docker编译openwrt固件

docker优势这里不重复,直接往下看

1. openwrt编译环境准备: 一键安装docker


wget -qO- https://get.docker.com/ | bash
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

2. 为openwrt环境编写dockerfile


这里用的是lienol源代码
FROM ubuntu:18.04
ENV TZ 'America/New_York'

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \    
    apt-get install -y sudo time git-core subversion build-essential gcc-multilib \
    build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3.5 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf vim screen \
                       libncurses5-dev zlib1g-dev gawk flex gettext wget unzip python &&\
    apt-get clean

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

USER openwrt
WORKDIR /home/openwrt

RUN git clone -b dev-19.07 https://github.com/Lienol/openwrt


  #&&\
 #   echo -ne "
#src-git lienol https://github.com/TinyTitanPro/lienol-openwrt-package" >> openwrt/feeds.conf.default &&\
 #  openwrt/scripts/feeds clean &&\
 #   openwrt/scripts/feeds update -a &&\
 #   openwrt/scripts/feeds  install -a

3.编译openwrt的docker镜像


在dockerfile目录下运行
docker build --no-cache -t openwrt .

4.运行镜像并编译openwrt


docker run -it openwrt:latest /bin/bash  # 运行本地docker镜像
docker exec -it a48a2bba1325 /bin/bash  # 进入已运行的docker容器,备用

4.1添加外部软件包


修改 feeds.conf.default 文件, 换行添加下面源(注意行首不能有空格)
src-git lienol https://github.com/TinyTitanPro/lienol-openwrt-package

4.2更新openwrt软件包


    openwrt/scripts/feeds clean &&\
   openwrt/scripts/feeds update -a &&\
   openwrt/scripts/feeds  install -a

4.3 编译openwrt


make menuconfig  # 修改型号,模块,主题等,保存
make -j1 V=s   #开始编译 

4.4 单独编译ipk


单独编译ipk的前提是已经编译固件,不然工具链不完整会出错.
 make package/feeds/lienol/tcping/compile V=99

5. openwrt其他docker镜像


这个docker镜像包比较小,适合研究
https://github.com/noonien/docker-openwrt-buildroot/blob/master/18.06/Dockerfile

参考来源:
https://github.com/Lienol/openwrt
https://github.com/TinyTitanPro/lienol-openwrt-package

发表评论