KVM HOST CentOS 7 Virtualization Host

CENTOS 7 VIRTUALIZATION HOST

Host: the machine that host other systems, KVM will be installed on this machine.
Guest: the system running in the host, also refered to as VM, Virtual Machine or domain.
Hypervisor: the piece of software that enables virtualization on the host. For example KVM, ESXi, Xen, …

File: host

1
192.168.2.22 kvmhost kvmhost.hochguertel.biz

SSH-Key austauschen:

1
2
3
4
5
ssh root@kvmhost
mkdir .ssh
chmod 600 .ssh
exit
cat ~/.ssh/*.pub | ssh root@kvmhost "cat >> ~/.ssh/authorized_keys"

KVM hypervisor and VM-extensions

1
egrep -c '(vmx|svm)' /proc/cpuinfo

Log: egrep -c '(vmx|svm)' /proc/cpuinfo

1
2
[root@kvmhost ~]# egrep -c '(vmx|svm)' /proc/cpuinfo
4

Log: cat /proc/cpuinfo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
[root@kvmhost ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz
stepping : 7
microcode : 0x29
cpu MHz : 799.937
cache size : 3072 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
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 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips : 3192.69
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz
stepping : 7
microcode : 0x29
cpu MHz : 804.625
cache size : 3072 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
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 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips : 3192.69
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz
stepping : 7
microcode : 0x29
cpu MHz : 800.000
cache size : 3072 KB
physical id : 0
siblings : 4
core id : 1
cpu cores : 2
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
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 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips : 3192.69
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i5-2467M CPU @ 1.60GHz
stepping : 7
microcode : 0x29
cpu MHz : 800.000
cache size : 3072 KB
physical id : 0
siblings : 4
core id : 1
cpu cores : 2
apicid : 3
initial apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
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 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips : 3192.69
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:

KVM installation

1
2
yum install kvm virt-manager libvirt virt-install qemu policycoreutils-python
yum -y install @virt* dejavu-lgc-* xorg-x11-xauth tigervnc libguestfs-tools policycoreutils-python bridge-utils

Networking

1
2
3
echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf
sysctl -p /etc/sysctl.d/99-ipforward.conf
ifconfig -a

Log: ifconfig -a

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@kvmhost ~]# ifconfig -a
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Lokale Schleife)
RX packets 132 bytes 11824 (11.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 132 bytes 11824 (11.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:9e:f3:99 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:9e:f3:99 txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.22 netmask 255.255.0.0 broadcast 192.168.255.255
inet6 2003:46:762:a900:76de:2bff:fe6a:fa2e prefixlen 64 scopeid 0x0<global>
inet6 fe80::76de:2bff:fe6a:fa2e prefixlen 64 scopeid 0x20<link>
ether 74:de:2b:6a:fa:2e txqueuelen 1000 (Ethernet)
RX packets 37309 bytes 46095805 (43.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20606 bytes 2591387 (2.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  • Wifi Devices can’t be bridged!
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    How did you come to this conclusion? Based on which reading?
    https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/
    Is there any utility or tool to use to scan wireless device in network and
    connect them as i want to stop to use Networkmanager to use laptop wireless
    interface as bridge for my guest vm.
    You cannot do what you want
    https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/ch-Configure_Network_Bridging.html
    "Note that a bridge cannot be established over Wi-Fi networks operating
    in Ad-Hoc or Infrastructure modes. This is due to the IEEE 802.11
    standard that specifies the use of 3-address frames in Wi-Fi for the
    efficient use of airtime."
    Thx
    Ben
    Alexander

File: /etc/sysconfig/network-scripts/ifcfg-enp0226u1u2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
DEVICE=enp0s26u1u2
HWADDR=F4:F9:51:F2:82:7F
TYPE=Ethernet
#BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s26u1u2
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
BRIDGE=virbr0

File: /etc/sysconfig/network-scripts/ifcfg-virbr0-enp0226u1u2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
DEVICE=virbr0
TYPE=BRIDGE
BOOTPROTO=static
#DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
#IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s26u1u2
ONBOOT=yes
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR="192.168.3.101"
NETMASK="255.255.0.0"
GATEWAY="192.168.3.1"
DNS1="192.168.3.1"

File: /etc/sysconfig/network-scripts/ifcfg-enp0226u1u2

1
2
3
4
5
6
DEVICE=enp0s26u1u2
HWADDR=F4:F9:51:F2:82:7F
TYPE=Ethernet
NAME=enp0s26u1u2
ONBOOT=yes
BRIDGE=virbr0

File: /etc/sysconfig/network-scripts/ifcfg-virbr0-enp0226u1u2

1
2
3
4
5
6
7
DEVICE=virbr0
TYPE=BRIDGE
BOOTPROTO=static
NAME=enp0s26u1u2
ONBOOT=yes
IPADDR="192.168.3.101"
NETMASK="255.255.0.0"

Finish and check the KVM installation

1
2
3
lsmod | grep kvm
ip a show virbr0
virsh -c qemu:///system list

Log: lsmod | grep kvm

1
2
3
[root@kvmhost /]# lsmod | grep kvm
kvm_intel 148081 0
kvm 461126 1 kvm_intel

Log: ip a show virbr0

1
2
3
4
5
6
7
8
9
[root@kvmhost /]# ip a show virbr0
4: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether f4:f9:51:f2:82:7f brd ff:ff:ff:ff:ff:ff
inet 192.168.3.101/16 brd 192.168.255.255 scope global virbr0
valid_lft forever preferred_lft forever
inet6 fdaa:fabb:cbd7:1:f6f9:51ff:fef2:827f/64 scope global dynamic
valid_lft 1814391sec preferred_lft 604791sec
inet6 fe80::f6f9:51ff:fef2:827f/64 scope link
valid_lft forever preferred_lft forever

Log: virsh -c qemu:///system list

1
2
3
[root@kvmhost /]# virsh -c qemu:///system list
Id Name Status
----------------------------------------------------

Using KVM with the CLI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
[root@kvmhost /]# virt-install --help
usage: virt-install --name NAME --ram RAM STORAGE INSTALL [options]
Neue virtuelle Maschine von festgelegten Installations-Medien erstellen.
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--connect URI Verbindung zum Hypervisor mit libvirt URI
Allgemeine Optionen:
-n NAME, --name NAME Name der Gastinstanz
--memory MEMORY Configure guest memory allocation. Ex:
--memory 1024 (in MiB)
--memory 512,maxmemory=1024
--vcpus VCPUS Number of vcpus to configure for your guest. Ex:
--vcpus 5
--vcpus 5,maxcpus=10,cpuset=1-4,6,8
--vcpus sockets=2,cores=4,threads=2,
--cpu CPU CPU model and features. Ex:
--cpu coreduo,+x2apic
--cpu host
--metadata METADATA Configure guest metadata. Ex:
--metadata name=foo,title="My pretty title",uuid=...
--metadata description="My nice long description"
--security SECURITY Erstellen Sie die Domänen-Sicherheit Treiber-
Konfiguration.
--numatune NUMATUNE Stimmen Sie die NUMA Richtlinie auf die Domänen
Verarbeitung ab.
--memtune MEMTUNE Tune memory policy for the domain process.
--blkiotune BLKIOTUNE
Tune blkio policy for the domain process.
--memorybacking MEMORYBACKING
Set memory backing policy for the domain process. Ex:
--memorybacking hugepages=on
--features FEATURES Set domain <features> XML. Ex:
--features acpi=off
--features apic=on,eoi=on
--clock CLOCK Set domain <clock> XML. Ex:
--clock offset=localtime,rtc_tickpolicy=catchup
--pm PM Configure VM power management features
--events EVENTS Configure VM lifecycle management policy
--resource RESOURCE Configure VM resource partitioning (cgroups)
Installations-Verfahren Optionen:
--cdrom CDROM CD-ROM-Installationsmedium
-l LOCATION, --location LOCATION
Installationsquelle (z.B. nfs:host:/pfad,
http://host/pfad, ftp://host/pfad)
--pxe Vom Netzwerk booten mittels PXE-Protokoll
--import Gast um vorhandenes Festplattenimage herum erstellen
--livecd CD-ROM-Medium wie Live-CD behandeln
-x EXTRA_ARGS, --extra-args EXTRA_ARGS
Zusätzliche Argumente, die an den Installations
Kernel, der von --location gestartet wird,
weitergegeben werden
--initrd-inject INITRD_INJECT
Fügen Sie die angegebene Datei zur Wurzel des initrd
von --location hinzu
--os-variant DISTRO_VARIANT
Die zu installierende Betriebssystemvariante für den
Gast, z.B. 'fedora18', 'rhel6', 'winxp', etc.
--boot BOOT Configure guest boot settings. Ex:
--boot hd,cdrom,menu=on
--boot init=/sbin/init (for containers)
--idmap IDMAP Enable user namespace for LXC container. Ex:
--idmap uid_start=0,uid_target=1000,uid_count=10
Speicherkonfiguration:
--disk DISK Specify storage with various options. Ex.
--disk size=10 (new 10GiB image in default location)
--disk path=/my/existing/disk,cache=none
--disk device=cdrom,bus=scsi
--disk=?
--nodisks Keine Festplatten für den Gast einrichten.
--filesystem FILESYSTEM
Host-Verzeichnis an Gast übergeben. Beispiel:
--filesystem /my/source/dir,/dir/in/guest
--filesystem template_name,/,type=template
Netzwerke Konfiguration:
-w NETWORK, --network NETWORK
Configure a guest network interface. Ex:
--network bridge=mybr0
--network network=my_libvirt_virtual_net
--network network=mynet,model=virtio,mac=00:11...
--network network=mynet,filterref=clean-traffic
--network help
--nonetworks Keine Netzwerkschnittstellen für den Gast erstellen.
Grafikkonfiguration:
--graphics GRAPHICS Konfigurieren Sie Gast-Anzeigeeigenschaften. Beispiel:
--graphics vnc
--graphics spice,port=5901,tlsport=5902
--graphics none
--graphics vnc,password=foobar,port=5910,keymap=ja
Geräteoptionen:
--controller CONTROLLER
Konfigurieren Sie ein Gast-Controllergerät. Beispiel:
--controller type=usb,model=ich9-ehci1
--serial SERIAL Konfigurieren Sie ein serielles Gerät für den Gast
--parallel PARALLEL Konfigurieren Sie ein paralleles Gerät für den Gast
--channel CHANNEL Konfigurieren Sie einen Gast-Kommunikationskanal
--console CONSOLE Konfigurieren Sie eine Textkonsolenverbindung zwischen
dem Gast und dem Host
--host-device HOST_DEVICE
Konfigurieren Sie physische Host-Geräte verknüpft
mit dem Gast
--sound [SOUND] Konfigurieren Sie Gast-Audiogerät-Emulation
--watchdog WATCHDOG Konfigurieren Sie ein Gast-Watchdog-Gerät
--video VIDEO Konfigurieren Sie Gast-Grafikhardware.
--smartcard SMARTCARD
Konfigurieren Sie ein Gast-Smartcard-Gerät. Beispiel:
--smartcard mode=passthrough
--redirdev REDIRDEV Konfigurieren Sie ein Gast-Umleitungsgerät. Beispiel:
--redirdev usb,type=tcp,server=192.168.1.1:4000
--memballoon MEMBALLOON
Konfigurieren Sie ein Gast-Memballoon-Gerät. Beispiel:
--memballoon model=virtio
--tpm TPM Configure a guest TPM device. Ex:
--tpm /dev/tpm
--rng RNG Configure a guest RNG device. Ex:
--rng /dev/random
--panic PANIC Configure a guest panic device. Ex:
--panic default
Virtualisierungsplattform-Optionen:
-v, --hvm Dieser Gast soll ein voll virtualisierter Gast sein
-p, --paravirt Dieser Gast soll ein paravirtualisierter Gast sein
--container Dieser Gast soll ein Container-Gast sein
--virt-type HV_TYPE Zu verwendender Hypervisor-Name (kvm, qemu, xen, ...)
--arch ARCH Die zu simulierende CPU-Architektur
--machine MACHINE Der zu emulierende Rechertyp
Sonstige Optionen:
--autostart Domäne soll automatisch nach dem Systemstart des
Hosts starten.
--wait WAIT Minutes to wait for install to complete.
--noautoconsole Nicht automatisch mit der Gastkonsole zu verbinden
versuchen
--noreboot Gast nach abgeschlossener Installation nicht starten.
--print-xml Print the generated domain XML rather than create the
guest.
--print-step XMLSTEP Drucken XML eines bestimmten Installations-Schrittes
(1, 2, 3, alle) anstatt den Gast zu definieren.
--dry-run Führen Sie den Installationsprozess durch, aber ohne
Geräte zu erstellen oder den Gast zu definieren.
-q, --quiet Unterdrücken Fehlerfreie Ausgabe
-d, --debug Debugging-Informationen anzeigen
Use '--option=?' or '--option help' to see available suboptions
Siehe die man-Seite für Beispiele und kompletter Options-Syntax.
[root@kvmhost /]#

SELinux Virtualbox Image Storage Directory Change:

1
2
3
mkdir /vm
semanage fcontext -a -t virt_image_t "/vm(/.*)?"
restorecon -R /vm

Überprüfen ob Libvirt Daemon korrekt gestartet werden konnte:

1
systemctl status libvirtd

Log: systemctl status libvirtd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@kvmhost vm]# systemctl status libvirtd
libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled)
Active: active (running) since So 2015-10-04 17:00:27 CEST; 8min ago
Docs: man:libvirtd(8)
http://libvirt.org
Main PID: 1603 (libvirtd)
CGroup: /system.slice/libvirtd.service
└─1603 /usr/sbin/libvirtd
Okt 04 17:00:27 kvmhost.hochguertel.biz systemd[1]: Starting Virtualization daemon...
Okt 04 17:00:27 kvmhost.hochguertel.biz systemd[1]: Started Virtualization daemon.
Okt 04 17:00:28 kvmhost.hochguertel.biz libvirtd[1603]: libvirt version: 1.2.8, package: 16.el7_1.4 (CentOS BuildSystem <http://bugs.cent...os.org)
Okt 04 17:00:28 kvmhost.hochguertel.biz libvirtd[1603]: Kann Bridge virbr0 nicht erstellen: Die Datei existiert bereits
Hint: Some lines were ellipsized, use -l to show in full.

Active: active (running) since So 2015-10-04 17:00:27 CEST; 8min ago

Example to add a windows-guest

List of Operation Systems:

1
osinfo-query os

Log: osinfo-query os

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@kvmhost vm]# osinfo-query os
Short ID | Name | Version | ID
----------------------+----------------------------------------------------+----------+-----------------------------------------
altlinux1.0 | Mandrake RE Spring 2001 | 1.0 | http://altlinux.org/altlinux/1.0
altlinux2.0 | ALT Linux 2.0 | 2.0 | http://altlinux.org/altlinux/2.0
altlinux2.2 | ALT Linux 2.2 | 2.2 | http://altlinux.org/altlinux/2.2
altlinux2.4 | ALT Linux 2.4 | 2.4 | http://altlinux.org/altlinux/2.4
altlinux3.0 | ALT Linux 3.0 | 3.0 | http://altlinux.org/altlinux/3.0
altlinux4.0 | ALT Linux 4.0 | 4.0 | http://altlinux.org/altlinux/4.0
altlinux4.1 | ALT Linux 4.1 | 4.1 | http://altlinux.org/altlinux/4.1
altlinux5 | ALT Linux 5.0.0 Ark | 5.0 | http://altlinux.org/altlinux/5
altlinux6 | ALT Linux 6.0.0 Centaurus | 6.0 | http://altlinux.org/altlinux/6
....

1
2
3
4
5
6
7
8
9
10
11
12
13
virt-install --connect qemu:///system \
-n vmwin7 \
-r 512 \
--vcpus=1 \
--disk path=/vm/vmwin7.img,size=10 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--os-type windows \
--os-variant win7 \
--accelerate \
--network=bridge:virbr0 \
--hvm \
--cdrom /vm/03_Installation-Medium/X17-58997.iso

–connect qemu:///system : connect to KVM on the local system, we could also connect to another KVM-host and define our new VM there
-n vmwin7 : name of the new VM: vmwin7
-r 512 : amount of memory for the VM: 1GB
–vcpus=1 : amount of virtual CPU’s for the VM: 2
–disk path=/var/lib/libvirt/images/vmwin7.img,size=10 : where to store the virtual disk image of the VM and the size: 10GB
–graphics vnc,listen=0.0.0.0 : how to display the VM’s console: via VNC accessible from outside
–noautoconsole : do not automatically connect to the console
–os-type windows –os-variant win7 : type of guest OS (from the list given above)
–accelerate : use KVM HW-acceleration
–network=bridge:virbr0 : network bridge to use
–hvm : full virtualisation
–cdrom /vm/03_Installation-Medium/X17-58997.iso : location of the installation ISO

Log: ``

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@kvmhost vm]# virt-install --connect qemu:///system \
> -n vmwin7 \
> -r 512 \
> --vcpus=1 \
> --disk path=/vm/vmwin7.img,size=10 \
> --graphics vnc,listen=0.0.0.0 \
> --noautoconsole \
> --os-type windows \
> --os-variant win7 \
> --accelerate \
> --network=bridge:virbr0 \
> --hvm \
> --cdrom /vm/03_Installation-Medium/X17-58997.iso
Installation wird gestartet...
Zuweisen von 'vmwin7.img' | 10 GB 00:00:00
Domain wird erstellt... | 0 B 00:00:00
Domain-Installation ist noch in Arbeit. Warten für die Installation fertigzustellen.

Exmaple of adding KVM Guests

1
2
3
4
5
6
7
8
9
10
11
12
13
virt-install --connect qemu:///system \
-n vm001 \
-r 512 \
--vcpus=1 \
--disk path=/vm/vm001.img,size=10 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--os-type linux \
--os-variant centos7.0 \
--accelerate \
--network=bridge:virbr0 \
--hvm \
--cdrom /vm/03_Installation-Medium/CentOS-7-x86_64-DVD-1503-01.iso
1
2
3
4
5
6
7
8
9
10
11
12
13
virt-install --connect qemu:///system \
-n vm002 \
-r 512 \
--vcpus=1 \
--disk path=/vm/vm002.img,size=10 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--os-type linux \
--os-variant centos7.0 \
--accelerate \
--network=bridge:virbr0 \
--hvm \
--cdrom /vm/03_Installation-Medium/CentOS-7-x86_64-DVD-1503-01.iso
1
2
3
4
5
6
7
8
9
10
11
12
13
virt-install --connect qemu:///system \
-n vm003 \
-r 512 \
--vcpus=1 \
--disk path=/vm/vm003.img,size=10 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--os-type linux \
--os-variant centos7.0 \
--accelerate \
--network=bridge:virbr0 \
--hvm \
--cdrom /vm/03_Installation-Medium/CentOS-7-x86_64-DVD-1503-01.iso
1
2
3
4
5
6
7
8
9
10
11
12
13
virt-install --connect qemu:///system \
-n vm004 \
-r 512 \
--vcpus=1 \
--disk path=/vm/vm004.img,size=10 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--os-type linux \
--os-variant centos7.0 \
--accelerate \
--network=bridge:virbr0 \
--hvm \
--cdrom /vm/03_Installation-Medium/CentOS-7-x86_64-DVD-1503-01.iso

Open VNC Ports in Firewall

To add a source (here 192.168.2.0/24) to a zone (here trusted) permanently, type:

1
2
firewall-cmd --permanent --zone=trusted --add-source=192.168.2.0/24
firewall-cmd --reload

Connect via VNC to Virtual Machine:

Getting the Screen-Number:

1
2
virsh vncdisplay vmwin7
netstat -tln|grep :59

Log: virsh vncdisplay vmwin7

1
2
3
4
[root@kvmhost ~]# virsh vncdisplay vmwin7
:0
[root@kvmhost ~]#

Log: netstat -tln|grep :59

1
2
3
[root@kvmhost ~]# netstat -tln|grep :59
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN
[root@kvmhost ~]#

Figure: Connect to the screen of KVM VM

192.168.2.22:5900
kvmhost:5900
spice://kvmhost:5900

1
2
3
4
5
6
7
8
9
10
11
12
13
virt-install --connect qemu:///system \
-n vmwin7 \
-r 512 \
--vcpus=1 \
--disk path=/vm/vmwin7.img,size=10 \
--graphics spice,listen=0.0.0.0 \
--noautoconsole \
--os-type windows \
--os-variant win7 \
--accelerate \
--network=bridge:virbr0 \
--hvm \
--cdrom /vm/03_Installation-Medium/X17-58997.iso

Remove Virtual Machine from Virtual Manager and Harddisk:

1
2
3
virsh destroy vmwin7
virsh undefine vmwin7
rm -rf /vm/vmwin7.img

0%