Virtualization with (KVM

Kernel-based Virtual Machine

Thomas Korber
Consultant and Trainer B1 Systems GmbH

Bruce Rogers
Consulting Software Engineer Novell, Inc.

First release in early 2007 Originally developed by Qumranet Included in Linux kernel release 2.6.20 GPL v2


© Novell, Inc. All rights reserved.

KVM – Full Virtualization

Relies on AMD's AMD-V or Intel's VT-x virtualization technologies Implemented as kernel modules
– –

kvm.ko: provides virtualization infrastructure kvm_amd.ko and kvm_intel.ko: hardware platform specific modules for the hardware virtualization technologies

=> Vanilla Linux kernel becomes virtual machine monitor, which can use any kernel infrastructure without modifications => KVM virtual machines become regular user-space processes


© Novell, Inc. All rights reserved.

KVM Architecture

Adds “Guest Mode” to Traditional Kernel and User Modes
Guest Userspace Processes Userspace Process Userspace Process


Guest Kernel (e.g. Linux Kernel) QEMU-KVM

Linux Kernel KVM (Module) Hardware Support, vitualization technologies for x86 (AMD-V/ Intel-VT)

© Novell, Inc. All rights reserved.

Source: “Virtualization with KVM” training, B1 Systems GmbH

Supported Hardware Any i386/x86_64 CPUs that have AMD-V or VT-x: => Almost any server CPU sold in the last couple years 5 © Novell. . All rights reserved. Inc.

Supported Hardware (Continued) Utilizes the following additional hardware virtualization features: VPID / ASID VT-d/IOMMU HAP (EPT/NTP) VMX Unrestricted Guest SR-IOV 6 © Novell. . Inc. All rights reserved.

0 support for KVM VMM Modified qemu-kvm is user space tool for KVM Communication with KVM via /dev/kvm • • • • 7 © Novell.QEMU • Community project founded in 2003 Emulates PC hardware and CPUs Since v 0. Inc.10. All rights reserved. .

net. clock. Inc. balloon Snapshots Delta images of virtual machines PCI passthrough Kernel samepage merging 8 © Novell.KVM Features Supports 32 and 64 bit guests (on 64 bit hosts) Supports hardware virtualization features Paravirtualized drivers (virtio): blk. All rights reserved. .

. Inc. All rights reserved. memory and disk over-commit Live migration CPU and device hotplug Non-kvm (emulation only) mode PXE boot 9 © Novell.KVM Features (continued) Sound support CPU.

. All rights reserved.KVM . Inc. OpenSolaris Linux BSD Windows 10 BSD Unix © Novell.Supported Guest Systems Solaris.

both 32 and 64 bit • SUSE Linux Enterprise Server 11 SP1 (level 3 supported) SUSE Linux Enterprise Server 10 SP3 (level 3 supported) SUSE Linux Enterprise Server 9 SP4 (level 3 supported) SUSE Linux Enterprise Desktop 11 SP1 (technical preview) Red Hat Enterprise Linux 4 (best effort) Red Hat Enterprise Linux 5 (best effort) • • • • • 11 © Novell. All rights reserved.KVM Guests Supported by Novell (I) ® Linux . Inc. .

All rights reserved.KVM Guests Supported by Novell (II) ® Microsoft Windows – both 32 and 64 bit (“best effort” support only) Microsoft Windows 2003 SP2+ plus PV drivers Microsoft Windows 2008+ plus PV drivers Microsoft Windows XP SP3+ plus PV drivers Microsoft Windows Vista SP1+ plus PV drivers • • • • 12 © Novell. Inc. .

20 para-virtual (virtio-blk) Maximum number of guests: total vCPUs <= 8 times total CPU cores in Host 13 © Novell. All rights reserved. . Inc.Supported Limits Host RAM and CPU limits are the same with or without kvm modules loaded Guest RAM size: 512 GB Virtual CPUs per guest: 16 NICs per guest: 8 Block devices per guest: 4 emulated.

All rights reserved. . hypervisor Kernel as I/O dispatcher and management domain Maintained and supported as a patch to mainline kernel by Novell ® Kernel module Uses kernel as VMM In upstream kernel Only supports fully virtualized VMs • • • • • Supports fully virtualized and paravirtualized Vms • 14 © Novell. Inc.Xen and KVM: A Comparison Xen • KVM • VMM implementation of its own.

All rights reserved.Virtualization in SUSE Linux Enterprise Server 11 SP1 ® • SUSE Linux Enterprise Server 11 SP1 will ship with both virtualization solutions (KVM and Xen) Xen is the primary solution. . being the proven enterprise-ready open source hypervisor Long term. Inc. Novell expects KVM eventually to become equivalent to Xen ® • • • Toolset shipped in SUSE Linux Enterprise Server 11 SP1 supports both Xen and KVM 15 © Novell.

Setting up KVM on SUSE Linux Enterprise 11 SP1 ® .

. DRBD primary/primary setup 17 © Novell.Demo Setup • Storage server and installation source: – SUSE Linux Enterprise Server 11 GA x86_64 ® – – Logical volume as iSCSI target for OCFS2 file system Installation sources (SUSE Linux Enterprise Server 11 SP1 Beta5 and SUSE Linux Enterprise High Availability Extension Server 11 SP1 Beta5) exported via HTTP • 2 KVM hosts – – SUSE Linux Enterprise Server 11 SP1 Beta5 x86_64 Logical volume for DRBD. All rights reserved. Inc.

.Demo Setup – Shared Storage Node 1 Node 2 Node 3 FC or iSCSI OCFS2 18 © Novell. All rights reserved. Inc.

Inc. .Demo Setup – Replicated Storage Node 1 Node 2 TCP/IP DRBD Local Disk 19 Local Disk © Novell. All rights reserved.

libvirt and virt-manager as GUI zypper in kvm virt-manager (optional) packages for shared storage: – – • server: iscsitarget KVM hosts: open-iscsi. drbd-kmp-default 20 © Novell.Packages • KVM. ocfs2-tools-o2cb or – KVM hosts: drbd. ocfs2-tools. . Inc. All rights reserved.

b1systems.conf | grep -v "#" Target iqn.iSCSI Setup • Storage Server: storage:~ # cat /etc/ietd.Type=fileio • KVM Hosts: node1:~ # iscsiadm -m discovery -tst -p storage 192. All rights Lun 0 Path=/dev/vg_system/lv_share.2009-11.b1systems.35:3260.1 iqn.2009-11. node1:~ # iscsiadm -m node -T iqn.168.168.2. .2009-11.35 -l 21 © -p 192.b1-systems.

syncer { rate 40M. Inc. } net { allow-two-primaries. } startup { become-primary-on both. ./etc/drbd. } 22 © Novell. All rights reserved.conf (I) Create /etc/drbd.conf global { usage-count no.conf and have the identical file on both nodes node1:~ # cat /etc/drbd.DRBD Setup . } resource r0 { protocol C.

meta-disk internal./etc/drbd.31:7791. meta-disk internal.32:7791. disk /dev/mapper/storage-lv_drbd. . } } 23 © Novell. } on node2 { device /dev/drbd0.168. disk /dev/mapper/storage-lv_drbd.DRBD Setup .2. Inc.2.168.conf (II) on node1 { device /dev/drbd0. address 192. All rights reserved. address 192.

DRBD Setup On both nodes: node1:~ # modprobe drbd && rcdrbd start node1:~ # drbdadm create r0 On first node: node1:~ # drbdadm -.--overwrite-data-of-peer primary r0 On second node: node1:~ # drbdadm primary r0 On either node: node1:~ # cat /proc/drbd 24 © Novell. Inc. . All rights reserved.

conf node: name = node1 cluster = ocfs2 number = 0 ip_address = 192. Inc.2.31 ip_port = 7777 node: name = node2 cluster = ocfs2 number = 1 ip_address = 192. All rights reserved.OCFS2 Setup (I) node1:~ # vi /etc/ocfs2/cluster.32 ip_port = 7777 cluster: name = ocfs2 node_count = 2 25 © Novell.168.2.168. .

Load O2CB driver on boot (y/n) [y]: Cluster stack backing O2CB [o2cb]: Cluster to start on boot (Enter "none" to clear) [ocfs2]: Specify heartbeat dead threshold (>=7) [31]: Specify network idle timeout in ms (>=5000) [30000]: Specify network keepalive delay in ms (>=1000) [2000]: Specify network reconnect delay in ms (>=2000) [2000]: Writing O2CB configuration: OK Loading filesystem "configfs": OK Mounting configfs filesystem at /sys/kernel/config: OK Loading stack plugin "o2cb": OK Loading filesystem "ocfs2_dlmfs": OK Mounting ocfs2_dlmfs filesystem at /dlm: OK Setting cluster stack "o2cb": OK Starting O2CB cluster ocfs2: OK 26 © Novell. Inc.OCFS2 Setup (II) node1:~ # rco2cb configure Configuring the O2CB driver. All rights reserved. . This will configure the on-boot properties of the O2CB driver.\:lv_share-lun-0 /var/lib/kvm/images/ 27 © Novell.iSCSI node1:~ # mkfs. Inc.168.35\:3260-iscsi-iqn.35\:3260-iscsiiqn. .2.2009-11.2009-11.ocfs2 /dev/disk/bypath/ip-192.OCFS2 Setup (III) .de\:lv_share-lun-0 On both nodes: node1:~ # mount /dev/disk/by-path/ip192. All rights reserved.168.

All rights reserved. Inc.DRBD node1:~ # mkfs.ocfs2 /dev/drbd0 On both nodes: node1:~ # mount /dev/drbd0 \ /var/lib/kvm/images 28 © Novell.OCFS2 Setup (IV) . .

. Inc. All rights reserved.KVM VM Installation – GUI 29 © Novell.

All rights reserved.iso \ -boot d -m 512 [installation of a “physical computer”] • • qemu-kvm -hda \ /var/lib/kvm/images/sles11_raw_disk1. .img -m 512 30 © Novell.img \ -cdrom /srv/isos/SLES-11-DVD-x86_64-GM-DVD1. Inc.KVM VM Installation: CLI • qemu-img create \ /var/lib/kvm/images/sles11_raw_disk1.img 5G qemu-kvm -hda \ /var/lib/kvm/images/sles11_raw_disk1.

xml --ossettings=/foo/bar/autoinst.KVM – Installation With vm-install Unattended installation: vm-install --background --vmsettings=/foo/bar/vm-template.xml … 31 © Novell. Inc. All rights reserved. .

KVM – Networking • Usermode network stack – Default setup No root permissions needed Integrated DHCP. SMB and DNS – – • TAP device Bridged mode (comparable to default Xen network setup) • 32 © Novell. Inc. All rights reserved. . DNS.

Inc. All rights reserved.] <bridge name="br0" /> [... .xml cat /etc/libvirt/qemu/networks/default..KVM – Networking (II) Example: bridged setup node1:~ # cat /etc/libvirt/qemu/sles11.xml <network> <name>default</name> [..] </network> 33 © Novell.

Inc. . All rights reserved.KVM – Selected Image Formats Name Compression Snapshot Encryption Deltas raw qcow2 X X X X X vmdk 34 © Novell.

Compressing and Encrypting Images • qemu-img convert -O qcow2 \ /var/lib/kvm/images/sles11_raw_disk1.img • qemu-img convert -c -O qcow2 \ /var/lib/kvm/images/sles11_qcow2_disk1.img \ /var/lib/kvm/images/sles11_qcow2_compr_disk1.img • qemu-img convert -e -O qcow2 \ /var/lib/kvm/images/sles11_qcow2_compr_disk1.img \ /var/lib/kvm/images/sles11_qcow2_compr_encr_disk1.KVM – Converting. . Inc.img 35 © Novell.img \ /var/lib/kvm/images/sles11_qcow2_disk1. All rights reserved.

Inc. . All rights reserved.Virt-Manager – Hardware Configuration 36 © Novell.

KVM – Snapshots • qemu-img snapshot -l image. All rights reserved.img • • • 37 © Novell.img qemu-img snapshot -a snapshot image. Inc. .img qemu-img snapshot -d snapshot image.img qemu-img snapshot -c snapshot image.

34:4444 • Via libvirt and virt-manger instances 38 © Novell.168. .3. Inc. All rights reserved.KVM – Live Migration • CLI: qemu-kvm -incoming tcp:0:4444 (qemu) migrate -d tcp:192.

Demo .


release. reserves the right to revise this document and to make changes to its content. Novell. Inc. condensed. abridged. Novell. and timing of features or functionality described for Novell products remains at the sole discretion of Novell. The development. modified. All third-party trademarks are the property of their respective owners. proprietary. distributed. revised. or market a product. expanded. or functionality. translated. Inc. and trade secret information of Novell. Inc. and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. All Novell marks referenced in this presentation are trademarks or registered trademarks of Novell. Inc. Access to this work is restricted to Novell employees who have a need to know to perform tasks within the scope of their assignments. Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability.Unpublished Work of Novell. makes no representations or warranties with respect to the contents of this document. Inc. at any time. deliver. General Disclaimer This document is not to be construed as a promise by any participating company to develop. Further. in the United States and other countries. This work is an unpublished work and contains confidential. It is not a commitment to deliver any material. collected. performed. or adapted without the prior written consent of Novell. No part of this work may be practiced. code. and should not be relied upon in making purchasing decisions. . copied. without obligation to notify any person or entity of such revisions or changes. Inc. All Rights Reserved.

Sign up to vote on this title
UsefulNot useful