centos 6.6 how to install the KVM virtual machine
- 2020-05-17 07:04:36
- OfStack
KVM refers to the virtual machine based on Linux kernel (Kernel-base Virtual Machine). The addition of Linux kernel is an important milestone in the development of Linux. It is also the first virtualization technology integrated into the main Linux kernel. In the KVM model, each virtual machine is a standard process managed by the Linux scheduler. You can launch the client operating system in user space. A normal Linux process has two modes of operation: kernel and user.
1 KVM virtual machine management tool
To be precise, KVM is just one module of the Linux kernel. Managing and creating a full KVM virtual machine requires more tools.
QEMU-KVM: in the Linux system, we can first load the KVM module with the modprobe command. If we install the KVM software package with RPM, the system will automatically load the module at startup. QEMU is a powerful virtual software, which can virtual different architectures.
Virt-manager: while the QEMU-KVM tool can create and manage KVM virtual machines, RedHat has developed more ancillary tools for KVM, such as libvirt libguestfs, etc., because the QEMU tool is inefficient and not easy to use.
1. First check whether the system supports kvm, there are two prerequisites
a, system is x86, by command
uname -a
b, CPU support virtualization technology
egrep 'vmx|svm' /proc/cpuinfo
If you see any output, you can prove that cpu supports virtualization. At the same time, special attention should be paid to check whether VT is enabled in BIOS. If it is not enabled, the virtual machine will be 10 minutes slow.
2. Install kvm using yum
The installation kvm The kernel
yum install -y qemu-kvm.x86_64 qemu-kvm-tools.x86_64
The installation virt Management tool
yum install libvirt.x86_64 libvirt-cim.x86_64 libvirt-client.x86_64 libvirt-java.noarch libvirt-python.x86_64
Load the kvm kernel
modprobe kvm
modprobe kvm-intel
See if the kernel is turned on
modprobe -ls | grep kvm
3. Configure network bridge,
Go to the directory /etc/sysconfig/ network-scripts and make a copy of the original ifcfg-eth0 as ifcfg-br0
cp ifcfg-eth0 ifcfg-br0
Modify ifcfg-br0, as follows:
DEVICE="br0"
BOOTPROTO=static
ONBOOT="yes"
TYPE="Bridge"
IPADDR=192.168.31.60
GATEWAY=192.168.31.1
NETMASK=255.255.255.0
DEFROUTE=yes
IPADDR, GATEWAY and NETMASK shall be modified according to their actual conditions.
Modify ifcfg-eth0, as follows:
DEVICE="eth0"
BOOTPROTO=none
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
BRIDGE="br0"
HWADDR=F8:DB:88:FF:99:E3
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME="System eth0"
Just restart the web service.
/etc/init.d/network restart
If there is a problem, close NetworkManager and try again.
chkconfig NetworkManager off
service NetworkManager stop
4. Install the guest system using the virt-install tool.
a, create hard disk image file
Create using the qemu-img command
qemu-img create -f raw /var/lib/libvirt/images/test.img 8G
Or create it using the dd command
dd bs=1M count=8096 if=/dev/zero of=/var/lib/libvirt/images/test.img
qemu-img is created in a sparse file format. The advantage is that it is super fast. As it is a sparse file, the performance may be slightly worse than the second one
qemu-img info /var/lib/libvirt/images/test.img
The output is: note that disk size is 0
image: test.img
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 0
Search for more information about sparse files.
b, install the system through the iso file
virt-install --name=test --ram 1024 --vcpus=2 --disk path=/var/lib/libvirt/images/test.img,size=3 --accelerate --cdrom /home/CentOS-6.6-x86_64-minimal.iso --graphics vnc,listen=0.0.0.0 --network bridge=br0 --force --autostart --connect qemu:///system
Use vnc client to connect, IP USES ip of host, if it is the first virtual machine, the port is 5900, if the connection fails, confirm the state of host iptables, it is better to close iptables first. Connect after be like installation system 1 kind 1 step by step come installation can.