Sunday, May 12, 2013

Can a KVM guest find out who it's host is?

Our puppet configuration performs a number of checks on our asset database to make sure things are recorded correctly.

One of the properties we record for virtual machines is their location (which host they are running on).

By default, KVM does not expose this information even though there are many ways it could technically be done.

Using bits and pieces from around the internet I have come up with a process where I can pass the serial number of the host into the guest.

qemu permits you to specify many DMI values on the command line like this:
qemu-kvm ... -smbios type=1,serial="MY-SERIAL"
The virtual machine will see this value and puppet will automatically create a fact with this value.

Unfortunately, libvirt does not use this mechanism and the serial number is blank in the virtual machine. The libvirt specification permits setting a value in the .xml config file but it is still not used.

I would like to insert a value which is the same as the host serial but with a prefix to indicate that this is indeed a virtual machine and then a suffix to make sure the serial is unique (such as the vm name).

Initially I used dmidecode to get the host serial number
dmidecode -s system-serial-number
but to run that you must be root and using sudo from the qemu user turned out to be a PITA. In the end I settled for
/usr/bin/hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.serial
which uses dbus but means I can run it without being root.

The next step was a shim around qemu-kvm which could add the command line parameters. On RHEL/CentOS 6, the binary lives in /usr/libexec so I put my wrapper in /usr/local/libexec (I think that is the first time I have ever used that directory). When a vm is being started, the first parameter is -name and then the machine name is specified (at least in the current EL6 version. This was not the case in a previous release so it could change). I check to see if that has been specified because qemu-kvm is also invoked by libvirt to check it's configuration/capabilities which does not require the dmi serial (although it does not hurt).

# This is a wrapper around qemu which will supply
# DMI information
if [ "$1" = "-name" ] ; then
    SERIAL=$(/usr/bin/hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.serial)
    exec /usr/libexec/qemu-kvm "$@" -smbios type=1,serial="KVM-$SERIAL-$2"
    exec /usr/libexec/qemu-kvm "$@"

The final step is to tell libvirt to use my new shim rather than the qemu-kvm binary directly. This also does not seem optimal but can be done by editing every guest and setting the <emulator> path to /usr/local/libexec/qemu-kvm
(either using virsh edit or your favourite XML editor).


  1. Any idea how one can get a comma into the manufacturer string?

  2. Finally, in step 10, we connect to the KVM guest using the console, list its interface configuration, and ensure that we can ping the bridge on the host OS.


    Spyhunter Keygen is malicious codes that snatch data, your PC working, and hide in your hardtack. but in the pretense of SpyHunter 5 Crack, there is no need to think about them now. SpyHunter 5 is able to detect such programs and files which contain such viruses and spyware. Alerts you whenever you try to download data. That help desk will help you until all issues resolve one by one.

    4K Video Downloader Crack is a video downloaded software with multi-functionality. It is a program to download songs, videos, and pictures, etc from YouTube and from various media channels. Drag the movie up and down as fast as you can with photos and posts. After all, you may like what you see on YouTube or similar media channels or sites, but it not allows you to download videos without this program.

    Adobe Photoshop CC Activation key format is very suitable for photographers and designers. This is also a tool that makes it easy to make websites, software programs, and icons. Articles include image editing and design software that support its creative cloud.

    YouTube By Click Crack is the most useful and famous video downloader software program. This fully supports the famous media site Youtube as its name displays. With only one click you can choose the format and can download your video. The “Youtube By Click” user can download special-quality videos in an adept method. If you’re finding the best video downloader app or software then what are you waiting to download it quickly.

    IDM Crack is simple and simple to utilize downloader and millions of popular have installed this application owing to its effortlessness and its 5x earlier rate. at the present, IDM Crack Key allow you to tear the folder you require to download to rationalize the download course and do it up to 5 era sooner than if you do it from the browser. Internet Download Manager has the skill of secure mixture downloading and folder division that provide you with the all downloading ability that you require.

  8. Tuxera NTFS Product Key
    Tuxera NTFS Product Key is an NTFS Industrial Car Owner made from the leading open-source driver of the NT 3GG file system. This application also completes reading and writing status compatibility with executables formatted with the NT file system on Mac. Access the store and quickly move documents.

  9. Safe Exam Browser Crack
    SEB for Windows 2.4 Crack Serial Key includes the SEB kiosk application, which opens it’s Windows desktop and system commands such as keyboard shortcuts (such as ALT + F4) and right clicks. The second part is Firefox, which works in XUL mode. The SEB XUL browser application running in Firefox communicates with LMS using a pre-configured start URL.

  10. Portrait Pro Studio Crack
    Cracked Here is a useful place where you can easily find Activators, Patch, Full version software Free Download, License key, serial key, keygen, Activation Key and Torrents. Get all of these by easily just on a single click.

  11. Total AV Antivirus Crack
    Total AV Antivirus Crack is an excellent software that is very popular due to his outstanding performance. This software also provides you essential security for your PC against each virus Adware and increases system performance and safety. They have many characteristics and tools that help you to check your system and search for every data on your PC.

    Internet Download Manager IDM Crack 6.38 Build 15 With Patch Free Download is the
    fastest and oldest internet download manager crack designed to increase your download
    speed up to 50 percent other than downloaders, IDM crack has the ability to resume
    due to network connection loss, network failure, computer shutdown or any issues that
    caused to disconnect your internet.

  13. chrispc screen recorder pro
    I am not sure where you are getting your information, but good topic.
    I need to spend some time learning much more or understanding more.
    Thanks for the fantastic information I was looking for this info
    for my mission.

  14. Heya this is somewhat of off topic but I was wanting to
    know if blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone
    with experience. Any help would be greatly
    wondershare dr fone crack

  15. I know this site provides good content and more information,
    Are there any websites that offer these features and quality?

    driver genius pro crack
    driverhub crack serial key
    zenmate premium crack

  16. I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored material stylish.
    nonetheless, you command get got a shakiness over that you wish
    be delivering the following. unwell unquestionably come further formerly
    again as the same nearly a lot often inside case you shield this hike.
    smadav crack
    actiondirector vide editor crack
    vmware fusion mac crack
    winzip pro crack activation code download

  17. If you are looking for bloggers, please let us know.
    Your position is very good, I think I will have a great advantage.
    If you want to lose some weight, I'm happy.
    Write something about your blog in exchange for my link.
    If you are interested, please email me, thanks!
    advanced systemcare pro key
    wolfram mathematica crack
    sketchup pro crack
    nero platinum crack