1. Install the KVM kernel and LIBVIRTD related components
Yum-y Install KVM python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer
2. AddCarrier KVM Operating module
[Root@localhost ~]# modprobe KVM
[Root@localhost ~]# modprobe-ls |grep KVM
Kernel/arch/x86/kvm/kvm.ko
Kernel/arch/x86/kvm/kvm-intel.ko
Kernel/arch/x86/kvm/kvm-amd.ko
3. Create a physical bridge
Virsh Iface-bridge eth0 br0
View Network
[Root@localhost ~]# Ifconfig
Br0 Link encap:ethernet hwaddr 00:0c:29:c1:62:56
inet addr:192.168.150.136 bcast:192.168.150.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FEC1:6256/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:4925 errors:0 dropped:0 overruns:0 frame:0
TX packets:3937 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:532933 (520.4 KiB) TX bytes:13484199 (12.8 MiB)
Eth0 Link encap:ethernet hwaddr 00:0c:29:c1:62:56
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:377686 errors:0 dropped:0 overruns:0 frame:0
TX packets:110643 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:507725096 (484.2 MiB) TX bytes:66233641 (63.1 MiB)
4. Create a virtual disk:
Qemu-img create-f qcow2/kvm/test003.img 5G
5. Create a virtual machine:
Qcow2 format
[Root@localhost ~]# virt-install--name test003--ram 512 \
--vcpus=1--disk path=/kvm/test003.img,size=5,format=qcow2,bus=virtio \
--accelerate--cdrom/tmp/centos-6.6-x86_64-minimal.iso\
--vnc--vncport=5910--vnclisten=0.0.0.0\
--network Bridge=br0,model=virtio--noautoconsole
RAW format:
[Root@localhost ~]# virt-install--name test003--ram 512 \
--vcpus=1--disk path=/kvm/test003.img,size=5,bus=virtio \
--accelerate--cdrom/tmp/centos-6.6-x86_64-minimal.iso\
--vnc--vncport=5910--vnclisten=0.0.0.0\
--network Bridge=br0,model=virtio--noautoconsole
6.VNC Connection
KVM Virtual Machine Experience
QEMU is a powerful virtual machine software that can completely simulate all the hardware needed for a complete computer in the form of software, even hardware that simulates different architectures, and can install a complete operating system on top of these virtual hardware. QEMU's run mode is as follows:
Obviously, this kind of software simulation hardware in the form of powerful, but the performance is difficult to meet the needs of users. The performance of the simulated hardware is inherently compromised compared to the performance of the physical hardware. To improve the performance of virtual machine software, developers are recount. The most common approach is to open a hole in the main operating system through the kernel module, which maps the operation in the virtual machine directly to the physical hardware, thereby improving the performance of the operating system running in the virtual machine. The following figure:
Where the KVM is the typical representative of this acceleration mode. In the community, KVM and Xen are often compared to each other, but they are actually completely different. As you can see from the diagram above, using kernel modules to accelerate this pattern, the main operating system is still dominant, the kernel module only opens a hole in the main operating system to connect the virtual machine and physical hardware to the virtual machine, but the client operating system in the virtual machine is still greatly restricted. This mode is more suitable for desktop users, the main operating system is still their major battlefield, whether it is the office or play games, through the main operating system, the client operating system is only on demand. As for Xen, the full use of different ideas, more suitable for enterprise-class users, desktop users do not easily touch, the specific content of the next I speak.
In fact, VirtualBox is also taking this model of kernel module acceleration. I say this because it requires dkms to be installed when VirtualBox is installed. The following figure:
People familiar with Linux know that dkms is to facilitate the user to manage the kernel module and the existence of people unfamiliar with the dkms Google can also know about a. On the specific use of VirtualBox content, I will say next. This article mainly talks about KVM.
KVM and QEMU are complementary, and QEMU can use the KVM kernel module to accelerate, and KVM needs to run virtual machines with QEMU. As you can see from the image above, if you want to use Ubuntu's package management software to install KVM, the installation is actually QEMU-KVM. And QEMU-KVM is not a very complicated package, it contains only a few files, the following figure:
Look at its documentation with the Man command and find that the QEMU-KVM package not only contains very few files, but also that its executable KVM is just a simple package for the qemu-system-x86_64 command, as shown in the following figure:
So the question is, which package does the KVM kernel module provide? In fact, since Linux 2.6, the KVM has been added to the kernel. If you do not want to find out which package the KVM kernel module Kvm.ko is provided by, you can examine it with the following command:
As you can see, the use of KVM is very simple. Next, I use KVM to run the WinXP operating system that was installed in the previous article to experience the efficiency of QEMU after KVM acceleration. Use the following command to run QEMU using KVM acceleration:
It can be seen that the use of KVM acceleration, the virtual machine in the WinXP operating speed increased a lot, the boot only took 34 seconds. I will adjust the resolution to 1366*768, the graphical interface is running smoothly, whether it is open IE browser or office Office software is no problem, there is no CPU usage soared to 100%. If you use Ps-ef | The grep qemu command looks at the QEMU-SYSTEM-X86_64 program that the KVM command is running, but adds the-ENABLE-KVM parameter, as shown in the following figure:
In addition, for desktop users, it is also important to have a user-friendly graphical interface. Although Qemu and KVM themselves have no graphical interface with Virtual Machine Manager, we can use 3rd party software, such as Virt-manager. You only need to use the sudo apt-get install Virt-manager to install the software. The software relies on Libvirt and is automatically installed during installation. The effect of running Virt-manager as shown below, note that you must run with sudo because the software requires Superuser privileges:
The software can automatically identify whether the virtual machine environment in the system is QEMU+KVM or Xen. Create a new virtual machine and choose to import an existing hard drive image because a WinXP system was previously installed. Click Next, the following interface appears:
There's nothing to say in this step, then. Next, the following figure:
You can set network options here. If you check "Custom configuration before Installation", you can further customize the hardware, as shown in the following figure:
In the above illustration, we can see the type of all virtual video cards supported by the virtual machine, where I certainly choose VMVGA, because I used to use VMware frequently to know that these operating systems are running without problems with VMware's virtual graphics settings. Of course, other options can be tried, but in a virtual operating system you need to install the appropriate driver.
Finally, the effect of the virtual machine running is as follows:
As you can see, the program provides a very rich menu of features that are very powerful and can even send combination keys to the operating system in the virtual machine.
It can be said that if there is no VirtualBox, the combination of QEMU+KVM should be the first choice for desktop users.