VirtualBox部署OpenWRT固件

文章目录

  • 下载软件SDK环境
    • 从gitee仓库下载
  • 编译固件
  • 转换固件为虚拟磁盘文件
  • 启动OpenWRT
  • 配置网络

下载软件SDK环境

从gitee仓库下载

gitee下载比较快,需要先注册账号和添加ssh公钥(按照gitee的说明操作即可),才能下载源码。
下载网址:https://gitee.com/harvey520/openwrt

ubuntu@ubuntu-vm ~ % git clone git@gitee.com:harvey520/openwrt.git

备注:当前版本为19.07,内核版本为Linux4.14

编译固件

  1. 编译前安装一些工具包用于编译的顺利进行:
sudo apt install git-core gnupg flex bison gperf
sudo apt install build-essential zip curl zlib1g-dev
sudo apt install libc6-dev lib32ncurses5-dev lib32z1
sudo apt install x11proto-core-dev libx11-dev
sudo apt install lib32readline-gplv2-dev
sudo apt install lib32z1-dev libgl1-mesa-dev g++-multilib tofrodos
sudo apt install python python-markdown libxml2-utils
sudo apt install android-tools-adb lzop
sudo apt install samba lua cifs-utils vim ctags vim-doc vim-scripts
sudo apt install gawk gawk-doc net-tools 
sudo apt install libssl-dev
sudo apt install subversion
sudo apt install zlib1g-dev qemu-utils
  1. 在sdk中更新openwrt的工具包并安装
./scripts/feeds update
./scripts/feeds install -a
  1. 配置编译选项
make deconfig
make menuconfig

VirtualBox部署OpenWRT固件_第1张图片

  1. 开始编译
    第一次建议用单线程,编译时间较长,保持网络畅通,建议晚上运行第一次编译。
make -j1

转换固件为虚拟磁盘文件

  1. 方法一
xxxxxx@MacBookPro ~ % VBoxManage convertfromraw /Volumes/share/openwrt/bin/targets/x86/generic/openwrt-x86-generic-combined-ext4.img openwrt-test.vmdk --format VMDK
Converting from raw image file="/Volumes/share/openwrt/bin/targets/x86/generic/openwrt-x86-generic-combined-ext4.img" to file="openwrt-test.vmdk"...
Creating dynamic image with size 285736960 bytes (273MB)...
xxxxxx@MacBookPro ~ % 
  1. 方法二
    在Linux中使用qemu-utils工具进行转换
ubuntu@ubuntu-vm ~ % qemu-img convert -f raw openwrt-x86-generic-combined-ext4.img -O vmdk openwrt-debug.vmdk

启动OpenWRT

  1. 启动VirtualBox或者VMwareWorkstation创建虚拟机
  2. 选择系统为linux4.x
  3. 设置好后启动虚拟机会进入命令行
    VirtualBox部署OpenWRT固件_第2张图片

配置网络

  1. 设置VMware的网络
    VirtualBox部署OpenWRT固件_第3张图片
    (1)修改网络适配器2
    VirtualBox部署OpenWRT固件_第4张图片
    (2)修改网络适配器
    VirtualBox部署OpenWRT固件_第5张图片
  2. 设置openwrt系统的网络配置
    VirtualBox部署OpenWRT固件_第6张图片
    配置后重启下
root@OpeneWrt:/# /etc/init.d/network restart

然后可以试一下ping通外网

你可能感兴趣的:(OpenWRT,openwrt)