- Updates
- Requirements
- Installation
- Services
- Basic virsh commands
- VM Configuration file for Linux guests
- Boot from CDROM or HD
- Map or pass through USB drive direct to libvirt
- VM Configuration file for Windows guests
- MS Windows on KVM-QEMU with QCOW2 Snapshots
- VGA and GPU passthrough
- Spice remote access
- Modify qcow2 image size
- Load KVM images in VirtualBox
- Secure connection to VMs through Virtual Machine Manager

- Updates


------->

Update version: 1
Update for Debian 10 codename "Buster":

Update note:
We have added information on how to share a single WIFI adapter with KVM, since there no native KVM option available yet. 
The solution consists of the implementation of a WIFI Bridge, and we did it, but it DOESN'T WORK on a Windows 10 Pro licensed Virtual Machine yet. In fact, we consider the current update as a work in progress/pending issue.
If you wan't to use a Wifi adapter ready KVM VM, you can attach an USB Wifi to your Laptop, and yes a Laptop or Dektop computer, because WiFi is primarily thought for Personal Computers instead of servers.
The solution hasn't been tested on Linux Virtual Machines either, but it is supposed that will work easily.
References:
Files: (Directory) WIFI Bridge (yet unavailable but not impossible).

Update note 2:
We have added a little of extra information through the document whether it was required.

------->

Update version: 1
Update for Debian 10 codename "Buster":

Update note:
From Debian 10 codename "Buster" I run the installation commands something like this:
$ sudo apt-get update
$ sudo apt-get install aptitude
$ sudo aptitude install libvirt0 qemu-kvm virtinst
$ sudo aptitude install virt-manager

------->

Update version: 2
Update for Debian 9 codename "Stretch":

Update note:
From Debian 9, codename "Stretch" substitute 'libvirtbin' with 'libvirt0'. You can add 'qemu-kvm' to the installation string if aptitude doesn't add it automatically.

------->


- Requirements

Platform: KVM server architecture and Operating System must be 64bit.
Check if processor supports KVM  (Intel VT or AMD-V):
# egrep '(vmx|svm)' --color=always /proc/cpuinfo
Should see something on the console like 'svm' in color red.


Bridged Wireless (WIFI) card option is not implemented in libvirt (yet?). Optionally, you can setup an USB wireless dedicated to an only guest, or use Virtualbox instead KVM virtualization. VirtualBox has already the wireless bridge option available in the section "Network" of the VMs "Settings", and it works.

Guides: 
Basic Networking
VirtualBox
Wine
Qemu

- Installation

Update repositories:
# apt-get update

Installing KVM:
# aptitude install kvm libvirt-bin virtinst

Install Virtual Machine Manager:
$ sudo install virt-manager
You have to create the vm container (.qcow2) using this application. It has more options
but don't touch what is different in the xml file in the configuration or can damage the VM.
Use keys CTRL + ALT to go from VMs to your desktop.

Add the user as which we're currently logged in (root) to the group libvirt:
# adduser `id -un` libvirt
To verify that the user is there we can open this file:
# nano /etc/passwd

You need to log out and log back in for the new group membership to take effect.

To check if KVM has successfully been installed, run:
root@foobar:~# virsh -c qemu:///system list
 Id Name                 State
----------------------------------

root@foobar:~#

If you catch an error instead something went wrong.
References:
Topic: What is the difference between qemu:///system and qemu:///session? Which one should I use?
Web: https://wiki.libvirt.org/page/FAQ#Where_are_VM_config_files_stored.3F_How_do_I_edit_a_VM.27s_XML_config.3F
File: FAQ - Libvirt Wiki.pdf

References:
Topic: What is KVM. Explain how KVM works.
Web: http://www.linux-kvm.org
Topic: How to install Window 7 OS on KVM. Go to section: Windows 7 as guest on Debian squeeze - with libvirt's virt-install recipe and virtio disk driver step-by-step instructions
Web: http://www.linux-kvm.org/page/HOWTO
Topic: How to install KVM:
Web: http://www.howtoforge.com/virtualization-with-kvm-on-a-debian-lenny-server
Web: http://wp.libpf.com/?p=186

