Install KVM and rhel7 in KVM

Install KVM and rhel7 in KVM

KVM brief introduction
KVM, short for kernel based virtual machine, is an open source system virtualization module. KVM is an open source software based on kernel virtualization technology, which is actually a virtualization module embedded in the system. Virtualization technology is used by optimizing the kernel. This kernel module turns linux into a hypervisor, and the virtual machine is managed using linux's own scheduler.
The kernel module of KVM is kvm Ko, which is only used to manage virtual CPU and memory. IO virtualization is implemented by the linux kernel and qemu.
Libvirt is an administrative tool for KVM. Libvirt includes the background daemon program libvirtd, API library and command line tool virsh. Libvirtd is a service program running in the background to receive and process API requests; API libraries enable others to develop advanced tools based on libvirt, such as virt manager, a graphical KVM management tool; Virsh is a frequently used KVM command line tool.
Next, I will demonstrate how to install KVM on the redhat7 host.
Before installing kvm, you need to check whether the host supports virtualization?
The host must have three conditions to support Virtualization:
1. CPU must be 64 bit
2. CPU has virtualization function
3. To enable virtualization in BIOS
Since kvm is to be installed on the redhat host, you can check whether virtualization is supported on the redhat through the command to view CPU information.

From the flags field, you can see two CPU flags. lm indicates that the CPU is 64 bit, and vmx indicates that the CPU supports virtualization.
Of course, you can also use the command to view directly

KVM is a kernel based virtual machine, so you must also load the KVM module to view the redhat system.

Install KVM
KVM software is in the redhat installation image, so the installation image needs to be used as the software source. The image file of redhat is used as the software source of the virtual machine in redhat. Here, I create the software source by setting up an ftp server.
1. Install the vsftpd package first

[root@localhost ~]# lsblk
sda      8:0    0   40G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
└─sda3   8:3    0   35G  0 part /
sr0     11:0    1  3.5G  0 rom  
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        35G  3.0G   33G   9% /
devtmpfs        3.8G     0  3.8G   0% /dev
tmpfs           3.9G   84K  3.9G   1% /dev/shm
tmpfs           3.9G  9.0M  3.9G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1      1014M  169M  846M  17% /boot
tmpfs           781M   16K  781M   1% /run/user/42
tmpfs           781M     0  781M   0% /run/user/0
/dev/sr0        3.6G  3.6G     0 100% /mnt
[root@localhost ~]# rpm -ivh /mnt/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm 
warning: /mnt/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.2-21.el7              ################################# [100%]

After installing the FTP service, create the software warehouse directory /var/ftp/dvd, and permanently mount the image file in this directory.

[root@localhost ~]# mkdir /var/ftp/dvd
[root@localhost ~]# vi /etc/fstab 
[root@localhost ~]# cat /etc/fstab 

# /etc/fstab
# Created by anaconda on Wed Feb 24 15:34:07 2021
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
UUID=e260d75c-d83a-45fe-b084-a5016087f284 /                       xfs     defaults        0 0
UUID=bbce0f47-6db0-4d4a-a37f-025ed12a45ca /boot                   xfs     defaults        0 0
UUID=c299518f-7ce3-430b-872d-7d30e5ec3b98 swap                    swap    defaults        0 0
/dev/sr0	/var/ftp/dvd	iso9660	defaults	0	0
[root@localhost ~]# mount /dev/sr0 /var/ftp/dvd

Restart the vsftpd service, set the startup to start the vsftpd service, and then create the configuration file DVD of the software warehouse Repo, pointing to the software warehouse stored in the newly created /var/ftp/dvd.

To install kvm, you usually need three packages: QEMU kvm, libvirt, and virt manager. QEMU kvm mainly provides kvm simulator, libvirt provides related library files, and virt manager provides virtual machine manager.

[root@localhost ~]# yum -y install qemu-kvm libvirt virt-manager
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
redhat                                                               | 4.1 kB  00:00:00     
(1/2): redhat/group_gz                                               | 136 kB  00:00:00     
(2/2): redhat/primary_db                                             | 3.9 MB  00:00:01     
Package 10:qemu-kvm-1.5.3-126.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package libvirt.x86_64 0:2.0.0-10.el7 will be installed
--> Processing Dependency: libvirt-daemon-config-nwfilter = 2.0.0-10.el7 for package: libvirt-2.0.0-10.el7.x86_64
--> Processing Dependency: libvirt-daemon-driver-lxc = 2.0.0-10.el7 for package: libvirt-2.0.0-10.el7.x86_64
---> Package virt-manager.noarch 0:1.4.0-2.el7 will be installed
--> Processing Dependency: virt-manager-common = 1.4.0-2.el7 for package: virt-manager-1.4.0-2.el7.noarch
--> Running transaction check
---> Package libvirt-daemon-config-nwfilter.x86_64 0:2.0.0-10.el7 will be installed
---> Package libvirt-daemon-driver-lxc.x86_64 0:2.0.0-10.el7 will be installed
---> Package virt-manager-common.noarch 0:1.4.0-2.el7 will be installed
--> Processing Dependency: libvirt-python >= 0.7.0 for package: virt-manager-common-1.4.0-2.el7.noarch
--> Processing Dependency: python-ipaddr for package: virt-manager-common-1.4.0-2.el7.noarch
--> Running transaction check
---> Package libvirt-python.x86_64 0:2.0.0-2.el7 will be installed
---> Package python-ipaddr.noarch 0:2.1.9-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package                              Arch         Version               Repository    Size
 libvirt                              x86_64       2.0.0-10.el7          redhat       136 k
 virt-manager                         noarch       1.4.0-2.el7           redhat       629 k
