Operations 12 min read

Master Linux KVM: Step-by-Step Installation, Configuration, and VM Management

This guide walks you through installing KVM on Linux, configuring libvirt tools, verifying hardware virtualization support, setting up networking, creating and managing virtual machines with virt-install and virsh, and monitoring VM performance using virt-top.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux KVM: Step-by-Step Installation, Configuration, and VM Management

KVM (Kernel-based Virtual Machine) is a Linux‑kernel virtualization technology that runs on hardware with virtualization extensions, allowing guest operating systems to be fully or partially virtualized.

1. VM Management Tools

KVM ships with the qemu-kvm binary, but using the libvirt suite (including the libvirtd daemon and the virsh CLI) is recommended for easier management of KVM, Xen, VMWare ESX and other hypervisors.

Additional graphical or script‑driven tools include: virt-manager – GUI for managing VMs vm-install – menu‑driven installer for guest OSes virt-viewer – X viewer with X509/SASL TLS/SSL support

2. Verify Hardware Virtualization Support

# egrep '(vmx|svm)' /proc/cpuinfo

If the output contains vmx (Intel) or svm (AMD), the CPU supports virtualization.

3. Install KVM Packages

Install KVM and related tools using your distro’s package manager (e.g., yum on RHEL/CentOS or apt on Debian). # yum install kvm After installing the hypervisor, install the management stack:

# yum install qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools

List the installed packages (example output omitted for brevity):

# rpm -qa | egrep "virt|kvm|qemu"

4. Network Requirements for VMs

By default VMs can only reach other VMs on the same host. To enable VLAN or external access, configure a bridge interface.

# edit /etc/sysconfig/network-scripts/ifcfg-eth0
BRIDGE=br0

Create the bridge configuration file:

# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE="br0"
BOOTPROTO="static"
IPADDR="xxx.xxx.xxx.xxx"
NETMASK="255.255.255.0"
ONBOOT="yes"
TYPE="Bridge"
NM_CONTROLLED="no"

If a firewall (e.g., iptables) is active, add a rule to allow bridge traffic.

5. Additional Pre‑Creation Settings

Ensure sufficient space in /var/lib/libvirt/images for VM disk images, or point the images to another location.

Enable IP forwarding by adding the following line to /etc/sysctl.conf and rebooting:

net.ipv4.ip_forward=1

6. Create a VM with virt-install

Use virt-install in interactive or non‑interactive mode. Example command:

# virt-install \
  -n myRHELVM1 \
  --description "Test VM with RHEL 6" \
  --os-type Linux \
  --os-variant rhel6 \
  --ram 2048 \
  --vcpus 2 \
  --disk path=/var/lib/libvirt/images/myRHELVM1.img,bus=virtio,size=10 \
  --graphics none \
  --cdrom /var/rhel-server-6.5-x86_64-dvd.iso \
  --network bridge:br0

Key parameters:

-n : VM name

--description : Human‑readable description

--os-type / --os-variant : Guest OS family and version

--ram : Memory size in MB

--vcpus : Number of virtual CPUs

--disk : Disk image path, bus type, and size (GB)

--graphics none : Use a text console instead of VNC

--cdrom : Path to installation ISO (or NFS/HTTP location)

--network bridge:br0 : Attach the VM to the previously created bridge

7. List All VMs

# virsh list --all

8. Edit a VM’s XML Definition

VM definitions are stored as <name>.xml under /etc/libvirt/qemu/. Edit them safely with:

virsh edit myRHELVM1

9. Connect to the VM Console

# virsh console myRHELVM1

Exit the console with Ctrl+]. If no graphical console is available, use the serial console as shown.

10. Show VM Information

# virsh dominfo myRHELVM1

11. Monitor VM Memory and CPU Usage

# virt-top

12. Start, Stop, and Reboot VMs

# virsh shutdown myRHELVM1   # graceful shutdown
# virsh reboot myRHELVM1     # reboot
# virsh start myRHELVM1      # start the VM

After starting, use virsh list --all to verify the VM state.

Source: "How to Install Linux KVM and Create Guest VM with Examples" (translated by 4byte.cn).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KVMcloud operationslibvirtVM managementLinux virtualizationvirt-install
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.