Remember Setting up bridge networking. Best way is to see the guide: "Basic networking"
References:
Topic: KVM Debian Wiki.
Web: https://wiki.debian.org/KVM

- Services

$ sudo systemctl status libvirtd.service
$ sudo systemctl status libvirt-guests.service

- Basic virsh commands

Do not use  but as example of new virtual machine you can do:
# virt-install --connect qemu:///system -n aestudio -r 768 --vcpus=1 -f ./aestudio.qcow2 -s 40 -c debian-6.0.6-amd64-i386-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debianSqueeze --accelerate --network=bridge:br0 --hvm
References:
Topic: How to pass QEMU command-line options through libvirt. Internal note: Here I have some files like this referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"virtio-gpu and libvirt/
Web: http://blog.vmsplice.net/2011/04/how-to-pass-qemu-command-line-options.html
File: Stefan Hajnoczi_ How to pass QEMU command-line options through libvirt.pdf

# cd /var/lib/libvirt/qemu
# virsh
virsh # --connect qemu:///system
virsh # help
virsh # list --all
virsh # list
virsh # define win10pro.xml
virsh # undefine win10pro
virsh # start win10pro
virsh # reboot win10pro
virsh # shutdown win10pro.xml

Exit to bash prompt:
virsh # exit
virsh # quit

Kill Virtual Machine Manager when fails, unable to reconnect, and idle:
# top
# pkill virt-manager

- VM Configuration file for Linux guests

Virtual Machine: Linux server
VM config file: x2.xml                             
Description: Basic configuration file

<domain type='kvm'>
  <name>x2</name>
  <uuid>fcb926c0-cd64-4af9-9718-5b5712067388</uuid>
  <memory>390000</memory>
  <currentMemory>390000</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type arch='i686' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='cdrom'>
  	<driver name='qemu' type='raw'/>
  	<source file='/var/lib/libvirt/images/KNOPPIX_V7.0.5DVD-2012-12-21-EN.iso'/>
  	<target dev='hdc' bus='ide'/>
  	<readonly/>
  	<address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/x2.qcow2'/>
      <target dev='hda' bus='scsi'/>
    </disk>
 <interface type='bridge'>
      <mac address='00:50:56:3E:06:0B'/>
      <source bridge='br0'/>
       </interface>
 <interface type='bridge'>
      <mac address='00:50:56:2A:04:3A'/>
      <source bridge='br0'/>
       </interface>
 <interface type='bridge'>
      <mac address='00:50:56:3D:F8:0E'/>
      <source bridge='br0'/>
       </interface>
 <interface type='bridge'>
      <mac address='00:50:56:36:4F:EC'/>
      <source bridge='br0'/>
       </interface>
 <interface type='bridge'>
      <mac address='00:50:56:32:52:C1'/>
      <source bridge='br0'/>
       </interface>
    <input type='mouse' bus='ps2'/> 
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>
  </devices>
</domain>

- Boot from CDROM or HD

Two ways to edit the VM configuration file, but use the second:
1. Using virtual shell (virsh) command:
# virsh
virsh # list --all
virsh # shutdown win10pro.xml
virsh # edit win10pro
2. Using xml file directly:
$ sudo nano /var/lib/libvirt/qemu/win10pro.xml
And then replace the tag:
<boot dev='cdrom'/>
by:
<boot dev='hd'/>

Restart the VM to review the xml changes.

- Map or pass through USB drive direct to libvirt

My USB card is supported but my External HD Drive is not installing the driver. It is supposed that KVM supports USB 1.0 and 2.0. I need to research the probability to map/passthrough using virtio drivers parameters in the VM or passthrough XML files (Pending). Meawhile I still use the Internet to share data between the host and guest.
References:
Topic: Mapping drives
Web: http://serverfault.com/questions/348983/mapping-usb-drive-direct-to-libvirt-kvm-virtual-machine
File: kvm virtualization - Mapping USB drive direct to libvirt KVM virtual machine_ - Server Fault.pdf

