Sunday, April 12, 2015

QEMU - Virtio - NetworkManager on Fedora 21

QEMU is a generic and open source machine emulator and virtualizer. It takes care of networking, disk interfaces, managing memory and all other resources in order to run a guest OS inside a host OS.
Virtio  is a virtualization standard for network and disk device drivers where the guest OS' device drivers know they are running in a virtual environment, and cooperate with the host OS in order to get high performance network and disk operations, giving most of the performance benefits of paravirtualization.
NetworkManager is a set of co-operative tools that make networking simple and straightforward. This setup uses NetworkManager to provide a full network stack to the guest OS.
This document is a simple tutorial to take full advantage of the benefits of the technologies listed above when creating a new QEMU machine. For this, we are using an up-to-date installation of Fedora 21.
  1. As root on the host OS, create the br0 bridge device with the following persistent configuration:
    /etc/sysconfig/network-scripts/ifcfg-br0
    DEVICE=br0
    STP=yes
    BRIDGING_OPTS=priority=32768
    TYPE=Bridge
    BOOTPROTO=shared
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=no
    NAME=br0
    UUID=<paste the output of uuidgen>
    ONBOOT=yes
  2. Whitelist the br0 bridge device for use with qemu:
    /etc/qemu/bridge.conf
    allow br0
  3. As the normal user who will run qemu, create the disk image of the guest OS on the host OS:
    $ qemu-img create -f qcow2 guest.qcow2 40G
  4. Define the options for qemu; you may want to save them to a script:
    OPTS="-enable-kvm -drive file=guest.qcow2,if=virtio,aio=native -m 4G --machine pc,accel=kvm:xen:tcg -cpu host -soundhw hda -name GuestOS -vga std -smp cpus=1,cores=2,threads=2 -netdev tap,helper=/usr/libexec/qemu-bridge-helper,id=tap0 -device virtio-net-pci,netdev=tap0,id=nic0"
  5. Run the guest OS installer disk image with the virtio drivers appropriate to it:
    qemu-system-x86_64 $OPTS -drive file="guestOSinstaller.iso",index=2,media=cdrom -drive file=virtio-drivers.iso,index=3,media=cdrom -boot d
  6. After installation, run the guest OS:
    qemu-system-x86_64 $OPTS -boot c

No comments:

Post a Comment

Is your comment or question:

1. Constructive?
2. Interesting?
3. Short?

If not, please post it in your own blog.