[HowTo] Run OMV as a KVM/qemu/libvirt host

  • OMV is a fantastic system like the swiss army knife of soho networking. As you have many tools in your workshop you some times need to run other things than your OMV installation supports.
    These other things can be run in a virtual machine on your OMV box.
    On my home OMV i am currently running a server with iRedMail/Roundcube and Owncloud. I am planning on moving my mythtv backend to a second vm on my OMV installation.


    This is a howto that describes how I made KVM/qemu/libvirt work under my OMV install. I choose to run KVM as a host platform for guest VM's because KVM is a intregral part of the Linux kernel and I believe that KVM is the hypervisor technology that is most efficient on Linux host systems. I used qemu and libvirt together with KVM for the same reasons. They work on the standard Linux kernel – no compilation and no kernel replacement. Stability and security is the most important factor when it concerns my household and our many irreplaceble personal data on our OMV NAS.
    This howto is based on a OMV that runs Squeeze backports. I don't know how it will work on standard Squeeze kernel. I have ”sudo” installed and my OMV gets it's ip-address from a static lease from my DHCP server. If you dont' have sudo install you can remove sudo from all my examples.
    To install Squeeze backports see http://forums.openmediavault.o…ic.php?f=10&t=2258#p13821


    First check if you CPU has virtualisation capability buildin.

    Code
    egrep '(vmx|svm)' /proc/cpuinfo


    look for 'svm' or 'vmx'. If neither of these is shown you cannot run KVM on your CPU and you must use another virtualisation technology like VirtualBox.
    Install KVM,libvirt and qemu.

    Code
    sudo apt-get update
    sudo apt-get dist-upgrade
    sudo apt-get -t squeeze-backports install qemu-kvm bridge-utils kvm libvirt-bin virtinst


    Since my KVM guest vil be a server, i need to be able to access the guest through it's own Ip-address and through NAT'ed connection from the internet. To this i need setup a network bridge on the host.
    Edit /etc/network/interfaces so it looks like this:


    or if you like me assigns the ip through a static lease from your router/dhcp server:


    restart nework with the new settings:

    Code
    sudo service networking restart


    make your adminuser member of the kvm and libvirt groups

    Code
    sudo adduser <adminuser> libvirt
    sudo adduser <adminuser> kvm


    Logout and login to make sure taht you have the new group membership in effect.
    Test if everything is working in your OMV and that

    Code
    sudo ifconfig

    shows your new br0 interface
    Start kvm and test if kvm is running

    Code
    sudo modprobe kvm
    sudo lsmod | grep kvm


    you should se someting like (depending on you processor Intel|AMD)

    Code
    kvm_amd                46642  3 
    kvm                   292670  1 kvm_amd


    Check that KVM and libvirt is installed and running

    Code
    virsh -c qemu:///system list


    since you have no virtual machines defined or running you should se something like

    Code
    Id    Name                           State
    ----------------------------------------------------


    Baiscally you now have a KVM host running. The host can be managed from either the commandline or by the application virt-manager installed on any machine on your network.


    install virt-manager to create and manage your hosts and guests
    To install virt-manager on another pc (mine are al Ubuntus or Debians) run:

    Code
    sudo apt-get install virt-manager


    Start virt-manager – choose add connection, chose hypervisor QEMU/KVM and insert the ip of your host system. Login with the hostssystems adminuser and password.


    Enter passwords etc.


    Now you have a virt-manager console connected to your OMV KVM hostssystem. In here you define and administer virtual guest vm's and storage areas on your OMV host. Define your vms and boot them from the downloaded iso files. I have defined two standard images – one Debian Wheeze and One Ubuntu 12.04.2. When ever i wan't to try something I make a clone of one of these and run the clone. Since KVM is a complete virtualisation host you can run all guest OS'es that run on x86 (32bit or 64bit). I haven't tried Windows guests because we don't have the need for Windows in our family.


    New to virt-manager and kvm – here's a short howto on defining storage pools and starting your first guest vm.
    Defining storage pools and your first guest vm
    Open virt-manager and connect to your host machine (OMV).
    Click ”connection details” move to the storage tab. Click on ”New Volume” and create a storage volume of your liking. I place my storage on a OMV share. Select the RAW format as this is the most cpu and disk efficient – remember the host is build on a low power cpu.


    Set the storage pool as started on boot.
    Create a storage volumes for you first guest machine. Make it of an fitting size. .raw images is of fixed size like ordinary harddisks and can only be altered with the same tools as ordinary disks. .qcow2 images can be altered by virt-manager but the again .qcow2 isn't as cpu and disk/io efficiet as .raw
    I have not defined Virtual networks since all my guests are servers and they need to be accessible from the outside so they will use the defined network bridge in /etc/network/interfaces. If you will run a workstation machine like a win desktop you can define and use virtual networks for this.
    Close the ”Connectons Details” window.


    Copy the iso image that you would like your vm's to install from into the directory of your defined storage pool this is easy if you have placed the storage poll on a share on your OMV.. You can have a selection of iso's to install from when you create machines.

  • Ceate a guest vm
    Choose ”create new machine”


    (I'm sorry but my machine is installed to danish so Næste=Next, Forrige=back and Annulér=Cancel)
    Choose Next. Choose use ISO image and click on Browse. Choose the Storage Pool you just defined and select the iso that you copied to the storage pool directory.
    Select apropriate OS type and Version. Click Next.
    Select the memory settings. I my example i am defining a Wheezy host so I can make do with 512M. Click next and choose ”Select managed or existing storage”. Browse to your storage pool and select the Volume you defined. You can also define a new Volume to use now by selecting ”New Volume”. When the volume is selected you are returned to the ”New VM” vindow. Select Next.
    Select ”Customize configuration before install” and select ”Specify shared device name” under advanced Options. Enter "br0" (no quotes) under bridge name: This is the network bridge defined in /etc/network/interfaces under install of kvm on the omv host.
    Click ”Finish”.
    In the next windows you can customize you guest vm.
    Under ”CPU” select ”Copy host CPU configuration” (If you later move this guest to a host with another CPU you must reset this parameter)
    Under ”VirtIO Disk 1” select ”Advanced” and select the ”virtio” interface. Select performance Options and set ”Cache mode” to none and ”IO mode” to native.
    Under ”NIC xx.xx.xx” select device model to ”virtio”.
    All these settings can be altered later if you need to.
    Leave all the other settings as default.
    Click ”Begin installation”.


    Virt-manager will display the console of the guest while booting the selected iso.Go on installation the vm.
    You must install support for ACPI on your guest to be able to shutdown the guest gracefully from within Virt-manager.


    There are a lot of howto's on the internet on how to define and administer guest vm's and storage pools on KVM/qemu/libvirt. Google is your friend.


    If you have no linux desktop!
    If you need to manage your KVM install from a Windows desktop pc you have some options:
    - use the libvirt commandline "virsh".
    see
    http://wiki.libvirt.org/page/FAQ, https://help.ubuntu.com/community/KVM/Virsh, http://www.rabexc.org/posts/ho…t-started-with-libvirt-on, http://pic.dhe.ibm.com/infocen…liaat%2Fliaatkvmvirsh.htm or http://acidborg.wordpress.com/…ual-machines-using-virsh/
    - Install Cygwin with virt-manager.
    - Install a local Virtualbox guest with Ubuntu or Debian to run virt-manager on.


    Short virsh command reference (in virsh the term domain equals guest vm's):
    -List your guests: "virsh list --all"
    -Start a predefined domain: "virsh start guestname"
    -Shutdown domain: "virsh shutdown guestname" This will shutdown the guest gracefull if it has ACPI capability.
    -Reboot: "virsh reboot guestname"
    -Terminate a guest - like pulling the power: "virsh destroy guestname"
    -To make a guest start automatic on host boot: "virsh autostart guestname"
    -To clone a guest: "virt-clone --original my-vm --auto-clone"


    To create a guest from the cli you can use virt-install ie:

    Code
    virt-install --connect qemu:///system -n My_First_Guest_Machine -r 1024 --vcpus=1 --disk path=/media/8b8dba5d-6565-48d6-9544-6fcf6a0c7800/images/kvm/virts/Wheezy-basis.img,size=12 -c /media/8b8dba5d-6565-48d6-9544-6fcf6a0c7800/images/kvm/virts/debian-7.1.0-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debianwheezy --accelerate --network=bridge:br0 --hvm


    Editing guest definitions in the CLI
    You can edit your guest definitions from the CLI on your host. The guest difinitionss are defined in .xml files default stored in /etc/libvirt/qemu. Be sure that the guest ins't running while you are editing it.
    Use the command:

    Code
    virsh edit <guest_name>

    this uses the default editor, which on OMV is set to vi. To use another editor like nano (which i prefer) you can use

    Code
    EDITOR=nano virsh edit <guest_name>


    Again google is your friend


    KVM Tuning tips
    I have made a collection af tuning tips to make the host and guests run most efficient with KVM. This is a major issue to me since my OMV is powered by an AMD E350 processor. There are many opinions on what is best regarding this.


    On the host
    Make the host swap only when it is absolutely necessary and make this permanent:

    Code
    sysctl vm.swappiness=0
    echo "vm.swappiness=0" >> /etc/sysctl.conf


    Set an efficient elevator in grub and better memory page management.
    Edit /etc/default/grub. In the line GRUB_COMMAND_LINE_DEFAULT insert

    Code
    transparent_hugepage=always elevator=deadline


    Update grub

    Code
    sudo update-grub


    On the guests (linux)
    Set the noop elevator in grub and better memory page management
    Edit /etc/default/grub. In the line GRUB_COMMAND_LINE_DEFAULT insert

    Code
    transparent_hugepage=always elevator=noop


    Update grub

    Code
    sudo update-grub


    NTP on guests should use kvm time module and not the guests own NTP service. Check that kvm-clock is loaded and disable the guests own ntp by:

    Code
    dmesg | grep kmv-clock

    You should se the kvm-clock module loaded during boot

    Code
    sudo service ntp stop
    sudo update-rc.d -f ntp remove


    When defining guests in virt-manager under advanced allways use ”virtio” as network device and disk device.
    Allways set the guest to use the hosts CPU features under CPU advanced.


    The virtio drivers for Windows guests can be found here: http://www.windowsservercatalo…cstext=&csttext=&chbtext=

  • Nice tutorial.


    However it would be nice if you would add the commandline commands to add virtual machines, as most of the users don't use gnome or kde or any desktop at all and don't have any linux client.


    Greetings
    David


    PS: We started the discussion on the other thread...: I have to take back what I said about Windows machines in the KVM "VM", i read in the wikipedia article that the KVM in the standard linux kernel is capable of running Windows natively, I did not thought this would be possible as it is not if you use proxmox, which uses a modified redhat kernel. (proxmox needs to run Windows in a VM, rather than a KVM Container...)

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • KVM is a fullblown/bare metal hypervisor. It can run all Guest OS's that uses the Intel/AMD architecture. In this tutorial i have also installed qemu. Qemu can emulate other CPU architectures like PowerPC as well - but then there is a performance penalty.
    I have added a litte about how to admin under Windows and som virsh ref url's

  • Thanks


    I also would not recommend it for everybody to set the swappiness to zero, depending on how much ram the individual user has and what applications are running...
    If your ram is nearly full, and you load an application that needs much ram, not only does your system needs to load the started application but also to swap files, which could render your system much slower!


    Greetings
    David


    PS: If linux is able to KVM right away, why is there any need for ESXi? ^^


    Edit: You forgot the instruction on how to add the backports sources, didn't you?

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Zitat von "davidh2k"

    I also would not recommend it for everybody to set the swappiness to zero, depending on how much ram the individual user has and what applications are running...
    If your ram is nearly full, and you load an application that needs much ram, not only does your system needs to load the started application but also to swap files, which could render your system much slower!


    I am allways runing vm.swappiness=0 on my linux servers except if they have very little ram. A swappiness set to 0 doesn't mean that it won't swap if it runs out of physical memory. With other settings to swappines linux will swap processes even though all memmory isn't used - just to be memory efficient.
    Swappiness=0 just tells the kernel to only swap when it is absolutely necessary - like no freee memory for a process. IMHO this is the best setting for linux servers.
    In the current case like a clean OMV system i would think you could set swappiness=0 if you have more that 2g ram.


    PS i have entered a ref to the posting about backports install.


    PSS yes why use a "foreign" hypervisor when you have the most efficient buildin your linux kernel.

  • Well, i'm trying it out ;) found a list of possible managing (web) interfaces too.


    Greetings
    David


    PS: My root has 32GB of ram, but I did not dare to set swappiness to zero :D

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Zitat


    Under ”CPU” select ”Copy host CPU configuration” (If you later move this guest to a host with another CPU you must reset this parameter)
    Under ”Disk 1” select ”Advanced” and select the ”virtio” interface. Select performance Options and set ”Cache mode” to none and ”IO mode” to native.


    I don't have these options, I only see virtio under NIC.
    My disk also is called "VirtIO Disk 1" and not simply "Disk 1" like yours.


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Don't you have a litte marker "advanced" under Disk?


    Are you using the .raw format or the qcow2 format for your disk?
    Oh and i missed the VirtIO in "VirtIO Disk 1" - corrected :o

  • I am gooing strictly after your tutorial!


    As you can see in the attachment, I don't have an advanced marker ;)


    Greetings
    David


    Edit: And i cannot copy cpu information as you posted above, also its called processor not cpu xD

    Bilder

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Is this WebVirtMan?
    Maybe they haven't implementet the advanced option under VirtIO Disk.
    If so you can edit this manually in the XML file for the Guest in /etc/libvirt/qemu

    Code
    virsh edit /etc/libvirt/qemu/the_name_of_the_guest.xml


    Look for:

    Code
    <disk type='file' device='disk'>
          <driver name='qemu' type='raw' cache='none' io='native'/>
          <source file='/media/8b8dba5d-6565-48d6-9544-6fcf6a0c7800/images/kvm/virts/MyFirstGuestsPool.img'/>
          <target dev='vda' bus='virtio'/>
          <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
        </disk>
  • Nope, iam tunneling virt-manager via xming/putty to my windows desktop. ;)


    So it should look like yours, except mine is older than yours ?


    Code
    root@chap:~# dpkg -l | grep virt-manager
    ii  virt-manager                               0.8.4-8                              desktop application for managing virtual machines
    root@chap:~#


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Yes yours is older. Mine is version 0.9.1
    Anyhow you can enter the options manually ind the .xml file
    David: You could load Ubuntu 12.04 or newer in a VirtualBox Vm on your Windows machine and run Virt-manager under Ubuntu

  • Debian Wheezy installation worked (alltough I had to select Debian Squeeze) and runs now. :)


    I'm trying to install Debian Mint Mate (Desktop system, runs live, can be installed to hard disk) but the installer does not recognize any hard disk. :(


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Zitat von "davidh2k"

    Debian Wheezy installation worked (alltough I had to select Debian Squeeze) and runs now. :)


    I'm trying to install Debian Mint Mate (Desktop system, runs live, can be installed to hard disk) but the installer does not recognize any hard disk. :(


    Good that you could make it vork. If you have Debian Wheezy working with X in a guest you could run virt-manager on it.
    According to http://packages.debian.org/wheezy/virt-manager it's the same version (0.9.1) of Virt-manager as mine. In virt.-manager 0.9.1 you can select which disk interface to emulate. Maybe emulating SATA or event IDE as disk could make Debian Mate boot.


    PS: In the original post Ihave written a litte ekstra about editing guests in CLI on the host.

  • Zitat von "davidh2k"

    I'm trying to install Debian Mint Mate (Desktop system, runs live, can be installed to hard disk) but the installer does not recognize any hard disk. :(


    Sorry it took so long to return on this. I had a failure on two disks on my raid. happy that it's raid 6. Took the only reserve from the closet and sync it up. So i'm still a disk short but I have ordered new wd red 3 tb disks. The old seagate 1.5T was from 2008 so they have been running 24/7 for 5 years. Quite good I believe.
    SMART reports that three more disks have rising value of reallocations so i belive they are about to go to the eternal fields of dead disks. I hope the WD reds arrive before they fail. Have startet an emergency rsync to my OMV backup NAS.


    I tried installing Mint Mate and it vent well. Disk and net was virtio drivers and video was cirrus. Can boot, start Firefox, browse the net and shut it down. No problems. I can post my .xml definition for you to try out if you like.


    BTW i had top showing load average 1 min going up til 40 when installing Mint while the mythtv server wrote gigs by NFS to the degraded raid6. Even under theese conditions the myth recordings was perfect and the installation of Mint vent well. Never had a machine working with that high a load average. OMV is avesome :D

  • Did you install Mint 15 with mate or did you use Debian Mint Mate?


    Greetings
    David

    "Well... lately this forum has become support for everything except omv" [...] "And is like someone is banning Google from their browsers"


    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Upload Logfile via WebGUI/CLI
    #openmediavault on freenode IRC | German & English | GMT+1
    Absolutely no Support via PM!

  • Zitat von "davidh2k"

    Did you install Mint 15 with mate or did you use Debian Mint Mate?


    Greetings
    David


    I have installed the ordinary Mint Mate 15. Not the debian version.

  • I have been trying to get this to work, but get the following when I try to connect with Virt-Manager:


    Unable to connect to libvirt.


    End of file while reading data: sh: nc: not found: Input/output error


    Verify that the 'libvirtd' daemon is running
    on the remote host.


    I did check that all was running according to the installation instructions, on this forum topic. Can anyone help me resolve this?

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!