Passthrough steps:

To get the vendor and product numbers of the USB devices:
$ lsusb
For example:
Bus 005 Device 002: ID 10f1:1a13 Importek 
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Use the numbers in the sixth column "10f1:1a13"
Vendor: 10f1
Product ID: 1a13

To passthrough the soundcard:
Create the file usbpassthrough-soundcard.xml:
<hostdev mode='subsystem' type='usb'>
  <source>
    <vendor id='0x10f1'/>
    <product id='0x1a13'/>
  </source>
</hostdev>

# virsh
virsh # attach-device win10pro /var/lib/libvirt/qemu/usbpassthrough-soundcard.xml 
To detach:
virsh # detach-device win10pro /var/lib/libvirt/qemu/usbpassthrough-soundcard.xml 

To passthrough the External HD Drive:
Create the file usbpassthrough-externalstorage.xml:
<hostdev mode='subsystem' type='usb'>
  <source>
    <vendor id='0x1058'/>
    <product id='0x0740'/>
  </source>
</hostdev>

# virsh
virsh # attach-device win10pro /var/lib/libvirt/qemu/usbpassthrough-externalstorage.xml 

Notes: 
win10pro is the VM of the same XML file under ../images
Attach is live operation which is not going to work with the virtual machine turned OFF.

References:
Topic: USB Passthrough not working for Windows 7 guest.
Web: https://bugs.launchpad.net/qemu/+bug/685096
File: USB Passthrough not working for Windows 7 guest _ Bugs _ QEMU.pdf
Topic: virt-manager USB 2.0 problem
Web: http://askubuntu.com/questions/192804/virt-manager-usb-2-0-problem
File: virtualization - virt-manager USB 2.pdf
Topic: Using USB pass-through under libvirt and KVM
Web: https://david.wragg.org/blog/2009/03/using-usb-pass-through-under-libvirt.html
File: Using USB pass-through under libvirt and KVM.pdf
Web: https://david.wragg.org/blog/2009/03/usb-pass-through-with-libvirt-and-kvm.html
File: USB pass-through with libvirt and KVM, part two.pdf
Topic: Adding Hard Drives and Other Block Devices to a Guest
Web: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-Virtualization-Adding_storage_devices_to_guests-Adding_hard_drives_and_other_block_devices_to_a_guest.html
File: 13.3.2.pdf
Topic: External Drive Not Recognized? This Is How To Fix It In Windows
Web: http://www.makeuseof.com/tag/external-drive-not-recognized-this-is-how-to-fix-it-in-windows/
File: External Drive Not Recognized_ This Is How To Fix It In Windows.pdf
Topic: Retrieve extra information on specific pci or usb devices with 'lspci' and 'lsusb'. See section: - Manual Wireless interface installation in Gnome
Guide: Basic Networking

- VM Configuration files for Windows guests

Virtual Machine: Windows 7, 8 and 10
VM config file: win10pro.xml                             
Description: Basic configuration file without video ram share

<domain type='kvm'>
  <name>win10pro</name>
  <uuid>fcb926c0-cd64-4af9-9718-5b5712067388</uuid>
  <memory>2340000</memory>
  <currentMemory>2340000</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='cdrom'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='cdrom'>
  	  <driver name='qemu' type='raw'/>
  	  <source file='/var/lib/libvirt/images/Win_7_64Bit.iso'/>
  	  <target dev='hdc' bus='ide'/>
  	  <readonly/>
  	  <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/virtio-win-0.1.102.iso'/>
      <target dev='hdd' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/win10pro.qcow2'/>
      <target dev='vda' bus='virtio'/>
    </disk>
 <interface type='bridge'>
      <mac address='00:50:56:3E:06:0B'/>
      <source bridge='br0'/>
       </interface>
    <input type='mouse' bus='ps2'/> 
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>
  
  </devices>
</domain>

