== HelenOS on a physical LAN/Internet from QEMU/KVM == This is a simple DIY checklist for running HelenOS in QEMU/KVM and connecting its TCP/IP networking stack to a real physical ethernet LAN and possibly to the public Internet via this LAN. Please note that the functionality of the HelenOS TCP/IP stack is still severely limited (especially concerning the actual usability of the UDP and TCP protocols), but the situation should improve soon. This checklist should work reasonably well with any recent GNU/Linux (2.6) distribution and QEMU/KVM 0.13.x on a IA-32 or AMD64 host system with a physical ethernet network card. Without any special arrangements you also need to have a root access on the host machine. If you have a substantially different software or hardware configuration than expected, your mileage may vary. == Prerequisites == This checklist assumes that you have an ethernet device called ''eth0'' up and configured with an IP address (the IP address can be static or configured by a DHCP). You also need the ''brctl'' tool for creating and configuring virtual ethernet bridges (it usually comes in a package called ''bridge-utils'' or similar) as well as the usual Linux network management utilities (e.g. ''ip'' and friends). The bridges are software-defined ethernet network interface layer interconnections implemented in the Linux kernel, but for any practical purposes you can think about them as the usual ethernet switches or hubs. == Creating a bridge == Store the following shell script in a convenient location (e.g. ''/etc/kvm/scripts/bridge''): {{{ #! /bin/bash function create_bridge() { local bridge="$1" echo -n "$bridge: creating bridge ... " brctl addbr "$bridge" echo "OK" echo -n "$bridge: setting bridge options ... " brctl stp "$bridge" off brctl setfd "$bridge" 0 sysctl -q -w "net.bridge.bridge-nf-call-arptables=0" sysctl -q -w "net.bridge.bridge-nf-call-ip6tables=0" sysctl -q -w "net.bridge.bridge-nf-call-iptables=0" echo "OK" } function transfer_addrs() { local src="$1" local dst="$2" echo -n "$src: transfering addresses to $dst ... " local addrs="`ip addr show "$src" | egrep '^ *inet ' | sed -e "s/^ *inet/ip addr add/g;s/$src/dev $dst/g"`" $addrs echo "OK" echo -n "$dst: removing automatic routes ... " local routes="`ip route list | sed -ne "/dev $dst\( \|$\)/s/^/ip route del /gp"`" $routes echo "OK" } function get_gateway() { local netdev="$1" echo -n "$netdev: storing gateway ... " gateway="`ip route show dev "$netdev" | fgrep default | sed "s/default via //"`" echo "OK" } function if_down() { local netdev="$1" echo -n "$netdev: link down ... " ip link set "$netdev" down echo "OK" echo -n "$netdev: address flush ... " ip addr flush "$netdev" echo "OK" } function transfer_name() { local netdev="$1" local tmpdev="$2" local phydev="$3" local bridge="$4" echo -n "$netdev: renaming to $phydev ... " ip link set "$netdev" name "$phydev" echo "OK" echo -n "$tmpdev: renaming to $bridge ... " ip link set "$tmpdev" name "$bridge" echo "OK" } function add_to_bridge() { local bridge="$1" local dev="$2" echo -n "$bridge: adding $dev ... " brctl addif "$bridge" "$dev" echo "OK" } function if_up() { local netdev="$1" echo -n "$netdev: bringing up ... " ip link set dev "$netdev" up echo "OK" } function set_gateway() { local netdev="$1" if [ -n "$gateway" ] ; then echo -n "$netdev: setting default gateway ... " ip route add default via $gateway echo "OK" fi } if [ "$#" -lt "1" ]; then echo "Syntax: $0 " exit 1 fi tmpdev="tmpbr" netdev="$1" phydev="p$netdev" bridge="$netdev" create_bridge "$tmpdev" get_gateway "$netdev" transfer_addrs "$netdev" "$tmpdev" if_down "$netdev" transfer_name "$netdev" "$tmpdev" "$phydev" "$bridge" add_to_bridge "$bridge" "$phydev" if_up "$bridge" set_gateway "$bridge" if_up "$phydev" }}} To create a bridge, just run manually this script and use the name of your physical ethernet device (which you want to be connected initially to the bridge) as the argument, e.g. {{{ /etc/kvm/scripts/bridge eth0 }}} The script basically renames your physical ethernet device ''eth0'' to ''peth0'', creates a bridge device called ''eth0'' and moves all the usual IP configuration from ''peth0'' to ''eth0''. By doing this your host system is still going to have IP connectivity via a network device with the original name, but the physical ethernet device is going to work just as one (network interface layer) port of the bridge. '''Note 1:''' The creation of the bridge is a manual process (since you probably don't want to have this around all the time) and its configuration won't be stored persistently during reboots (unless you have some crazy AI-driven Linux distribution). But typically the existence of the bridge should be transparent to any networking applications you run on your host. '''Note 2:''' The script has been tested only on IPv4 networks. It should work similarly with IPv6 or any other network protocol, but the script might require some tweaking. == Connecting QEMU/KVM networking to the bridge == In order for QEMU/KVM to be able to connect network interface of the virtual machine to the virtual bridge, you again need some scripts, but this time the script will be executed by QEMU/KVM itself. First, store the main script into a convenient path (e.g. ''/etc/kvm/scripts/ifup''): {{{ #!/bin/sh if [ "$#" -lt "2" ]; then echo "Syntax: $0 " exit 1 fi iface="$1" bridge="$2" ip link set "$iface" down ip link set "$iface" arp off ip link set "$iface" multicast off ip link set "$iface" addr fe:ff:ff:ff:ff:ff ip addr flush "$iface" brctl addif "$bridge" "$iface" ip link set "$iface" up }}} This script connects the TAP device created by QEMU/KVM when initializing the virtual machine into the bridge. Since the scripting interface of QEMU/KVM only provides means for a single script argument (merely the TAP device name), you also need a small wrapper script, again stored say in ''/etc/kvm/scripts/ifup-eth0'': {{{ #!/bin/sh /etc/kvm/scripts/ifup "$1" eth0 }}} == Configuring HelenOS networking == HelenOS does not support any dynamic network configuration (e.g. via DHCP) so far. Thus, you need to configure the IP parameters for HelenOS manually prior to running it in QEMU/KVM. Just go to the ''uspace/srv/net/cfg'' directory in the HelenOS source tree and edit the ''ne2k'' configuration file according to your network parameters (you need to reserve an IP address statically for your HelenOS virtual machine). For example in my case I have to change the following values: {{{ IP_ADDR=192.168.254.254 IP_NETMASK=255.255.255.0 IP_BROADCAST=192.168.254.255 IP_GATEWAY=192.168.254.1 }}} Compile HelenOS for IA-32 in a usual way. == Running HelenOS in QEMU/KVM == Finally, after all has been successfully configured and HelenOS compiled, you can run it with a command line similar to this one: {{{ qemu-kvm \ -name helenos \ -drive index=0,file=/home/user/HelenOS/image.iso,if=ide,media=cdrom,boot=on \ -m 512 \ -device ne2k_isa,irq=5,vlan=0,mac=aa:de:ad:be:ef:fe \ -net tap,script=/etc/kvm/scripts/ifup-eth0 \ -vga std }}} '''Note 1:''' Please modify any of the QEMU/KVM options for your specific configuration (paths, etc.). It is probably also a good idea to change the MAC address of the virtual NE2000 card to a different value (just for the case that accidentally more people start playing with this on the same LAN). '''Note 2:''' The ''-device ne2k_isa,irq=5,vlan=0'' and ''-net tap'' options are naturally essential for the correct functionality of the networking, you probably should not mess with them. Also please take note that currently in SMP virtual machines (with more than one CPU) the networking won't work. == Starting up networking in HelenOS == After HelenOS boots up, just run the following command from ''bdsh'': {{{ net }}} You should see some output indicating whether the initialization of the whole networking stack went OK and if it is the case then HelenOS should be ''visible'' on the network.