Running OpenWRT on qemu

These are insrtuctions to get OpenWRT running on qemu.

GET OpenWRT

$ git clone git://git.openwrt.org/openwrt.git
$ git clone git://git.openwrt.org/packages.git

Copy whatever seems necessary:

$ cd openwrt
$ cp -a ../packages/utils/strace \
        package/
$ cp -a ../packages/utils/valgrind \
        package/

Configure and build OpenWRT

If you have your own packages for OpenWRT, you may now put them under package/ before running the following command.

$ make menuconfig

choose to build for malta; in “Target images” -> “Root filesystem images”, choose ext4. configure packages

$ make target/linux/clean world

The above command will build a full OpenWRT image with TinyScheme and any other language you selected in menuconfig included.

$ cp bin/malta/openwrt-malta-le-vmlinux.elf \
     my-openwrt-image.elf
$ cp bin/malta/openwrt-malta-le-root.ext4 \
     my-openwrt-root.ext4

See if it works:

$ qemu-system-mipsel -kernel my-openwrt-image.elf M malta \
                     -hda openwrt-malta-le-root.ext4 \
                     -append "root=/dev/sda console=ttyS0" \
                     -nographic

Connect from inside OpenWRT to outside only

The following will give you a 10.0.*.* IP:

# udhcpc -i br-lan

The host is 10.0.2.2, you can ping,

# ping 10.0.2.2

or log in, transfer files, etc.

# ssh 10.0.2.2

Set up bridge

Make sure network bridging is compiled into the host kernel.

# ifdown eth0

edit: /etc/network/interfaces

from: auto eth0 iface eth0 inet blah (eth0 config here)

to: auto br1 iface br1 inet blah (eth0 config here) bridge_ports eth0

# ifup br1

Start qemu giving the target a network interface:

$ qemu-system-mipsel -kernel my-openwrt-image.elf -net nic -net tap -nographic

If the router can’t reach the host, see if there’s an interface configured with an IP. If not:

edit: /etc/config/network remove IP and netmask, switch from static to dhcp or use an IP in the same subnet of your host…

If you have chosen to get an IP via DHCP:

# ifup lan
# ifconfig

(It should have picked an IP from your DHCP server)