Kvm Basic Principle 2
The idea of KVM is to add a virtual machine management module on the basis of Linux, and reuse the completed process scheduling, memory management, IO management, and other parts in the Linux kernel, therefore, KVM is not a complete simulator, but a kernel plug-in that provides virtualization functions. The specific simulator work is completed by QEMU.
In the Xen architecture, the Xen Hypervisor runs on the hardware, virtualizes system resources, and allocates virtualized resources to upper-layer virtual machines (VMS ), then run the corresponding client operating system through the VM. in KVM, a virtual machine is a traditional Linux thread with its own PID Number and can be directly killed by the kill System Call (in this case, the Virtual Machine behavior is "sudden power failure "). in a Linux system, there are as many VMS as there are processes. example: 1
107 2349 1 4 Mar01? 1-10:21:43/usr/bin/kvm-name instance-00000074-S-M pc-1.2-cpu Penryn, + dca, + pdcm, + xtpr, + tm2, + vmx, + ds_cpl, + monitor, + dtes64, + pbe, + tm, + ht, + ss, + acpi, + ds, + vme-enable-kvm-m 2048-smp 2, sockets = 2, cores = 1, threads = 1-uuid f8450270-9d96-4dba-b1c2-8ebcef1ff012-no-user-config-nodefaults-chardev socket, id = charmonitor, path =/var/lib/libvirt/qemu/instance-00000074.monitor, server, nowait-mon chardev = charmonitor, id = monitor, mode = control-rtc base = utc, driftfix = slew-no-kvm-pit-reinjection-no-shutdown-device piix3-usb-uhci, id = usb, bus = pci.0, addr = 0x1.0x2-drive file =/var/lib/nova/instances/instance-00000074/disk, if = none, id = drive-virtio-disk0, format = qcow2, cache = none-device virtio-blk-pci, scsi = off, bus = pci.0, addr = 0x4, drive = drive-virtio-disk0, id = virtio-disk0, bootindex = 1-netdev tap, fd = 20, id = hostnet0, vhost = on, vhostfd = 22-device virtio-net-pci, netdev = hostnet0, id = net0, mac = fa: 16: 3e: 7b: 8b: b6, bus = pci.0, addr = 0x3-chardev file, id = charserial0, path =/var/lib/nova/instances/instance-00000074/console. log-device isa-serial, chardev = charserial0, id = serial0-chardev pty, id = charserial1-device isa-serial, chardev = charserial1, id = serial1-device usb-tablet, id = input0-vnc 10.1.1.190: 1-k en-us-vga cirrus-device virtio-balloon-pci, id = balloon0, bus = pci.0, addr = 0x5
2
Root 2350 2 0 Mar01? 00:00:00 vhost-2349
3
Root 2354 2 0 Mar01? 00:00:00 [kvm-pit/2349] the VM process information above is carried out through qemu-kvm. The related control switch is used as the name line parameter input, such as the disk corresponding to the virtual image, virtual Nic, VNC settings, video card settings, and I/O settings. KVM APIs are accessed through/dev/kvm devices. /dev/kvm is a dedicated device. 1
Root @ ubuntu :~ # Ls-l/dev/kvm
2
Crw-rw ---- 1 root kvm 10,232 Mar 14/dev/kvm is only a module of the Linux kernel. More auxiliary tools are required to manage and create a complete kvm vm.
1. qemu-Kvm: only the KVM module is far from enough, because users cannot directly control the kernel module to do things, and there must be a user space tool. With regards to user space tools, KVM developers have chosen the ready-made open-source virtualization software QEMU. QEMU is a powerful virtualization software that can Virtualize different CPU architectures.
The KVM module running in the kernel provides an operation interface through the/dev/kvm character device file. by providing the libkvm operating library, KVM converts the ioctl APIs at the/dev/kvm layer into function API calls in the general sense and provides them to the corresponding adaptation layer of QEMU.
For example, you can Virtualize a Power CPU on an x86 CPU and use it to compile programs that can run on Power. KVM uses the x86-based QEMU and is slightly transformed to form a user space tool QEMU-KVM that can control the KVM kernel module. therefore, Linux releases are divided into kernel KVM kernel modules and QEMU-KVM tools. this is the relationship between KVM and QEMU.
2. Libvirt, virsh, virt-manager: Although QEMU-KVM tools can create and manage KVM virtual machines, RedHat has developed more auxiliary tools for KVM, such as libvirt and libguestfs. The reason is that the QEMU tool is not efficient and is not easy to use. libvirt is a set of APIs that provide multi-language interfaces. It provides a set of convenient and reliable programming interfaces for various virtualization tools. It not only supports KVM, but also supports other virtual machines such as Xen. to use libvirt, you only need to connect to the KVM or Xen host through the functions provided by libvirt, and then you can use the same command to control different virtual machines. libvirt not only provides APIs, but also comes with a set of text-based commands for managing virtual machines-virsh. You can use the virsh command to use all libvirt functions. But the end user is more eager for the graphical user interface, which is virt-manager. it is a virtual machine management GUI written in python. You can use it to operate different virtual machines. virt-manager is implemented using libvirt APIs.