Virtual Machine: Windows 7, 8 and 10
VM config file: win10pro-v2.0.xml                             
Description: Basic configuration file which includes 2 video ram share alternatives to choose from (no second video car with passthrough (PCI passthrough) required), audio with qemu headers, and minimun acceptable MS Windows 10 requirements set up. Definitely, use this to virtualize MS Windows 10!

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>win10pro</name>
  <uuid>fcb926c0-cd64-4af9-9718-5b5712067388</uuid>
  <memory>2340000</memory>
  <currentMemory>2100000</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='cdrom'>
  	  <driver name='qemu' type='raw'/>
  	  <source file=''/>
  	  <target dev='hdc' bus='ide'/>
  	  <readonly/>
  	  <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file=''/>
      <target dev='hdd' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/win10pro.qcow2'/>
      <target dev='vda' bus='virtio'/>
    </disk>
 <interface type='bridge'>
      <mac address='00:50:56:3E:06:0B'/>
      <source bridge='br0'/>
       </interface>
    <input type='mouse' bus='ps2'/> 
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>
     <video>
      <model type='cirrus' vram='256000' heads='1'/>                                                            
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
     </video> 
 <!-- <video>
        <model type='vga' vram='256000' heads='1'>
        </model>
     </video> //-->
     <sound model='ich6'>
        <codec type='micro'/>
     </sound>
  </devices>
<qemu:commandline>
  <qemu:env name='QEMU_AUDIO_DRV' value='pa'/>
  <qemu:env name='QEMU_PA_SAMPLES' value='8192'/>
  <qemu:env name='QEMU_AUDIO_TIMER_PERIOD' value='99'/>
  <qemu:env name='QEMU_PA_SERVER' value='/run/user/1000/pulse/native'/>
</qemu:commandline>
</domain>

Virtual Machine: Windows XP Pro
VM config file: XPROSP2.xml                             
Description: Basic configuration file

<domain type='kvm'>
  <name>XPROSP2</name>
  <uuid>fcb926c0-cd64-4af9-9718-5b5712067389</uuid>
  <memory>390000</memory>
  <currentMemory>390000</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='i686' machine='pc'>hvm</type>
    <boot dev='cdrom'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='cdrom'>
          <driver name='qemu' type='raw'/>
          <source file='/var/lib/libvirt/images/XPRO_SP2.iso'/>
          <target dev='hdc' bus='ide'/>
          <readonly/>
          <address type='drive' controller='0' bus='1' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/home/esteban/Documents/INA English/Interchange/Self-Study DVD-ROM/IC4 Self-study,.iso'/>
      <target dev='hdd' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/XPROSP2.qcow2'/>
      <target dev='hda' bus='scsi'/>
    </disk>
 <interface type='bridge'>
      <mac address='00:50:56:3E:06:0B'/>
      <source bridge='br0'/>
       </interface>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>

  </devices>
</domain>

- MS Windows on KVM-QEMU with QCOW2 Snapshots

Preparing a XML file:
VM config file: win10pro.xml
Windows 10 requirements:
Processor: 1 gigahertz (GHz) or faster.
RAM: 1 gigabyte (GB) (32-bit) or 2 GB (64-bit)
Free hard disk space: 16 GB.
Graphics card: Microsoft DirectX 9 graphics device with WDDM driver.
A Microsoft account and Internet access.

List of Windows 7, 8 and 10 requirements:
1- Have two CDROM units in the XML configuration file
2- Download and install virtio driver image from Red Hat during the MS Windows installation
3- Install the correct SCSI driver, viostor.
Optionally:
4- You can install more virtio drivers like the RAM Ballooning.
5- Before or after the installation you should change the default video driver and passthrough a video card dedicated for the guest OS.

1- Have two CDROM units in the XML configuration file

References:
See XML file for Windows 7, 8 and 10.

2- Download and install virtio driver image from Red Hat during the MS Windows installation
3- Install the correct SCSI driver, viostor

