1. 介绍
Openwrt系统是一个开源的路由器系统。
2. 构建方法
2.1 环境安装
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib
git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libfuse-dev libglib2.0-dev libgmp3-dev
libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libpython3-dev libreadline-dev
libssl-dev libtool lrzsz mkisofs msmtp ninja-build p7zip p7zip-full patch pkgconf python2.7 python3
python3-pyelftools python3-setuptools qemu-utils rsync scons squashfs-tools subversion swig texinfo
uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
2.2 下载源代码
git clone https://github.com/coolsnowwolf/lede
cd lede
./scripts/feeds update -a
./scripts/feeds install -a
2.3 下载dl库
make download -j8
2.4 编译系统
首次单线程编译
make V=s -j1
3. Docker构建
将编译环境封装到Docker镜像中,方便快速搭建编译环境。
3.1 构建docker镜像
- Dockerfile文件
FROM ubuntu:22.04
LABEL Maintainer="zhangfenghui <1416077322@qq.com>"
LABEL Description="openwrt dev env"
# Setup document root
# WORKDIR /var/www/html
RUN echo "Asia/Shanghai" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
&& echo "root:1" | chpasswd \
&& useradd -m -s /bin/bash dev \
&& usermod -aG sudo,adm dev \
&& echo "dev:1" | chpasswd \
&& sed -i '35,41s/^#//' /etc/bash.bashrc
# Install packages and remove default server definition
RUN apt update -y && apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib \
git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libfuse-dev libglib2.0-dev libgmp3-dev \
libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libpython3-dev libreadline-dev \
libssl-dev libtool lrzsz mkisofs ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 \
python3-pyelftools python3-setuptools qemu-utils rsync scons squashfs-tools subversion swig texinfo \
uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev sudo \
&& chmod 777 /etc/sudoers && echo "dev ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && chmod 440 /etc/sudoers
COPY openwrt_point.sh /bin
CMD ["bash","/bin/openwrt_point.sh"]
- openwrt_point.sh
echo "system_init,uid:$UID gid:$GID"
USERNAME=dev
CURRENT_UID=$(grep "^$USERNAME:" /etc/passwd | cut -d: -f3)
CURRENT_GID=$(grep "^$USERNAME:" /etc/group | cut -d: -f3)
if [[ "$UID" =~ ^[0-9]+$ ]] && [[ "$CURRENT_UID" -ne "$UID" ]]; then
echo "update uid:$UID"
usermod -u $UID $USERNAME
fi
if [[ "$GID" =~ ^[0-9]+$ ]] && [[ "$CURRENT_GID" -ne "$UID" ]]; then
echo "update gid:$UID"
groupmod -g $GID $USERNAME
fi
su $USERNAME
- 执行docker build即可构建镜像
docker build -t openwrt_dev:1.0.0 .
3.2 启动编译环境
需要自己映射源码路径和dl路径
进入docker源码位于/home/dev/openwrt
docker run -it \
--rm \
--name=openwrt-dev-`logname` \
--env UID=`id -u` \
--env GID=`id -g` \
-v ./:/home/dev/openwrt \
-v /tmp:/home/dev/openwrt/dl \
-w /home/dev/openwrt \
--privileged \
nexus.huihui.space:1443/zfh/openwrt_dev:1.0.0
4. 1疑难问题
4.1 系统类
4.1.1 系统重启后文件系统变为只读根文件
- 临时解决方案
mount -o remount rw /
- 永久解决方案
按顺序取消选中
- Extra packages ---> automount
- Base system ---> block-mount