Libvirt Web Manager

Screenshot of the initial design of the libvirt-based web manager I am creating . . .

Libvirt Web Manager

I am developing a Web based Manager for Libvirt written in c# using MVC. I am writing it to run on windows until the new release of mvc which will make the project multi platform. At that point, the manager can be used on a Linux host using the native libraries instead of using the Mingw built libraries. Get involved and help out at

Fedora 22 libvirt remote management setup without authentication


This method should only be used for testing purposes as there is no authentication and no encryption!

  1. Install Pre-reqs: Open a console
    sudo dnf -y update && sudo dnf -y install qemu-kvm libvirt virt-install bridge-utils
  2. sudo gedit /etc/libvirt/libvirtd.conf
  3. Change the following lines:

    #listen_tls = 0


    listen_tls = 0

    #listen_tcp = 0


    listen_tcp = 1

    #auth_tcp= “sasl”


    auth_tcp= “none”

    Now save the file
  4. In a console, type
    sudo gedit /etc/sysconfig/libvirtd
  5. Change the following lines:



    Now save the file
  6. In a console, type
    sudo systemctl start libvirtd.service
  7. In Console type
    sudo systemctl enable libvirtd.service
  8. Add Firewall Rules

    If you want to use TLS to connect to libvirt, add the below rule

    sudo firewall-cmd --permanent --add-port=16514/tcp

    If you want to connect to your VM’s using NoVNC, or VNC add the below rule

    sudo firewall-cmd --permanent --add-port=5700-6000/tcp

    If you want to use Regular –Unencrypted– TCP to connect to libvirt, add the below rule

    sudo firewall-cmd --permanent --add-port=16509/tcp
  9. Restart Firewall so Rules can take effect
    sudo systemctl restart firewalld.service

Thats it, now you can connect via tcp without having to authenticate. Be sure to use this for testing only!

How to Build Libvirt for windows using Fedora 22

  1. Install Prereqs
    In a console type

    sudo dnf update && sudo dnf install -y autoconf automake gcc gcc-c++ mingw64-gcc mingw64-gcc-c++ mingw64-zlib mingw64-libxml2 mingw64-portablexdr mingw64-gnutls mingw32-gcc mingw32-gcc-c++ mingw32-zlib mingw32-libxml2 mingw32-portablexdr mingw32-gnutls

  2. Get Files:
    Download the latest source code from For example, I downloaded libvirt-1.2.16.tar.gz.
  3. Extract Files:
    Extract the downloaded files anywhere on the machine, I extracted mine to /home/scott/Downloads/libvirt-1.2.6/
  4. Configure Build
    Open Terminal and change directory to the extracted files from above. Now Type


  5. Running Make
    In a console type

    sudo make

  6. Running Make Install
    In a console type

    sudo make install

  7. Copy /usr/x86_64_w_64-mingw32/sys-root/mingw/bin contents to a windows machine and get starting using virsh.exe


There is a bug that has been in the libvirt library since 1.2.14 for the windows build that causes an error when connecting to a libvirt host. The error message is ‘Internal Error: Received hangup / error event on socket.’ I have submitted a bug report, we will see how long before it is fixed. Until then, you can build version 1.2.13 and run it without issue. . . Enjoy.

Next post will be how to enable tls for libvirt for remote management.

Ubuntu 14.04 Libvirt compile and install

  1. Install Prereqs
    In a console type

    sudo apt-get update && sudo apt-get install qemu-kvm libvirt-bin qemu-system

  2. Get Files:
    Download the latest source code from For example, I downloaded libvirt-1.2.16.tar.gz.
  3. Extract Files:
    Extract the downloaded files anywhere on the machine, I extracted mine to /home/scott/Downloads/libvirt-1.2.6/
  4. Install Dependencies:
    Open a terminal, and type

    sudo apt-get install gcc make pkg-config libxml2-dev libgnutls-dev libdevmapper-dev libcurl4-gnutls-dev python-dev libpciaccess-dev libxen-dev libnl-dev libyajl-dev uuid-dev

  5. Configure Build
    Open Terminal and change directory to the extracted files from above. Now Type

    ./ –system

  6. Running Make
    In a console type

    sudo make

  7. Running Make Install
    In a console type

    sudo make install

  8. Restart Libvirt

    sudo service libvirt-bin restart

  9. Check installed version

    libvirtd –version

    The version should be updated now.

Libvirt on Windows Part II