References:
Web: http://www.azertech.net/content/windows7-kvm-qemu-qcow2-snapshots
File: Windows7 on KVM-QEMU with QCOW2 Snapshots _ Azer Technology.pdf
Topic: Download the virtio driver image from Red Hat
Web: http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/
Topic: Installing the Drivers on an Installed Windows Guest Virtual Machine
Web: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/form-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Para_virtualized_drivers-Mounting_the_image_with_virt_manager.html
File: 10.2.pdf

4- (Optionally) You can install more virtio drivers like the RAM Ballooning

References:
Topic: Installing the Drivers on an Installed Windows Guest Virtual Machine
Web: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_host_configuration_and_guest_installation_guide/form-virtualization_host_configuration_and_guest_installation_guide-para_virtualized_drivers-mounting_the_image_with_virt_manager
File: Installing the Drivers on an Installed Windows Guest Virtual Machine.pdf

5- (Optionally) Before or after the installation you should change the default video driver and passthrough a video card dedicated for the guest OS. The final step is installing the right driver in the guest OS. 
See the section: "VGA and GPU passthrough" to proceed with any Windows Guests.
I am not using the virtio for video due to I am sharing my video card with the guest, instead of using a passthrough, but here are the notes anyway. I hope they are useful.

Examples of alternatives to shared video card host and guest (simplest configuration):

Example with Virtio video driver:
References:
Guide: This guide, see section "- MS Windows on KVM-QEMU with QCOW2 Snapshots" to know how to download virtio iso. You will find this site, and there read the "deprecated" README: https://dl.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/
References:
Topic: virtio-gpu and libvirt. libvirt has no support for virtio-vga. There is a bug for virtio-vga support in libvirt. But for the time being we need to play some tricks. Luckily libvirt has some special xml syntax to pass command line options to qemu. Internal note: This reference is under the directory "virtio-gpu and libvirt" of the guide "3D Acceleration and VR": Here I have some files referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: https://www.kraxel.org/blog/2015/10/virtio-gpu-and-libvirt/
File: virtio-gpu and libvirt _ kraxel's news.pdf

At the end the next new section is supposed to be after the section <graphics></grapics> in the XML file (<graphics type='vnc' port='-1' listen='127.0.0.1'/>):
    <video>
      <model type='virtio' vram='32468' heads='1'>
      </model>
    </video>

Example with QXL video driver:
Windows 8 or later require drivers following the Windows Display Driver Model, so the standard qxl driver won't work. You will need the qxl-dod driver for which binaries are available.
References:
Topic: Windows disk and video drivers in KVM
Web: http://bart.vanhauwaert.org/hints/installing-win10-on-KVM.html
File: Installing Windows 10 on KVM.pdf
Topic: Windows Display Driver Model
Web: https://en.wikipedia.org/wiki/Windows_Display_Driver_Model
File: Windows Display Driver Model - Wikipedia, the free encyclopedia.pdf
Topic: Latest available qxl-dod driver
Web: http://people.redhat.com/~vrozenfe/qxlwddm/
Web: https://github.com/vrozenfe/qxl-dod

