User Tools

Site Tools

This documentation is no longer maintained by the Turris team (although it can be used by the community to share content). The current official documentation is at docs.turris.cz.

Running Turris OS 3 inside QEMU

If you want to run unmodified TOS or TOS4/TOS5, check out https://github.com/jose1711/qemu_turrisos

The goal of this guide is to show how you can run (slightly modified) clone of your existing installation of Turris OS (TOS) inside QEMU emulator. This may serve as a platform for testing upgrades before you do it on your production router etc. Of course one cannot expect full feature set as QEMU is unable to emulate all the features of hardware or for instance connected USB devices. In order to make things easier we'll only use two network interfaces:

  • eth0 - „wan“ - dhcp from range 10.x.x.x/24 (assigned by QEMU)
  • eth1 - lan - static IP 192.168.123.1

Preparation (PC)

install qemu (you'll need qemu-system-arm)

distribution-specific (e. g. apt install qemu)

enable packet forwarding in firewall

sudo iptables -P FORWARD ACCEPT
# you may have to adjust (or maybe temporarily disable) firewall

create directory containing kernel and rootfs

mkdir -p ~/omnia-qemu/root

get 32-bit arm kernel from OpenWrt (the original one from TOS did not work)

curl -o ~/omnia-qemu/zImage https://downloads.openwrt.org/snapshots/targets/armvirt/32/openwrt-armvirt-32-zImage

copy start_omnia.sh script into ~/omnia-qemu

#!/bin/sh
LAN=ledetap0
KERNEL=zImage

# enable ip forwarding
fwd_orig=$(sysctl net.ipv4.ip_forward | awk '{print $NF}')
sysctl net.ipv4.ip_forward=1

# create tap interface which will be connected to OpenWrt LAN NIC
ip tuntap add mode tap $LAN
ip link set dev $LAN up

ip addr add 192.168.123.100/24 dev $LAN

qemu-system-arm \
 -nographic -M virt -kernel "${KERNEL}" -m 512 -no-reboot \
 -fsdev local,id=rootdev,path=root,security_model=none \
 -device virtio-9p-pci,fsdev=rootdev,mount_tag=/dev/root \
 -append 'rootflags=trans=virtio,version=9p2000.L,cache=loose rootfstype=9p' \
 -nic user \
 -device virtio-net-pci,netdev=lan \
 -netdev tap,id=lan,ifname=$LAN,script=no,downscript=no \

# cleanup. delete tap interface created earlier
ip addr flush dev $LAN
ip link set dev $LAN down
ip tuntap del mode tap dev $LAN

sysctl net.ipv4.ip_forward=${fwd_orig}

Backup current system (Omnia, root prompt)

make a snapshot of the current system and export it to device (path) with enough free space

schnapps export /some/path

this will put omnia-medkit-XXXXXXXX.tar.gz file into /some/path directory. All the following commands are to be executed on your PC.

Configuration changes and running emulator

Transfer and extract the archive to your PC

ssh omnia 'cat /some/path/omnia-medkit-XXXXXXXX.tar.gz' | ( cd ~/omnia-qemu/root; tar xvzf -; )

append the following line into root/etc/inittab:

ttyAMA0::askfirst:/bin/ash --login

reconfigure network interfaces in root/etc/config/network:

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config interface 'wan'
        option ifname 'eth0'
        option ipv6 '1'
        option dns '8.8.8.8 8.8.4.4'
        option proto 'dhcp'

config interface 'wan6'
        option ifname '@wan'
        option proto 'dhcpv6'

config interface 'lan'
        option proto 'static'
        option ipaddr '192.168.123.1'
        option netmask '255.255.255.0'
        option ifname 'eth1'

overwrite root/usr/bin/crypto-wrapper with the following contents:

#!/bin/sh
echo 0000000000000000
exit

edit root/etc/init.d/start-indicator in the following manner:

start() {
  .. # don't change and/or delete any lines
  # only add this somewhere into the start() block
  echo 'Turris Omnia' > /tmp/sysinfo/model
}

Optional step: disable services (option enabled '0' ) which you don't really need inside virtualized system:

  • root/etc/config/ddns
  • root/etc/config/hd-idle
  • root/etc/config/minidlna
  • root/etc/config/mjpg-streamer
  • root/etc/config/openvpn

execute qemu as root

cd ~/omnia_qemu
sudo ./start_omnia.sh

Hit Enter to activate console and wait for Router Turris successfully started. message.

Check, whether the following commands all work:

/sbin/ifstatus wan   # should return json
cat /tmp/sysinfo/model  # should return 'Turris Omnia' string
ls -l /tmp/run/foris-controller-client.sock  # should return name and file attributes
                          # if not, run /etc/init.d/foris-controller start and give it some moments

Open https://192.168.123.1/ in your browser and log-in to Luci or Foris (may need certificate exception).

Things that are not working

  • OpenVPN
  • firewall (iptables)
  • LXC
  • schnapps and everything related to btrfs (virtualized system is using 9p-type filesystem)
  • some pages in Foris/Luci dedicated to network (lan, network, network interfaces)
  'FileNotFoundError: [Errno 2] No such file or directory: '/sys/firmware/devicetree/base/model'
  'No such file or directory: '/proc/net/nf_conntrack'

Quitting emulator

inside guest system:

reboot

qemu will terminate, ledetap0 interface will be removed and ipv4 forwarding will be set to the original state.

Notes

These instructions are based on https://openwrt.org/docs/guide-user/virtualization/qemu and were successfully tested with TOS 3, host system was x86_64 running Arch Linux.