How to Create KVM Virtual Machines on CentOS Server

Running virtual machines (VMs) on your own CentOS server is a cool way to save money and learn new skills. With a little setup, you can turn one physical computer into many “mini computers” using something called KVM. I use it myself at home, and once it’s running, it’s like having a whole computer lab in one box—without the noisy fans or tangled cables.

In this guide, I’ll show you how to set up KVM virtual machines step by step on a CentOS server. Don’t worry—it’s not as scary as it sounds. I’ll explain what things mean as we go, and I’ll keep the steps simple and short.


What is KVM?

Let’s start with the basics.

KVM stands for Kernel-based Virtual Machine. It’s a way to run multiple operating systems—like Linux or Windows—on a single computer. Think of it as a way to split your real computer into several fake ones that work independently.

Here are some words you’ll hear a lot:

  • Virtual Machine (VM): A pretend computer that runs inside your real one.
  • Host: The main computer running the VMs.
  • Guest: Each virtual machine running inside the host.
  • Hypervisor: The software that creates and manages VMs. KVM is one type of hypervisor.
  • libvirt: A tool that helps manage VMs with KVM.

If this sounds complex, think of it like running multiple TV shows on one streaming account—you just switch between them as needed.


Why I Like Using KVM

I’ve used a few VM tools before, but KVM is my go-to when I use CentOS. It’s free, built into the Linux kernel, and pretty lightweight. You don’t need to install a heavy GUI unless you want one.

Here’s what I like:

  • It runs fast.
  • I don’t need a fancy computer.
  • It feels stable and solid.
  • It works well with CentOS.

Plus, once you get used to the commands, you feel like a keyboard ninja.


Before You Begin

Let’s make sure your server is ready. I recommend:

  • A CentOS 7 or 8 server (minimal install is fine)
  • At least 2 CPU cores
  • At least 4 GB of RAM (8 GB is better)
  • 20 GB of free disk space or more
  • A stable internet connection

You’ll also need root access or sudo privileges. And maybe a drink and a snack—you deserve it.


Step 1: Check If Your Server Supports Virtualization

Not all CPUs can run VMs. Let’s find out if yours can.

Open a terminal and run:

egrep -c '(vmx|svm)' /proc/cpuinfo
  • If the number is 1 or more, you’re good to go.
  • If it shows 0, your CPU may not support virtualization. Double-check BIOS settings.

That one line saved me hours once. I once spent forever trying to make VMs work, only to learn virtualization was disabled in the BIOS. Oops.


Step 2: Install KVM and Required Tools

Now we’ll install the KVM packages.

For CentOS 7 or 8, use:

sudo yum install -y qemu-kvm libvirt virt-install bridge-utils virt-manager

This installs everything needed to create and manage VMs.

After that, start and enable the libvirtd service:

sudo systemctl start libvirtd
sudo systemctl enable libvirtd

Let’s check if it worked:

sudo virsh list --all

If it doesn’t show an error, you’re ready.


Step 3: Create a Virtual Network (Optional but Handy)

KVM usually sets up a default virtual network, but you can make your own.

Here’s how I set up a basic NAT network:

sudo virsh net-list --all

If “default” is there and active, you can use it. If not, run:

sudo virsh net-start default
sudo virsh net-autostart default

This makes sure your VMs can talk to the internet through your host.


Step 4: Download an ISO File

Just like installing a real computer, VMs need an installer.

Pick your favorite OS (Ubuntu, Debian, CentOS, etc.) and download the ISO. I usually put mine in /var/lib/libvirt/images/.

For example:

cd /var/lib/libvirt/images/
sudo wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.4.0-amd64-netinst.iso

You can use any ISO you want—as long as your server has space for it.


Step 5: Create a Virtual Machine

Now the fun part: building your VM.

Use this command:

sudo virt-install \
--name=myvm \
--ram=2048 \
--vcpus=2 \
--disk path=/var/lib/libvirt/images/myvm.qcow2,size=20 \
--cdrom=/var/lib/libvirt/images/debian-12.4.0-amd64-netinst.iso \
--os-type=linux \
--network network=default \
--graphics none \
--console pty,target_type=serial

Let’s break it down:

  • --name: The name of your VM
  • --ram: How much memory to give the VM
  • --vcpus: Number of CPU cores
  • --disk: Where to store the VM’s hard drive
  • --cdrom: The ISO file for installing the OS
  • --graphics none: We’re using text only, no GUI
  • --console: So we can see the install process in the terminal

It will now boot up your VM in the terminal. Follow the steps to install the OS just like you would on a real PC.


Step 6: Managing Your VM

After install, you can start, stop, and check on your VM with these commands:

  • Start a VM:
sudo virsh start myvm
  • Shut it down:
sudo virsh shutdown myvm
  • Force off (like pulling the plug):
sudo virsh destroy myvm
  • See running VMs:
sudo virsh list
  • See all VMs (even stopped ones):
sudo virsh list --all

Once you know these, you’ll feel like you’re piloting a spaceship.


Benefits of KVM on CentOS

Why bother setting this up? Here’s what I’ve gained:

  • Multiple systems on one machine
  • Less hardware needed
  • Safer testing: I can break things in a VM without hurting my server
  • Fast setup and teardown of new environments

Tips and Tricks (aka “Learn From My Goofs”)

Some handy things I’ve learned:

  • Always give your VMs unique names. Trust me, vm1, vm1, vm1 gets confusing fast.
  • Keep ISO files in one folder. Easier to manage.
  • Don’t give VMs all your RAM. Leave some for the host.

Useful Tools and Extras

Here are some nice tools to try out later:

Optional GUI Tools:

  • virt-manager: A graphical tool to manage VMs (works best with a desktop environment)
  • cockpit: A web-based server tool that supports VM management

Common ISO Sources:


Wrapping It Up

Running KVM virtual machines on CentOS is a great way to build and test multiple systems on one physical machine. You can try out new things without risking your main server.

At first, it might feel like riding a unicycle while juggling. But with practice, you’ll be creating, deleting, and managing VMs like a pro. And unlike real juggling, you won’t break any plates.

Leave a Reply