I have successfully started developing a VM Mamangement tool on windows utilizing C#. So far, it is progressing better than I expected — the libvirt library is really fantastic! I am modeling the start of the tool after the VM Manager in linux.

You can check out the solution here

Libvirt on windows

I am experimenting with libvirt, and my favorite IDE is visual studio so I looked for an easy method to build the libvirt library on windows and found that the state of cross-platform libraries like Mingw are outdated or difficult to use correctly. I know there is a way, but assembling the right libraries and commands was just too much. So, I found that the libvirt dll’s are actually a part of most distros of linux and can be downloaded and extracted. I just needed to find out what dlls were needed, then search the repos for those files.

After the search, I have begun work on a powershell script to get the latest libvirt builds from fedora, download and extract them. After that, you can go to town building libraries against the libvirt api. Check out the script here:

Anyone who links against the libvirt library would be creating a management tool of some sort so a language like C# so after I create this tool, I will write some code to generate the C# code files for the DLLImport calls. The Libvirt header thousands of lines long so I will write some code to extract the calls/structs and generate the PInvoke calls for everything at once.

SystemParametersInfo Error

While working on the desktop sharing program, I came across a very interesting bug in the SystemParametersInfoW function while trying to get the current users wallpaper.

THE FIX IS TO USE SystemParametersInfoA — this works as expected: no junk data added and no buffer overrun.

Here is the code to reproduce the error — THERE IS NO OTHER CODE

#include <windows.h>

int main()

wchar_t OldWallpaper[MAX_PATH * 4];
for (auto i = 0; i < 5; i++){
SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, OldWallpaper, 0);
return 0;

I put this into a loop so I could see the data changing in the debugger by inserting a break point at the end of each for loop iteration. What I found was that the variable OldWallpaper was being filled with all sorts of junk data, sometimes it had something about ‘TRS\\USERS’, another time it was ‘\\.\DISPLAY6′. The upside is that the first character was always a null character if there was no wallpaper selected, so the function is partially correct. In cases where a wallpaper did exist, junk data was inserted after the path.

Now, I could live with this, but the function occasionally overan the buffer by a few characters at random times. It was causing heap corruption and crashing the program because the function was overrunning the buffer. My recommendation is to use twice the buffer to give it space to grow when needed.

If you look up SystemParametersInfo with SPI_GETDESKWALLPAPER, the function expects the size of the buffer in CHARACTERS, not bytes, as stated below for SPI_GETDESKWALLPAPER:

Retrieves the full path of the bitmap file for the desktop wallpaper. The pvParam parameter must point to a buffer to receive the null-terminated path string. Set the uiParam parameter to the size, in characters, of thepvParam buffer. The returned string will not exceedMAX_PATH characters. If there is no desktop wallpaper, the returned string is empty.

In any case, the junk data being returned is problematic even if the function should take the number of bytes instead of the number of characters.

You can view the bug report here which contains the images of the bug.


Desktop Viewer status

I currently have a working, stable VNC-like remote viewing desktop application at In all of my tests, it outperforms VNC on network traffic by 2-4X, and performance is the same.

All of the functionality is there, copy/paste between client and server; drag and drop file transfer. If you install the server as a service, which you can do by running the server exe with the -install command, it will allow you to view the Login Screen, Windows Locked Screen, Switch Users screen and the server will persist across reboots.

Next on the list

  • Support for more than 1 monitor
  • add option for server to remove itself upon command from viewer (this is most helpful when you want to connect to assist someone, then completely remove the application) — the code is done, I just need to tie it in.
  • Create a Proxy Server which will allow the server and client to be behind a NAT device and still connect to each other. It acts as a bridge between internal networks.

code postings

I have stopped work on my c# VNC like application. You can view the code on Github at  The application is stable, but has lag spikes that occur at random times. I suspect that the problem is the garbage collector, but I dont want to go into tracking this problem down because this would be going against the language. Others might say that it is natural to have to optimize code, but the type of optimization necessary is like helping a blind man see.

So, i decided to re-write it in c++! You can check it out at The code is stable and will capture UAC, Logon log off, and regular windows operations. It is better than vnc in all of my performance/networking testing by wide margins. Additionally, it is about 10X faster than the C# equivalent code and does not have fluctuations in its running as my c# application did.

The only issue is when switching users, this causes the program to get “confused.” Once the user logs back into the desktop everything resets.  This was designed for Vista and forward.. It might work on XP, but I havent tried and dont plan on supporting an old OS.

Encryption is in place, but I have to hook it in. Within the next few days I guess. . . .