For embedded developers, OpenWRT is a powerful open-source router operating system. Typically, OpenWRT runs on embedded systems in routers, requiring a purchase of a dedicated ARM architecture development board to boot it. Here, we will attempt to run it on an x86 architecture virtual machine, making it easier for those without a development board to learn about OpenWRT.
This article will introduce how to pull the OpenWRT source code, configure and compile it, and deploy it to a VMware virtual machine, ultimately achieving network interconnection between the host and the virtual machine.
Environment Preparation
First, ensure that your Ubuntu system has the necessary compilation tools installed:
sudo apt update
sudo apt install build-essential libncurses5-dev libncursesw5-dev
zlib1g-dev gawk git gettext libssl-dev xsltproc rsync wget unzip python
You can refer to the article below for a quick setup of the Ubuntu Linux system environment on Windows.
WSL: A Linux Development Tool on Windows
Author: Linux IoT Notes
Also, download the VMware Workstation virtual machine software and install it on your Windows system.
Getting OpenWRT Source Code
Clone the official source code
git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
Update feeds (package list)
./scripts/feeds update -a
./scripts/feeds install -a
Since the resources are hosted abroad, this process may be extremely slow, so patience is required.
Configuring Compilation Options
Enter the configuration interface
make menuconfig
Key Configuration Options
The following are configuration options related to the virtual machine and x86 architecture.
In the configuration interface, pay special attention to the following settings:
Target System: Select x86
Subtarget: Select x86_64 (based on your virtual machine architecture)
Target Profile: Select Generic x86/64
Target Images: Check Build VMware image files (VMDK)
The recommended filesystem format is squashfs
Network: Select the network card drivers to compile
LuCI: If a web management interface is needed, check the relevant LuCI components
menuconfig Configuration Option Status Explanation
Blank option [ ]
[ ] Network Support
Indicates that this feature will not be compiled into the final image, nor will the corresponding module be generated.
Checked status [*]
[*] Network Support
Indicates that this feature will be compiled directly into the kernel, becoming part of the system.
Module status <M>
<M> USB Support
Indicates that this feature will be compiled as a loadable module, which can be dynamically loaded and unloaded while the system is running.
Specific Steps
Step 1: Enter Target System Configuration
→ Target System (x86) —>
→ Subtarget (x86_64) —>
→ Target Images —>
Use the → key to enter the “Target System” submenu and select the x86 architecture.
Step 2: Select Image Format
In the “Target Images” menu:
[ ] Build ext4 filesystem images
[*] Build VMware image files (VMDK)
[ ] Build VirtualBox image files (VDI)
Press the space key to select the VMware image format.
Step 3: Configure Network Drivers
→ Kernel modules —>
→ Network Devices —>
<*> Virtual Network Driver
<*> VMware VMXNET3 driver
Ensure that the required network drivers for the virtual machine are selected.
Step 4: Save Configuration
After configuration is complete, press ESC ESC to exit to the main interface, and select:
< Save > – Save the current configuration to .config file
< Exit > – Exit menuconfig
Start Compilation
Begin the compilation process
make -j$(nproc) V=s
-j$(nproc) indicates using all available CPU cores for compilation, and V=s indicates outputting detailed information. For example, execute make -j4 V=s
If the network is poor, you can download all resources first before compiling by executing
make download V=s
and then proceed with the compilation.
For a detailed analysis of the OpenWRT compilation process, please refer to the article below.
Analysis of OpenWrt Project and Compilation Process
Author: Linux IoT Notes
Obtaining Compiled Image Files
After compilation is complete, you can find the generated image files in the bin/targets/x86/64/ directory:
openwrt-x86-64-generic-squashfs-combined.img.gz
openwrt-x86-64-generic-squashfs-combined.vmdk (for VMware)
Copy the openwrt-x86-64-generic-squashfs-combined.vmdk image file to your Windows system for later use in VMware installation.
VMware Virtual Machine Deployment
Create a New Virtual Machine
Select “Custom” configuration
Select the latest version for hardware compatibility
Select “I will install the operating system later”
Select Linux -> Other Linux 5.x or later kernel 64-bit
Configure the processor and memory as needed (at least 1 core and 2GB is recommended)
Select “Bridged” for the network type
(Other configurations can be chosen as preferred, preferably defaults)
Select to use an existing virtual disk and point to the generated .vmdk file
Adjust Virtual Machine Settings
Ensure the network card is set to bridged mode
Adjust the video memory to 4MB
Detailed Network Bridging Configuration
VMware Network Settings
Host Settings:
Open the Windows Control Panel, go to “Network and Internet” → “Network Connections”
Confirm that the “VMware Network Adapter” network adapter is enabled
In the Virtual Network Editor, bridge VMnet to the physical network card
Virtual Machine Settings:
Select “Bridged” for the network adapter
Check the box to copy the physical network connection status
OpenWRT Network Configuration
After the first boot of OpenWRT, you need to modify the network configuration via serial or by editing the network configuration:
# Edit the network configuration file
vi /etc/config/network
# Modify LAN port configuration
config interface 'lan' option type 'bridge' option ifname 'eth0' option proto 'static' option ipaddr '192.168.1.1' # Set IP in the same subnet as the host option netmask '255.255.255.0' option gateway '192.168.1.254' # Host gateway option dns '8.8.8.8'
Restart Network Services
/etc/init.d/network restart
Network Connectivity Testing
Host Ping Test
# Execute ping 192.168.1.1 in the host terminal
OpenWRT Ping Host Test
# Execute ping 192.168.1.100 in OpenWRT terminal # Assuming the host IP is 192.168.1.100
Test External Network Connection
# Test external network connectivity in OpenWRT
ping 8.8.8.8
Through the detailed steps in this article, we have deployed a self-compiled OpenWRT system in VMware and achieved network intercommunication with the host. This environment provides a solid foundation for subsequent network function development and testing, facilitating OpenWRT application development.
The power of OpenWRT lies in its customizability, and we hope to explore more interesting features based on this foundation!