This document describes how to run the x86-64 OpenWrt images in VirtualBox, or VB for short.
gzip -d openwrt-x86-64-combined-ext4.img.gz
VBoxManage convertfromraw --format VDI openwrt-x86-64-combined-squashfs.img openwrt-x86-64-combined-squashfs.vdi
if you receive an error similar to
VBoxManage: error: VD: The given disk size 19444018 is not aligned on a sector boundary (512 bytes) VBoxManage: error: Error code VERR_VD_INVALID_SIZE at /Users/vbox/tinderbox/5.1-mac-rel/src/VBox/Storage/VD.cpp(7002) in function int VDCreateBase(PVBOXHDD, const char *, const char *, uint64_t, unsigned int, const char *, PCVDGEOMETRY, PCVDGEOMETRY, PCRTUUID, unsigned int, PVDINTERFACE, PVDINTERFACE) VBoxManage: error: Cannot create the disk image "openwrt.vdi": VERR_VD_INVALID_SIZE
you may need to pad the image with
dd if=openwrt-x86-64-combined-squashfs.img of=openwrt.img bs=128000 conv=sync and use the padded image as input to VBoxManage convertfromraw.
Or you can compile your own image (Target System → x86-64 and Target Images → Build VirtualBox image files).
ext4 needs to be enabled first.
$ VboxManage modifymedium openwrt-x86-64-combined-squashfs.vdi --resize 128 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Tutorial and screenshots from VirtualBox 5.1.8 on Linux host, on Windows or macOS hosts there will be some cosmetic differences (a different top bar) but the VirtualBox panels and buttons will be exactly the same
It's recommended to place the disk image in a permanent place before linking it with VB. If you move it afterwards, VB will not find it anymore and will complain about this issue on next start (or when you try to start the VM). It will offer a guided procedure to link the disk image again, so don't worry.
This part of the configuration will deal with setting up networking manually.
The configuration you will set up by following this tutorial is:
Note that the order of the “Host-only Adapter” as “Adapter 1” and “NAT” as “Adapter 2” is important for turn-key operation of OpenWrt in the VM. While it can be configured using the console, configuration in this way simplifies getting to a running configuration.
we first need to make sure there is a Host-only network adapter and that it has the right settings
Note: this is found in VB 6.0 (at least for Windows) under Tools, and is pre-configured.
Click on Host-only Networks tab and then if you don't see a vboxnet0 entry click on the + icon on the right of the window to add a new one.
Now select the vboxnet0 entry, and click on the screwdriver icon on the right to open its settings.
(optional) you can also set the DHCP server as shown in the screenshot if you want to have dynamic addresses to the VM, but for this tutorial it is not required as we set a static address in the VM itself
Press OK to save and close until you are back to VirtualBox Manager interface again.
Due to limitations, the keyboard in the virtual machine's terminal is set to US, so some (or most) of your keys may not print the symbols as indicated by the keycaps.
Also, due to the fact that what you see there is a bare machine terminal and not a smart thing like a SSH program (Putty/Kitty/whatever) or a terminal emulator program, you cannot copy-paste text into it.
Don't worry, most of the setup will be done after you are connected with SSH (remote terminal) that does not have any of these issues.
Look at this US keyboard layout to find what button you need to press on your keyboard to generate the right symbol.
random: crng init donewith OpenWrt 17.01.4). Until there is sufficient entropy, SSH and other cryptographic functions may fail.
root@openwrt:~# uci show network network.loopback=interface network.loopback.ifname='lo' network.loopback.proto='static' network.loopback.ipaddr='127.0.0.1' network.loopback.netmask='255.0.0.0' network.globals=globals network.globals.ula_prefix='fd1b:e541:8f1a::/48' network.lan=interface network.lan.type='bridge' network.lan.ifname='eth0' network.lan.proto='static' network.lan.netmask='255.255.255.0' network.lan.ip6assign='60' network.lan.ipaddr='192.168.1.1' network.wan=interface network.wan.ifname='eth1' network.wan.proto='dhcp' network.wan6=interface network.wan6.ifname='eth1' network.wan6.proto='dhcpv6'
Note that the default LAN address of 192.168.1.1 is present on first boot.
uci batch <<EOF set network.mng=interface set network.mng.type='bridge' set network.mng.proto='static' set network.mng.netmask='255.255.255.0' set network.mng.ifname='eth0' set network.mng.ipaddr='192.168.56.2' delete network.lan delete network.wan6 set network.wan=interface set network.wan.ifname='eth1' set network.wan.proto='dhcp' EOF
root@openwrt:~# uci changes network.mng='interface' network.mng.type='bridge' network.mng.proto='static' network.mng.netmask='255.255.255.0' network.mng.ifname='eth0' network.mng.ipaddr='192.168.56.2' -network.lan -network.wan6 network.wan='interface'
uci batch <<EOF set network.lan=interface set network.lan.ifname='eth2' set network.lan.proto='dhcp' EOF uci commit
If you have more complex requirements you will have to set that up on your own by reading the documentation, or through luci.