Installing for dependencies:
 libvirt-daemon-config-nwfilter       x86_64       2.0.0-10.el7          redhat       140 k
 libvirt-daemon-driver-lxc            x86_64       2.0.0-10.el7          redhat       801 k
 libvirt-python                       x86_64       2.0.0-2.el7           redhat       321 k
 python-ipaddr                        noarch       2.1.9-5.el7           redhat        36 k
 virt-manager-common                  noarch       1.4.0-2.el7           redhat       1.1 M

Transaction Summary
Install  2 Packages (+5 Dependent packages)

Total download size: 3.1 M
Installed size: 13 M
Downloading packages:
(1/7): libvirt-2.0.0-10.el7.x86_64.rpm                               | 136 kB  00:00:00     
(2/7): libvirt-daemon-config-nwfilter-2.0.0-10.el7.x86_64.rpm        | 140 kB  00:00:00     
(3/7): libvirt-daemon-driver-lxc-2.0.0-10.el7.x86_64.rpm             | 801 kB  00:00:00     
(4/7): libvirt-python-2.0.0-2.el7.x86_64.rpm                         | 321 kB  00:00:00     
(5/7): python-ipaddr-2.1.9-5.el7.noarch.rpm                          |  36 kB  00:00:00     
(6/7): virt-manager-1.4.0-2.el7.noarch.rpm                           | 629 kB  00:00:00     
(7/7): virt-manager-common-1.4.0-2.el7.noarch.rpm                    | 1.1 MB  00:00:00     
Total                                                       5.1 MB/s | 3.1 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : libvirt-daemon-driver-lxc-2.0.0-10.el7.x86_64                            1/7 
  Installing : python-ipaddr-2.1.9-5.el7.noarch                                         2/7 
  Installing : libvirt-python-2.0.0-2.el7.x86_64                                        3/7 
  Installing : virt-manager-common-1.4.0-2.el7.noarch                                   4/7 
  Installing : libvirt-daemon-config-nwfilter-2.0.0-10.el7.x86_64                       5/7 
  Installing : libvirt-2.0.0-10.el7.x86_64                                              6/7 
  Installing : virt-manager-1.4.0-2.el7.noarch                                          7/7 
redhat/productid                                                     | 1.6 kB  00:00:00     
  Verifying  : libvirt-daemon-config-nwfilter-2.0.0-10.el7.x86_64                       1/7 
  Verifying  : libvirt-python-2.0.0-2.el7.x86_64                                        2/7 
  Verifying  : libvirt-2.0.0-10.el7.x86_64                                              3/7 
  Verifying  : virt-manager-1.4.0-2.el7.noarch                                          4/7 
  Verifying  : python-ipaddr-2.1.9-5.el7.noarch                                         5/7 
  Verifying  : virt-manager-common-1.4.0-2.el7.noarch                                   6/7 
  Verifying  : libvirt-daemon-driver-lxc-2.0.0-10.el7.x86_64                            7/7 

  libvirt.x86_64 0:2.0.0-10.el7              virt-manager.noarch 0:1.4.0-2.el7             

Dependency Installed:
  libvirt-daemon-config-nwfilter.x86_64 0:2.0.0-10.el7                                      
  libvirt-daemon-driver-lxc.x86_64 0:2.0.0-10.el7                                           
  libvirt-python.x86_64 0:2.0.0-2.el7                                                       
  python-ipaddr.noarch 0:2.1.9-5.el7                                                        
  virt-manager-common.noarch 0:1.4.0-2.el7                                                  


After the three packages required by kvm are installed, enter virt manager in the terminal to open the graphical interface to manage kvm.

[root@localhost ~]# virt-manager

Create a new virtual machine in kvm
Running an operating system in kvm also requires creating a new virtual machine.
In virtual machine manager, select the new command.

After entering the new virtual machine wizard, select how to install the operating system. Here, select network installation.

Enter the configuration page and find the following picture information to adjust.

After adding, select Start installation.

Installing rhel7 in a kvm virtual machine
Install the operating system in rhel7-vm01 virtual machine.

It is found that after installation, the content cannot be entered during login. Go back to the virtual machine configuration.

The previously set application has not been saved. Now there is no problem after resetting.

Tags: Virtualization kvm

Posted by zizzy80 on Fri, 03 Jun 2022 07:38:04 +0530