Posts Tagged ‘ KVM

Linux bridge: MAC addresses and dynamic ports

Scenario: KVM virtualization host running several bridged guests. The host has a bridge interface br0 that starts out containing only eth0, and other interfaces are dynamically added and removed from the bridge as guests are started and stopped.
The problem is, the host seems to randomly suffer some loss of connectivity (from a few to 30-40 seconds) when some guest is started or stopped. Initially one might think of something related to STP, but it turns out that it is disabled (and even then, ports appearing or disappearing should not affect existing ports).

What happens here is that, when a new guest is started, a tap interface is created and enslaved to the bridge (the tap interface is usually connected to the guest’s own ethernet interface). This interface has a name like vnet5, for example. Minor but important detail, this tap interface has a more or less random MAC address. (Note that we’re talking of the host-side tap interface, not the guest-side virtual interface, whose MAC address is configurable in the guest’s configuration file or on the command line). It is theoretically possible to set the MAC address of this host-side tap interface, but it’s quite involved and basically nobody does that (and also virt-manager has no provision to do that).

Now, by default bridge interfaces in Linux use, for their MAC address, the lowest MAC address among the enslaved interfaces. So if the newly created interface has a lower MAC, the bridge changes its MAC address and uses that of the new interface. When the guest is stopped, the tap interface is removed from the bridge and destroyed, at which point the bridge’s MAC address has to change again. Depending on when and how often guests are started/stopped, the host’s bridge interface may be changing its MAC address quite often.

Of course, this may (and does) cause connectivity problems for traffic to/from the host (fortunately, traffic to/from the guests is not affected), because neighboring computers and network devices suddenly have to update their ARP caches with the new MAC address before they can talk to the host. Depending on the traffic patterns, this may take anything from a few seconds to several tens of seconds.
Read more

Redirect port to guest in libvirt

If you want to redirect ports from WAN to quest Virtual Machine than you may do this:
Go to edit VM from Virsh

virsh edit my-vm-name

In header add xmlns

<domain type='kvm' xmlns:qemu=''>

Change interface type to user

<interface type='network'>

to this:

<interface type='user'>

Read more

Vagrant: libvirt library not found in default locations (RuntimeError)

vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:
An error occurred while installing ruby-libvirt (0.5.2), and Bundler cannot continue.
Make sure that `gem install ruby-libvirt -v '0.5.2'` succeeds before bundling.
Warning: this Gemfile contains multiple primary sources. Using `source` more than once without a block is a security risk, and may result in installing unexpected gems. To resolve this warning, use a block to indicate which gems should come from the secondary source. To upgrade this warning to an error, run `bundle config disable_multisource true`.Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
    /opt/vagrant/embedded/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.
Provided configuration options:
extconf.rb:73:in `<main>': libvirt library not found in default locations (RuntimeError)
Gem files will remain installed in /home/reverse/.vagrant.d/gems/gems/ruby-libvirt-0.5.2 for inspection.
Results logged to /home/reverse/.vagrant.d/gems/gems/ruby-libvirt-0.5.2/ext/libvirt/gem_make.out

Fix this problem with Vagrant

apt-get install libvirt-dev

Конвертация xva в KVM формат qcow2

Итак…имеем XenServer на котором крутятся виртуалки.
Задача: нужно перенести их в другое место. А под рукой есть только сервак с KVM

Заходим на Xenserver, делаем Snapshot и сохраняем его куда то.
Закидываем бекап на сервер с KVM
Наш файл имеет формат xva, это ни что иное как обычный архив

Распаковываем его

tar vxf vm1.xva
tar: Ref:50/00008193: implausibly old time stamp 1970-01-01 01:00:00
tar: Ref:50/00008193.checksum: implausibly old time stamp 1970-01-01 01:00:00

Read more

Управляем KVM через браузер с помощью WebVirtMgr

При работе с системами виртуализации всегда хочеться получить доступ к хост-машине с любой точки мира и с любого устройства которое есть под рукой. Если пользоваться штатными инструментами KVM, XenServer, VMWare то там необходима установленая консоль управления на локальном ПК и если нужно сделать, что то удаленно и быстро то возникают проблемы… начинаеш ставить консоль, не хватает .Net… поставил его, не хватает чего то другого. В результате, иногда, чтоб перегрузить умершую виртуалку требуется 30-60мин пока все скачаеш и поставишь. Хотя все это можно проделать с консоли за 30сек 🙂
Но мы не об этом.

Тут будет актуально имет скорый доступ к управлению через браузер, что даст возможность подключится даже с телефона.
Приступим к настройке.
Исходные данные: Debian 7.7
Настраиваем все с нуля.
Read more