Openwrt编译
下载Openwrt源码
git clone https://github.com/openwrt/openwrt.git
或者
git clone https://git.openwrt.org/openwrt/openwrt.git/
下载安装拓展包
cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
./scripts/feeds update -a // 更新最新的包 ./scripts/feeds install -a // 下载所有安装所有包 目录 package/feeds/
使用feeds.conf.default 默认配置进行软件包的更新与安装
配置环境
Ubuntu环境安装依赖
sudo apt install -y gcc binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils libncurses5-dev ncurses-term zlib1g-dev wget perl thread-queue libssl-dev zlib1g ncurses-dev g++
Centos环境安装依赖
sudo yum -y install gcc binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils libncurses5-dev ncurses-term zlib1g-dev wget perl-Thread-Queue openssl-devel zlib-static ncurses-devel gcc-c++
编译配置
运行如下命令:
make defconfig // 检查编译工具是否全,生成.config文件
make menuconfig // 打开编译菜单
进入功能配置界面
target system 选择x86平台,其他先默认配置,后续根据自己的需求可以增加删除软件包,修改配置选项。
编译
make V=99 // V = verbose 全部都显示
单独编译软件包
make package/tcpdump/clean 清除编译生成的文件
make package/tcpdump/prepare 进行编译准备
make package/tcpdump/configure 根据设置选项进行配置并生成Makefile
make package/tcpdump/compile 根据生成的Makefile进行编译
make package/tcpdump/install 生成安装包
make download 下载所有已选择的软件代码压缩包
make tools/install
make toolchain/install
make target/compile
make package/cleanup
make package/compile # 编译包
make package/install # 安装包
make package/preconfig
make target/install
make package/index
清除缓存
make clean # rm -rf bin build_dir
make dirclean # rm -rf bin build_dir staging_dir toolchain logs
make distclean # 删除以上所有文件 , dl 和 .config
对于特定组件进行clean
make target/linux/clean V=s
make package/luci/clean
编译完成后在bin/target目录下,有elf 和ext4文件系统
复制 openwrt-malta-le-root.ext4 与 openwrt-malta-le-vmlinux.elf 文件 到你要运行的目录,然后执行下面的命令
通过Qemu运行Openwt
qemu-system-x86_64 -m 5120 -smp 4 -M pc -drive file=openwrt-x86-64-combined-ext4.img,if=none,id=openwrtdisk –device ich9-ahci,id=ahci -device ide-drive,drive=openwrtdisk,bus=ahci.0 -net nic,vlan=0,macaddr=52:54:00:AF:53:81,model=virtio -net user,vlan=0 -redir tcp:10023::23 -redir tcp:10080::80 –localtime
可能默认编译出来是没有这个文件openwrt-x86-64-combined-ext4.img,要修改编译选项,取消“GZip images”选项,即不通过gzip打包,如下图所示。