install kvm on centos 7 with console

Some info about setting up KVM on centos 7

Prerequisites
Make sure that your system has the hardware virtualization extensions: For Intel-based hosts, verify the CPU virtualization extension [vmx] are available using following command.

[[email protected] ~]# grep -e ‘vmx’ /proc/cpuinfo
Check Virtualization Support
Check Virtualization Support

For AMD-based hosts, verify the CPU virtualization extension [svm] are available.

[[email protected] ~]# grep -e ‘svm’ /proc/cpuinfo
Check CPU Virtualization Support
Check CPU Virtualization Support

If there is no output make sure that virtualization extensions is enabled in BIOS. Verify that KVM modules are loaded in the kernel “it should be loaded by default”.

[[email protected] ~]# lsmod | grep kvm
The output should contains kvm_intel for intel-based hosts or kvm_amd for amd-based hosts.

Check KVM Kernel Module Support
Check KVM Kernel Module

Before starting , you will need the root account or non-root user with sudo privileges configured on your system and also make sure that your system is up-to-date.

[[email protected] ~]# yum update
Make sure that Selinux be in Permissive mode.

[[email protected] ~]# setenforce 0
Step 1: KVM Installation and Deployment
1. We will install qemu-kvm and qemu-img packages at first. These packages provide the user-level KVM and disk image manager.

[[email protected] ~]# yum install qemu-kvm qemu-img
2. Now, you have the minimum requirement to deploy virtual platform on your host, but we also still have useful tools to administrate our platform such as:

virt-manager provides a GUI tool to administrate your virtual machines.
libvirt-client provides a CL tool to administrate your virtual environment this tool called virsh.
virt-install provides the command “virt-install” to create your virtual machines from CLI.
libvirt provides the server and host side libraries for interacting with hypervisors and host systems.
Let’s install these above tools using the following command.

[[email protected] ~]# yum install virt-manager libvirt libvirt-python libvirt-client
3. For RHEL/CentOS7 users, also still having additional package groups such as: Virtualization Client, Virtualization Platform and Virtualization Tools to install.

[[email protected] ~]#yum groupinstall virtualization-client virtualization-platform virtualization-tools
4. The virtualization daemon which manage all of the platform is “libvirtd”. lets restart it.

[[email protected] ~]#systemctl restart libvirtd
5. After restarting the daemon, then check its status by running following command.

[[email protected] ~]#systemctl status libvirtd
Sample Output
libvirtd.service – Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled)
Active: active (running) since Mon 2014-12-29 15:48:46 EET; 14s ago
Main PID: 25701 (libvirtd)
Check Libvirtd Status
Check Libvirtd Status

Now, lets switch to the next section to create our virtual machines.

============================

Step 1: Configure Storage Pool

Virsh CLI tool is a management user interface for managing virsh guest domains. The virsh program can be used either to run one command by giving the command and its arguments on the shell command line.

In this section, we will use it to create storage pool for our KVM environment. For more information about the tool, use the following command.

# man virsh

1. Using the command pool-define-as with virsh to define new storage pool, you need also to specify name, type and type’s arguments.

In our case, name will be Spool1, type will be dir. By default you could provide five arguments for the type:

  1. source-host
  2. source-path
  3. source-dev
  4. source-name
  5. target

For (Dir) type, we need the last argumet “target” to specify the path of storage pool, for the other arguments we could use “” to unspecific them.

# virsh pool-define-as Spool1 dir - - - - "/mnt/personal-data/SPool1/"

Create New Storage Pool

Create New Storage Pool

2. To check the all storage pools you have in the environment, use the following command.

# virsh pool-list --all

List All Storage Pools

List All Storage Pools

3. Now it’s time to build the storage pool, which we have defined above with the following command.

# virsh pool-build Spool1

Build KVM Storage Pool

Build Storage Pool

4. Using the virsh command pool-start to active/enable the storage pool we have just created/built above.

# virsh pool-start Spool1

Enable KVM Storage Pool

Active Storage Pool

5. Check the status of environment storage pools using the following command.

# virsh pool-list --all

Check KVM Storage Pool Status

Check Storage Pool Status

You will notice that the status of Spool1 converted to active.

6. Configure Spool1 to start by libvirtd service every time automaticlly.

# virsh pool-autostart Spool1

Configure KVM Storage Pool

Configure KVM Storage Pool

7. Finally lets display information about our new storage pool.

# virsh pool-info Spool1

Check KVM Storage Pool Information

Check KVM Storage Pool Information

Congratulations, Spool1 is ready to be used lets try to create storage volumes using it.

Step 2: Configure Storage Volumes/Disk Images

Now it is disk image’s turn, using qemu-img to create new disk image from Spool1. For more details about qemy-img, use the man page.

# man qemu-img

8. We should specify the qemu-img command “create, check,….etc”, disk image format, the path of disk image you want to create and the size.

# qemu-img create -f raw /mnt/personal-data/SPool1/SVol1.img 10G

Create KVM Storage Volumes

Create Storage Volume

9. By using qemu-img command info, you could get information about your new disk image.

Check KVM Storage Volume Information

Check Storage Volume Information

Warning: Never use qemu-img to modify images in use by a running virtual machine or any other process; this may destroy the image.

Now its time to create virtual machines in the next step.

Step 3: Create Virtual Machines

10. Now with the last and latest part, we will create virtual machines using virt-istall. The virt-install is a command line tool for creating new KVM virtual machines using the “libvirt” hypervisor management library. For more details about it, use:

# man virt-install

To create new KVM virtual machine, you need to use the following command with all the details like shown in the below.

  1. Name: Virtual Machine’s name.
  2. Disk Location: Location of disk image.
  3. Graphics : How to connect to VM “Usually be SPICE”.
  4. vcpu : Number of virtual CPU’s.
  5. ram : Amount of allocated memory in megabytes.
  6. Location : Specify the installation source path.
  7. Network : Specify the virtual network “Usually be vibr00 bridge”.

Create KVM machines

virt-install –name cloudapp3 –ram 12000 –disk path=/data/kvm/spool/cloudapp3.img –location /data/images/CentOS-7-x86_64-DVD-1708.iso  –nographics –accelerate –extra-args=”console=ttyS0″ –network bridge=br1

Most import parameter is –extra-args=”console=ttyS0″, otherwise can’t connect to console

 

This is a good reference about how to install kvm utilities
<a href=”https://www.tecmint.com/install-and-configure-kvm-in-linux/”>https://www.tecmint.com/install-and-configure-kvm-in-linux/</a>