Installation of KVM in Linux Machine & VM Centos - Ubuntu
Published: 2023-10-28 12:13:06

#### KVM

> Virtualization software in simple.

1. Kernel-based Virtual Machine
2. Is an open source virtualization technology built into Linux. Specifically, KVM lets you turn Linux into a hypervisor that allows a host machine to run multiple, isolated virtual environments called guests or virtual machines (VMs). 
3. KVM is part of Linux.
4. KVM is faster than VMware because it does not need to translate the guest operating system into the host's native instructions. While VMware is more flexible than KVM because it can run more than just one operating system on a virtual machine.
5. KVM can turn any Linux machine into a bare-metal hypervisor. This allows developers to scale computing infrastructure for different operating systems without investing in new hardware.
6. **_Though KVM runs on Linux, it can run Windows VMs and Microsoft Hyper-V can host Linux VMs._**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3qz5vp3b1kyocrscma3.png)

Below command should be > than 0.

```
egrep -c '(vmx|svm)' /proc/cpuinfo
free -h
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jxcx1gfx4det6xhgap3s.png)

```
sudo apt install cpu-checker
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t09vxbdgsfx3zvuznzwf.png)

```
sudo kvm-ok
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zfjsiqtfudx2qrmkn1lx.png)

```
sudo apt install -y qemu-kvm virt-manager libvirt-daemon-system virtinst libvirt-clients bridge-utils --> YES is passed inside the command so it will start the installation once you execute the command.
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu3ssqvs7ladjmgxc2h9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/thhgngnbtlsfwiw1xxer.png)

```
sudo systemctl enable –now libvirtd
sudo systemctl start libvirtd
sudo systemctl status libvirtd
sudo usermod -aG kvm $USER
sudo usermod -aG libvirt $USER
virt-manager
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frefmgga7f42axpppwyt.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nvk11ce5rq6o2clhb0ua.png)

```
Solution >> newgrp libvirt & reboot the PC
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cav68gcf54h0raw8h8ls.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ry1emf2500gendjzryh3.png)

#### Lets Install CENTOS & UBUNTU
### CENTOS

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4a1tc2jd5fufgyhvp07a.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vlkx7vfj2x8dpplqtht5.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lhfdd0w414rjsbbr0sht.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j993ia90z8jcbqtv8aut.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dl6bfo6z50ux1nra5a72.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4q4h3561gxrryebrowsj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vj7y5qocs70am77bteqo.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zm76nup60gdy31dki267.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n6rvcxe7mnw8dt2ke5uh.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xu9b320x5stp4n8n3e0j.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jllakox8fzc7lqy3b58o.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0x36lyyp7ox1hwpuzqw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5e4kfr1i8o1doysf24b9.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhdwsbf9rdqqkzypgtf7.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yrm8jndy67uck9qz3lda.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxu8b1rwwszzs23r5q2l.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/un6ltxpivsxm1wyp6b2d.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8drunucozc0b1onb4lj.png)

- Execute the below command in the target servers because if you take the clone of the target server , the machine name or IP should be same . To avoid this we need to execute the below commands.

```
echo -n > /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/use7rb28gg7ikusi8kd2.png)

#### SSH Key Generation

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0z23g0vdeequ6euc3hsd.png)

> Copy the ssh key to the target server

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/03s3khp7c4vwtn3s7dl5.png)

```
ssh-copy-id -i id_rsa.pub sathishpy1808@192.168.122.152
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3f8ziqa0e7zuuduj2maf.png)

### UBUNTU

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5vmi01ifbzdfx9fy16g.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wcuzy5jb4v0dn1kl6yb.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdbou5uhjdm0xub1sc3o.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov20yoin9abz1husw1pa.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/40cu6mtwd1ynr4rin8ob.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38as8pv4kkpw76dn0wur.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kbinzm215gtlflnb2zvs.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvo9tl9wzrav0pnuyait.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gq0cqn4xymd2zeb1x2ir.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ameme70e1pq3qq2ojvf1.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1q1k2wpa9uauf94v7a6g.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fl3krxone6g482pnu795.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8sfe8m9v2b9r4mgyx0x.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cilsk747mu4ecghpawui.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sv92o4vbamzk8gtft2ul.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckbw5ntm8wbbajravll3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de5cnzb42bzmtglzfum4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78hb4u0j2qv5mmfenz0w.png)

> WAIT TILL THE INSTALLATION COMPLETES

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0mx8pnqzgyjg6t2e3rj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11tf6hc2ggrfckdowwr6.png)

- Execute the below command in the target servers because if you take the clone of the target server , the machine name or IP should be same . To avoid this we need to execute the below commands.

```
echo -n > /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs006dmc1x0lzw63163v.png)

```
ssh-copy-id -i id_rsa.pub sathishpy1808_user@192.168.122.250
ssh sathishpy1808_user@192.168.122.250

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj127ccahsybs8egeeon.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1a2h7qihtsr340mebgmx.png)

#### ERROR

https://askubuntu.com/questions/345218/virt-manager-cant-connect-to-libvirt

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ijnox5beptqgi010iaxw.png)

#### Reference

https://linux-kvm.org/page/Main_Page
https://www.youtube.com/watch?v=59XDojAsWH4