Kernel-based Virtual Machine (KVM) is an open-source virtualization technology built into the Linux kernel. It allows you to run multiple, isolated virtual machines on a single physical server. In this comprehensive guide, we’ll show you how to install KVM on Oracle Linux and set up your virtualization environment. We’ll cover the installation process, network configuration, and how to create and manage virtual machines.
Table of Contents
- Prerequisites
- Installing KVM and Necessary Packages
- Configuring Networking for KVM
- Creating and Managing Virtual Machines
- Conclusion
Prerequisites
Before you proceed, make sure your system meets the following requirements:
- Oracle Linux installed and updated
- A processor with hardware virtualization support (Intel VT-x or AMD-V)
- A minimum of 4GB RAM
Tip: If you haven’t already, learn how to disable root login on Oracle Linux and enable 2FA on Oracle Linux for enhanced security.
How to Install KVM on Oracle Linux
Installing KVM and Necessary Packages
- First, update your system and install the necessary packages:
sudo yum update -y
sudo yum install -y qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
- Enable and start the libvirtd service:
sudo systemctl enable libvirtd
sudo systemctl start libvirtd
- Verify the installation by running the following command:
sudo virsh list --all
If the installation is successful, you should see an empty list of virtual machines.
Configuring Networking for KVM on Oracle Linux
- KVM uses a default NAT-based network for virtual machines. To see the available networks, run:
sudo virsh net-list --all
- If the default network is not active, enable and start it:
sudo virsh net-autostart default
sudo virsh net-start default
- To create a bridged network, install the bridge-utils package:
sudo yum install -y bridge-utils
- Configure a new network bridge by editing the
/etc/sysconfig/network-scripts/ifcfg-<interface>
file (replace<interface>
with your network interface name). For example:
DEVICE=<interface>
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
- Restart the network service for the changes to take effect:
sudo systemctl restart network
- Verify that the bridge is up and running:
sudo brctl show
Creating and Managing Virtual Machines
- To create a new virtual machine, use the
virt-install
command. For example:
sudo virt-install --name myvm --memory 2048 --vcpus 2 --disk size=20 --os-type=linux --os-variant=oraclelinux7 --network bridge=<bridge_name> --graphics vnc --location /path/to/oraclelinux7.iso
This command creates a virtual machine named myvm
with 2GB of RAM, 2 vCPUs, a 20GB disk, and a bridged network. Replace <bridge_name>
with the name of the bridge you created earlier and /path/to/oraclelinux7.iso
with the actual path to the Oracle Linux ISO file.
- To manage your virtual machines, use the
virsh
command. Some useful commands include:- List all virtual machines:
sudo virsh list --all
- Start a virtual machine:
sudo virsh start <vm_name>
- Shutdown a virtual machine:
sudo virsh shutdown <vm_name>
- Suspend a virtual machine:
sudo virsh suspend <vm_name>
- Resume a virtual machine:
sudo virsh resume <vm_name>
- Delete a virtual machine:
sudo virsh undefine <vm_name>
- List all virtual machines:
- To access the virtual machine’s console, use the
virsh console
command:
sudo virsh console <vm_name>
- If you prefer to manage your virtual machines with a graphical interface, you can use Virtual Machine Manager. Install it with:
sudo yum install -y virt-manager
After installation, launch Virtual Machine Manager and connect to your KVM host using your system’s credentials.
Conclusion
You’ve successfully installed KVM on Oracle Linux and learned how to create and manage virtual machines using both command-line and graphical tools. Now you can start deploying virtual machines and optimizing your server resources.
For more information and tutorials on Oracle Linux, check out the following resources: