Install Windows on Linux server with QEMU Virtualization

linux-kvmThis guide explains how you can install and use KVM for creating and running virtual machines on a CentOS 6.4 server. I will guide to install Windows on Linux server with qemu virtualization step-by-step to demonstrate how this must be done. KVM is short for Kernel-based Virtual Machine and makes use of hardware virtualization, i.e., you need a CPU that supports hardware virtualization, e.g. Intel VT or AMD-V. (Note: I wrote this quite a long time ago but it seems the article was disappeared due to some data loss in the past)

1. First, check CPU requirement

Check to be sure if your CPU supports virtualization (otherwise nothing will work):

[bash][root@canada ~]# egrep ‘(vmx|svm)’ –color=always /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave avx lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave avx lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave avx lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave avx lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid[/bash]

If there is nothing displayed, your CPU does not support VT and I must say “Poor you ;-)”. If it is ok, continue to next steps 🙂

2. Install necessary softwares

[bash][root@canada ~]# yum install kvm qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools
[root@canada ~]# chkconfig libvirtd on
[root@canada ~]# service libvirtd start[/bash]

. Check if the above softwares were installed properly:

[bash][root@canada ~]# service libvirtd status
libvirtd (pid 29269) is running…
[root@canada ~]# virsh -c qemu:///system list
Id Name State
—————————————————-
[/bash]

3. Setup network bridge

  • Install bridge-utils tool:

    [bash][root@canada ~]# yum install bridge-utils[/bash]

  • View current network configuration, remember BOOTPROTO, IPADDR, NETMASK, GATEWAY:

    [bash][root@canada ~]# less /etc/sysconfig/network-scripts/ifcfg-eth0[/bash]

  • Create a network bridge configuration at /etc/sysconfig/network-scripts/ifcfg-br0 with the following content (be sure TYPE=Bridge):

    [bash]DEVICE="br0"
    NM_CONTROLLED="yes"
    ONBOOT=yes
    TYPE=Bridge
    BOOTPROTO=static
    IPADDR=XXX.XXX.XXX.XXX
    GATEWAY=YYY.YYY.YYY.YYY
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=yes
    IPV6_AUTOCONF=no
    IPV6ADDR=ZZZZ:ZZZZ:ZZZZ:ZZZZ::1/128
    NAME="System br0"[/bash]

  • Change the /etc/sysconfig/network-scripts/ifcfg-eth0 and comment BOOTPROTO, IPADDR, NETMASK, GATEWAY, add BRIDGE=br0:

    [bash]DEVICE=eth0
    #BOOTPROTO=static
    #IPADDR=XXX.XXX.XXX.XXX
    #NETMASK=TTT.TTT.TTT.TTT
    ONBOOT=yes
    #GATEWAY=YYY.YYY.YYY.YYY
    IPV6INIT=yes
    IPV6_AUTOCONF=no
    IPV6ADDR=ZZZZ:ZZZZ:ZZZZ:ZZZZ::1/128
    BRIDGE=br0[/bash]

  • Restart network interface:

    [bash]/etc/init.d/network restart[/bash]

4. Install Windows server to KVM

  • View current supported os-variant (use rhel6 if you intend to install CentOS 6) by

    [bash][root@canada images]# virt-install –os-variant list[/bash]

  • Download Windows 2008 ISO at Microsoft Website.
  • Be sure to give the /dev/kvm the permission:

    [bash][root@canada images]# chown root:kvm /dev/kvm[/bash]

  • Install a Windows 2008 with ISO at /var/lib/libvirt/images/win2k8-eval-180d.iso, 100G HDD, 3G RAM, 2vCPU:

    [bash]virt-install -n Win2k8 –description "Win 2k8" –ram=3072 –vcpus=2 –os-variant=win2k8 –accelerate –hvm -c /var/lib/libvirt/images/win2k8-eval-180d.iso –network bridge:br0 –graphics vnc,listen=XXX.XXX.XXX.XXX,port=9999,password=abc123 –disk path=/home/kvm-images/Win2k8.img,size=100[/bash]

    . Continue by opening VNC with port 9999 and follow the installation procedures.

  • Managing the VM with some of the following commands (more commands HERE):
    • View all VMs:

      [bash]virsh list[/bash]

    • Displaying guest Information:

      [bash]virsh dominfo [domain-id, domain-name or domain-uuid][/bash]

    • Suspending a guest:

      [bash]virsh suspend [domain-id, domain-name or domain-uuid][/bash]

    • Resuming a guest:

      [bash]virsh resume [domain-id, domain-name or domain-uuid][/bash]

    • Shutting Down a guest:

      [bash]virsh shutdown [domain-id, domain-name or domain-uuid][/bash]

    • Rebooting a guest:

      [bash]virsh reboot [domain-id, domain-name or domain-uuid][/bash]

    • Terminating a guest:

      [bash]virsh destroy [domain-id, domain-name or domain-uuid][/bash]

TroubleShooting

  • To change a VM configuration, we can edit the XML file located at /etc/libvirt/qemu and then restart the VM to take the change into account.
  • We can always check which is visible commands for managing each configuration by
    [bash]virsh –help|egrep "info|mem"[/bash]
    . For example, if we want to change the max allow memory on the VM to 1.5G, we can run
    [bash]virsh setmaxmem VMWin2k8 1536M[/bash]
    on a non-active VM.
  • ERROR Guest name ‘Win2k8’ is already in use. Login to virsh to undefine that name:

    [bash][root@canada images]# virsh
    Welcome to virsh, the virtualization interactive terminal.

    Type: ‘help’ for help with commands
    ‘quit’ to quit

    virsh # undefine Win2k8
    Domain Win2k8 has been undefined

    virsh # quit[/bash]

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Install Windows on Linux server with QEMU Virtualization”