Example of problems with Windows XP PRO SP2:
Probably I am not using a good compilation of QXL drive, but the correct type (XP is not Windows 8 or later).
References:
Topic: WDDM (Windows Display Driver Model)
Web: https://en.wikipedia.org/wiki/Windows_Display_Driver_Model
File: Windows Display Driver Model - Wikipedia, the free encyclopedia.pdf
I already installed QXL driver with spice vd-agent, but doesn't work well. The problem is that the pointer doest target objects inteh desktop and even the desktop itself. The problem is not the configuration.. but qxl doesn't work on my Win XP VM (Local Virtual Manager accessed. Remote or HTML access not tried yet). The reason can be that my machine doesn't support the usage of qxl, according to next document.
Topic: Look for the tag <video> and virtio options
Web: https://libvirt.org/formatdomain.html
File: Domain XML format.pdf
Steps done:
You need to install soft in the guest VM.
Web: http://mapopa.blogspot.com/2011/11/installing-qxl-drivers-on-windows7.html
File: Installing qxl video drivers on windows7 and XP.pdf
Topic: Here explains but, spice-guest-tools doesn't work on XP (I don't know if in Win7), and I actually downloaded pre-compiled EXE QXL driver and spice vd-agent files (instead of GIT files) from the previous web mentioned.
Web: https://spice-space.org/download.html
File: Windows guest tools.pdf
Topic: Explanation of GL (Actually  QXL GL acceleration doesn't work in Windows guests yet), web file sharing and more. 
Web: https://spice-space.org/spice-user-manual.html#_folder_sharing
File: Spice user manual.pdf
At the end the section was supposed to be after the section <graphics></graphics> in the XML file:
	<video>
	  <model type='qxl' ram='131072' vram='131072' vgamem='65536' heads='1'/>
	  <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
	</video>

- VGA and GPU passthrough

Topic: KVM: Single display, single GPU. Internal note: Here I have some files like this referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: https://www.reddit.com/r/linux/comments/402xdt/single_display_single_gpu_qemu_kvm_possible/
File: Single Display, Single GPU; Qemu-KVM possible?.pdf

To use a second video card in a KVM server guest Virtual Machine (VM) you need virtualization-capable IOMMU supporting hardware
References:
Topic: VGAPassthrough
Web: https://wiki.debian.org/VGAPassthrough
File: VGAPassthrough.pdf
Topic: GPU Passthrough with KVM and Debian Linux.
Web: https://scottlinux.com/2016/08/28/gpu-passthrough-with-kvm-and-debian-linux/
File: GPU Passthrough with KVM and Debian Linux.pdf
Topic: List of IOMMU-supporting hardware (Includes video cards). 
Web: https://en.wikipedia.org/wiki/List_of_IOMMU-supporting_hardware
File: List of IOMMU-supporting hardware (Includes video cards).pdf

References:
Topic: VGA and GPU passthrough. Sections: "OpenCL Virtualization ready Checklist", and "Versioning Compatibility Checklist" (Keyword = passthrough).
Guide: 3D Acceleration and VR

References:
Topic: Setup video card.
Guide: Video Card

In order to make the passthrough work you need to setup video tag to vga like this in the XML configuration file of the guest host:
Examples of VGA video driver:

    <video>
      <model type='vga' vram='32468' heads='1'>
      </model> 
    </video>

Or:

    <video>
      <model type='vga' vram='16384' heads='1'>
        <acceleration accel3d='yes' accel2d='yes'/>
      </model>
    </video>

Note: The first xml snippet works at sharing the only video card in the system, but the second snippet doesn't work. The cause can be that the virtual machine is KVM, and the acceleration option in the script (not the acceleration itself) only works with Virtualbox VMs, running from libvirt.
References:
Topic: This reference actually shows how to translate qemu commands into libvirt XML file syntax, but just search for every video and VGA option you can set, in the reference. Internal note: This reference is under the directory "virtio-gpu and libvirt" of the guide "3D Acceleration and VR": Here I have some files referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: http://wiki.libvirt.org/page/QEMUSwitchToLibvirt
File: QEMUSwitchToLibvirt - Libvirt Wiki.pdf

I think that the VGA setup in the XML host file is the only you need to make the passthrough work. With this ready prepare the passthrough in the KVM server OS, so:
Reference:
Topic: VGAPassthrough
Web: https://wiki.debian.org/VGAPassthrough
File: VGAPassthrough.pdf
Topic: GPU Passthrough with KVM and Debian Linux.
Web: https://scottlinux.com/2016/08/28/gpu-passthrough-with-kvm-and-debian-linux/
File: GPU Passthrough with KVM and Debian Linux.pdf

After you  prepared the passthrough in the KVM server OS, test it on the guest VM. You need to install the extra video card in the guest. Steps:
Topic: Installing the Drivers on an Installed Windows Guest Virtual Machine
Web: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_host_configuration_and_guest_installation_guide/form-virtualization_host_configuration_and_guest_installation_guide-para_virtualized_drivers-mounting_the_image_with_virt_manager
File: Installing the Drivers on an Installed Windows Guest Virtual Machine.pdf

- Spice remote access

If you want to have both local Virtual Machine Manager access to Guest with passthrough video cards and remote access to guests through the network, first setup the video with passthrough and then try to upgrade to Spice, using the QXL driver (probably you can setup both together in  different video tags in the XML host configuration file).

Spice is an open remote computing solution, providing client access to remote displays and devices (e.g. keyboard, mouse, audio). The main use case is to get remote access to virtual machines, although other use cases are possible and in various development stage.
Spice provides a desktop-like user experience, while trying to offload most of the intensive CPU and GPU tasks to the client. The basic building blocks of Spice are:
Spice Server
Spice Client
Spice Protocol

References:
Topic: Spice user manual
Web:  https://www.spice-space.org/spice-user-manual.html
File: Spice user manual.pdf

Topic: Redhat now distributes a Spice Video support package for Windows VMs. Not only does it install support for your Spice Video - you also get clipboard support to allow cutting and pasting between your VM and your desktop.
Web: http://www.spice-space.org/download.html
File: Download.pdf
Topic: Spice guest tools for Windows
Web: http://www.spice-space.org/download/windows/spice-guest-tools/

Topic: Windows guests binaries and configuration.
Web: https://spice-space.org/download.html
File: Windows guest tools.pdf
Web: http://mapopa.blogspot.com/2011/11/installing-qxl-drivers-on-windows7.html
File: Installing qxl video drivers on windows7 and XP.pdf

Topic: Adding Spice support to an existing virtual machine using qemu commands or libvirt XML syntax. Internal note: This reference is under the directory "Spice" of the guide "3D Acceleration and VR": Here I have some files referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: https://people.freedesktop.org/~teuf/spice-doc/html/ch02s03.html
File: Adding Spice support to an existing virtual machine.pdf
Web: http://www.linux-kvm.org/page/SPICE
File: SPICE - KVM.pdf

Topic: Controlling Virtual Machine with VNC and Spice. Internal note: This reference is under the directory "Spice" of the guide "3D Acceleration and VR": Here I have some files referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: http://www.admin-magazine.com/Archive/2013/13/Controlling-virtual-machines-with-VNC-and-Spice
File: VNC and Spice - ADMIN Magazine.pdf

Topic: Add SSL connection to Spice connection. Internal note: This reference is under the directory "Spice" of the guide "3D Acceleration and VR": Here I have some files referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: http://www.spice-space.org/page/SSLConnection
File: SSLConnection - Spice.pdf

Topic: Spice web client. Internal note: This reference is under the directory "Spice" of the guide "3D Acceleration and VR": Here I have some files referring to KVM topic under the references directory "./3D Acceleration and VR/References/OpenCL system installation alternatives/OpenCL Virtualization/KVM Linux/"
Web: https://www.spice-space.org/spice-html5.html
File: SSLConnection - Spice.pdf
Web: https://cgit.freedesktop.org/spice/spice-html5
File: Html5 - Spice.pdf

- Modify qcow2 image size

Topic: Increasing the Size of a qcow2 Image Under KVM
Web: http://www.naturalborncoder.com/virtualization/2014/12/05/increasing-the-size-of-a-qcow2-image-under-kvm/
File: Increasing the Size of a qcow2 Image Under KVM - Natural Born Coder.pdf

- Load KVM images in VirtualBox
Topic: - Load KVM images in VirtualBox
File: - Load KVM images in VirtualBox.pdf

- Secure connection to VMs through Virtual Machine Manager

Uses Client-Server(and Guest) model.

Install ssh in the server (vgui, running Debian Squeeze) and the backup server (foobar)
Check the ips constantly.
As per the user to access the Virtual Manager is xcapncrunchx create the authentication for xcapncrunchx

Install ssh:
References:
Guide: SSH Secure Shell

Setup the firewall ports accordingly:
References:
See guide: Netfilter

Note: It is mandatory to use the default SSH port, 22 for remote hosts, and some services and programs to work correctly. Check port availability, configuration and usage with netfilter, netstat and what is in the file /etc/services. See also the respective programs guides.

Automatic public key authentication.

            The authentication with a public key also is required for our objectives, is specially used special to execute local scripts in a remote machine without pass phrase typing in user command prompts. As follows:

            <1> The server and the backup-server had being accessed remotely, because the ssh directories we need are created while servers ssh was being configured, otherwise we do not have that dirs to work. After a process like that, restart the ssh service with the command sh> /etc/init.d/ssh restart (or use the equivalent systemd command '$ sudo systemctl restart ssh.service' or something like that). Enter to the server machine remotely or locally.
References:
Guide: Systemd

            <2> In the server machine go to the ssh directory. It is in the 'user-name' directory.

sh> cd /home/esteban/.shh/

            <3> Generation of the new public and private key.

sh> ssh-keygen -t dsa

            For old systems or ssh programs using the RSA algorithm instead of the DSA, use this other command:

sh> ssh-keygen -t rsa

            For DSA and RSA while the new key is being created the system will ask you where to put the new keys, then press ENTER key. When the system asks for a password press ENTER key again. We don't need the password because we want an automatically 'ssh' communication, with typing passwords, for our script, that we are preparing. In other stages this password can be needed, but not now.

            <4> Verify the new key is on our relative directory. There are two new keys, the key and key.pub with their default names: id_dsa.pub and id_dsa.

sh> ls

            <5> Send the public key (key.pub) to the /home/user directory  in the backup-server. Since the ./ssh directory (where we are)

sh> scp -P 49 id_dsa.pub esteban@backup-server-IP-adress-or-FQDN:~

            The scp program going  to show the public key was recorded in the backup-server. The -P option means the ssh port we are listen in both machines. That port was configured during the section “Hosts communication security enforce topics”.

            <6> Backup and Edit the ssh configuration's file in  the server:

sh> cp /etc/ssh/sshd_config /etc/ssh/sshd_configBAK

sh> vim  /etc/ssh/sshd_config

            Quit the '#' to the lines #AuthorizedKeysFile, and #%h/.ssh/authorized_keys.

            <6> In the backup-server machine, look for the public key we recently added to the user directory:

sh> cd /home/esteban/.ssh

sh> ls

            <7> Add the public key to the authorized_keys file, is in the user directory in the backup server.

sh> cat id_dsa.pub>.ssh/authorized_keys

            For other scenarios we can add more keys using 'cat file.pub >> authorized_keys ', to have all keys in the same file. Keys are function like registered IDs to enter to a building.

            <8> Restart the ssh service.

sh> /etc/init.d/ssh restart

            <9> Go back to the server machine and try to enter to the backup-server by type, from it and as user esteban to avoid errors:

sh> ssh -2 esteban@backup-serverIP-or-FQDN -p 49

            The number '2'  in the command, determines the use of the version 2 of the ssh protocol, esteban is the user who access using the new key, the part next to @ may be 192.168.1.40, and -p 49 defines the ssh port (do not use 22) to enter to the backup-server creating an unknown VPN. That port was previously configured in the section “Hosts communication security enforce topics”.  In case of we are using an incorrect port we are going to receive the message: “Connection Refused”.  

            If the configuration and the public key are working, we will see the prompt of the backup-server at this point.

            Note: For use other key file we can add an “i” to the command, specifying the path that public key.

sh> ssh -2  -i /etc/ssh/key2.pub esteban@backup-serverIP-or-FQDN -p 49

            Check where is the key in the remote machine.

            <10> Do the same process of authentication using public keys, but thinking the server is the backup-server and backup sever is the server, because our script to backup the server needs to send 'rsync' commands from one machine to other thorugh the ssh VPN tunnel.

            Note: There is another ssh in the market called ssh2 but we are not using it.

            Note: SSH combined in the way described here with the program 'sudo' can be used to execute root commands in a remote systems. Sudo is described in the section “Sudo to give root commands to users”.






