Skip to content

Wiki

Build Environment Preparation

About 9 min read

1.Environment description: This tutorial uses Ubuntu 22.04 as the environment

Please ensure the global magic of the compilation process

2.Basic Compilation Process

Set environment variables (not sure if it helps):

注意使用root编译会报错,可以在/etc/profile 最后添加export FORCE_UNSAFE_CONFIGURE=1,然后执行
export FORCE_UNSAFE_CONFIGURE=1
  1. System software package update
sudo apt-get -y update && sudo apt-get -y upgrade
  1. Install dependencies and the compilation toolchain
sudo apt install -y ack antlr3 aria2 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 libglib2.0-dev libgmp3-dev libltdl-dev \
libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz \
mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip libpython3-dev qemu-utils \
rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
  1. Download OpenWrt source code
git clone https://github.com/openwrt/openwrt.git && cd openwrt 
git clone https://github.com/coolsnowwolf/lede && cd lede

# 还有个
git clone https://github.com/istoreos/istoreos

(There are many source codes; this tutorial uses the official source code and LEDE as examples.)

  1. Switch to the appropriate branch

openwrt-22.03 iptables has been removed. To avoid compatibility issues, temporarily switch to openwrt-21.02 branch:

git checkout openwrt-21.02
  1. Update and install feeds package sources
./scripts/feeds update -a && ./scripts/feeds install -a

(The following is a campus network anti-detection deployment)

  1. Add Module
git clone https://github.com/Zxilly/UA2F.git package/UA2F
git clone https://github.com/CHN-beta/rkp-ipid.git package/rkp-ipid 
  1. Configuration Edit
make menuconfig

Configure compilation rdp-ipid:

  • Kernel modules → Other modules → kmod-rkp-ipid

Configure and compile ua2f:

  • Network → Routing and Redirection → UA2F

Configure and compile the iptables module (in Firewall)

Selected:

  • iptables-mod-filter
  • iptables-mod-ipopt
  • iptables-mod-u32

Basic interface configuration:

  • LuCI → Collections → luci (selected by default in LEDE)
  • LuCI → Modules → Translations → Chinese Simplified (zh_Hans) (selected by default in LEDE)
  • LuCI → Modules → luci-compat
  • LuCI → Applications → luci-app-ttyd (web terminal)
  • LuCI → Themes → xxxxx (choose the admin interface theme as needed; if the router storage is too small, it is recommended to keep the default)

Other configurations:

  • Add EXT4 hard disk format support: Kernel modules > Filesystem > kmod-fs-ext4
  • Add USB support (if not added, the keyboard may not respond): Kernel modules > USB Support

Network adapter driver configuration:

  • After checking, the network card uses Intel IG211-AT and operates over the PCIe channel; here, e1000e should be selected.
  • Kernel modules > Network Devices: Select the kmod-e1000e and kmod-igb drivers.

Wireless network card driver:

  • The wireless driver in the kernel finds the driver for RTL8821AE
  • Kernel modules > Wireless Drivers

Author: KANSUNG > Link: https://www.jianshu.com/p/5190ab903820 > Source: Jianshu

Add other tools (optional):

  • LuCI > Applications -> luci-app-openclash
  • LuCI > Applications -> luci-app-adblock
  • LuCI > Applications -> luci-app-ddns-go

Add necessary components:

  • Kernel modules -> Network Support -> kmod-tun (required for OpenClash TUN mode)

Exclude conflicting components:

  • Base system -> dnsmasq (uncheck it, because dnsmasq-full is installed by default, and dnsmasq needs to be excluded to avoid conflict errors)

Edit configuration file:

  • Use vim .config, and add a line at the beginning (required for the UA2F plugin):
CONFIG_NETFILTER_NETLINK_GLUE_CT=y
  1. Compile and configure the kernel
make kernel_menuconfig
make -j1 V=sc kernel_menuconfig  # 日志更详细

Configuration path: Networking support → Networking options → Network packet filtering framework (Netfilter) (select first, then enter) → Core Netfilter Configuration →

Select the following option:

  • Netfilter NFNETLINK interface
  • Netfilter LOG over NFNETLINK interface
  • Netfilter connection tracking support
  • Connection tracking netlink interface
  • NFQUEUE and NFLOG integration with Connection Tracking
  1. Compile Download the compilation tool:
make download -j$(nproc) V=s

Start compilation:

make -j$(nproc) V=s
make -j1 V=sc 2> build.log  # 错误输出到日志

The secondary compilation requires updating the source code:

git pull

2.1.Reconfigure If reconfiguration is required:

rm -rf ./tmp && rm -rf .config
make menuconfig
make -j$(($(nproc) + 1)) V=s   # 多线程编译失败后自动进入单线程编译,失败则输出详细日志

2.2.Compile and replace firmware for other CPU architectures (recommended operation)

Clear old compilation artifacts:

make clean

Execute this after large-scale source updates or kernel updates to ensure compilation quality. This operation will delete files in the /bin and /build_dir directories.

Remove old compilation artifacts, cross-compilation tools, toolchain, and other directories:

make dirclean

Must be executed before compiling for a different architecture. This operation will delete files in the /bin and /build_dir directories (make clean) as well as files in /staging_dir, /toolchain, /tmp, and /logs.

Remove files other than the OpenWrt source code (optional):

make distclean

Unless you are doing development and intend to push to a remote repository such as GitHub, you will hardly ever need it. This operation is equivalent to make dirclean plus deleting the /dl and /feeds directories and the .config file.

Restore the OpenWrt source code to its initial state (optional):

git clean -xdf

Use this when the source code has been broken, or when compilation has not been performed for a long time.

Clear temporary files:

rm -rf tmp

Delete some temporary files generated after executing make menuconfig, including retrieval information for some software packages. After deletion, the software packages in the package directory will be reloaded. If not deleted, some newly added software packages will not be displayed.

Delete compilation configuration file:

rm -f .config

Without deleting, if you deselect certain components, their dependent components will not be automatically deselected, so for cases where components need to be adjusted, it is recommended to delete them.

Note: Do not use the root user for any operations.

Copyright Notice: This article is an original article by the blogger and follows the CC 4.0 BY-SA copyright agreement. When reposting, please attach the original source link and this notice.

Original link:https://blog.csdn.net/u010674953/article/details/129280724