Table of Contents
1. Check Hardware Virtualization Support
2. Install KVM and Related Packages
3. Verify KVM Installation
4. Set Up Network Bridging (Optional but Recommended)
5. Create a Virtual Machine
6. Manage Virtual Machines
7. Enable Nested Virtualization (Optional)
Home Operation and Maintenance CentOS How to install KVM on CentOS 7

How to install KVM on CentOS 7

Aug 11, 2025 pm 05:12 PM

Check CPU support for virtualization using egrep -c '(vmx|svm)' /proc/cpuinfo, where a result of 1 or higher indicates support; 2. Install KVM packages including qemu-kvm, libvirt, and virt-install using sudo yum install -y; 3. Start and enable libvirtd service with systemctl start and enable, then verify its status; 4. Confirm KVM modules are loaded via lsmod | grep kvm and ensure /dev/kvm exists, loading the module manually if needed and adding it to /etc/modules-load.d/kvm.conf for persistence; 5. Use default NAT networking by starting and enabling the default network with virsh net-start and net-autostart, or set up bridged networking optionally; 6. Create a VM using virt-install with specified parameters such as name, RAM, vCPUs, disk path, OS type, network, and ISO location, then follow terminal prompts to complete installation; 7. Manage VMs via virsh commands to list, start, shutdown, connect, or delete virtual machines; 8. Optionally enable nested virtualization by configuring kvm-intel.conf and reloading the module, verifying with cat /sys/module/kvm_intel/parameters/nested, which should return Y, completing a fully functional KVM setup on CentOS 7.

How to install KVM on CentOS 7

Installing KVM (Kernel-based Virtual Machine) on CentOS 7 allows you to run virtual machines efficiently using hardware virtualization. Here’s a step-by-step guide to set up KVM and create a basic virtualization environment.

How to install KVM on CentOS 7

1. Check Hardware Virtualization Support

Before installing KVM, ensure your CPU supports hardware virtualization (Intel VT-x or AMD-V) and that it’s enabled in BIOS.

Run this command:

How to install KVM on CentOS 7
egrep -c '(vmx|svm)' /proc/cpuinfo
  • If the output is 0, virtualization is not supported or disabled.
  • If the output is 1 or higher, your system supports KVM.

You can also check if /dev/kvm exists after loading the module (next step).


Install the necessary packages for KVM and virtual machine management:

How to install KVM on CentOS 7
sudo yum install -y qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
  • qemu-kvm: Main KVM module for emulation.
  • libvirt: Provides the libvirtd daemon for managing VMs.
  • virt-install: Command-line tool to create VMs.
  • libguestfs-tools: Tools for manipulating guest disk images.

Now start and enable the libvirtd service:

sudo systemctl start libvirtd
sudo systemctl enable libvirtd

Verify the service is running:

sudo systemctl status libvirtd

3. Verify KVM Installation

Check that KVM modules are loaded:

lsmod | grep kvm

You should see kvm_intel (or kvm_amd) and kvm.

Also confirm that /dev/kvm exists:

ls -l /dev/kvm

If it's missing, load the module manually:

sudo modprobe kvm-intel    # For Intel CPUs
# OR
sudo modprobe kvm-amd      # For AMD CPUs

Add the module to be loaded at boot:

echo "kvm-intel" | sudo tee /etc/modules-load.d/kvm.conf

Note: On CentOS 7, the module is usually loaded automatically when libvirtd starts.


By default, libvirt uses NAT networking via virbr0. For better performance and direct network access, consider setting up a bridge.

But for basic use, the default network is sufficient. Start and enable it:

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

Check with:

sudo virsh net-list --all

5. Create a Virtual Machine

Use virt-install to create a VM. Example: Install a CentOS 7 VM from an ISO.

First, download an ISO and place it in /var/lib/libvirt/images/.

Then run:

sudo virt-install \
  --name centos7-vm \
  --ram 2048 \
  --vcpus 2 \
  --disk path=/var/lib/libvirt/images/centos7-vm.qcow2,size=20 \
  --os-type linux \
  --os-variant rhel7 \
  --network network=default \
  --graphics none \
  --console pty,target_type=serial \
  --location '/var/lib/libvirt/images/CentOS-7-x86_64-Minimal-2009.iso' \
  --extra-args "console=ttyS0"

Replace the ISO path with your actual ISO file. This example uses text-mode installation via console.

After running the command, the installation will begin in the terminal. Follow the prompts to complete the OS setup.


6. Manage Virtual Machines

Use virsh to manage VMs:

  • List running VMs:

    sudo virsh list
  • List all VMs (including shut off):

    sudo virsh list --all
  • Start, shutdown, or reboot:

    sudo virsh start centos7-vm
    sudo virsh shutdown centos7-vm
  • Connect to VM console:

    sudo virsh console centos7-vm
  • Delete a VM:

    sudo virsh destroy centos7-vm
    sudo virsh undefine centos7-vm

7. Enable Nested Virtualization (Optional)

If you want to run VMs inside a KVM guest (e.g., for lab environments), enable nested virtualization:

For Intel:

echo "options kvm-intel nested=Y" | sudo tee /etc/modprobe.d/kvm-intel.conf

Then reload the module:

sudo rmmod kvm-intel
sudo modprobe kvm-intel

Verify:

cat /sys/module/kvm_intel/parameters/nested

Should output Y.


That’s it. You now have a working KVM setup on CentOS 7. You can create and manage virtual machines using command-line tools or optionally install virt-manager on a desktop system for GUI access.

Basically just follow the steps, make sure virtualization is enabled, and use virt-install or virsh to manage your VMs.

The above is the detailed content of How to install KVM on CentOS 7. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1594
276
How to format a new disk in CentOS How to format a new disk in CentOS Aug 03, 2025 am 08:19 AM

Identifythenewdiskusinglsblkorfdisk-ltolocatethecorrectdevicelike/dev/sdb.2.Optionallypartitionthediskwithfdisk/dev/sdb,createaprimarypartitionusingdefaultsettings,andwritechangeswithw,thenrunpartprobetoupdatethekernel.3.Createafilesystemusingmkfs-tx

How to configure network bonding in CentOS How to configure network bonding in CentOS Jul 27, 2025 am 03:44 AM

Make sure the system has loaded the bonding module and confirm that the network card interface is available, use modprobebonding and lsmod to verify; 2. Create /etc/sysconfig/network-scripts/ifcfg-bond0 configuration files, set DEVICE, TYPE, BONDING_MASTER, IP parameters and BONDING_OPTS=mode=active-backupmiimon=100primary=ens33; 3. Configure ifcfg files of physical network cards ens33 and ens34, set MASTER=bond0, SLAVE=yes and remove IP configuration

How to install Apache on CentOS How to install Apache on CentOS Aug 02, 2025 am 06:12 AM

Update the system: Run sudoyumupdate-y or sudodnfupdate-y to ensure the system is up to date; 2. Install Apache: Use sudoyuminstallhttpd-y or sudodnfinstallhttpd-y to install the web server; 3. Start and enable the service: execute sudosystemctlstarthttpd and sudosystemctlenablehttpd to ensure the power is started automatically; 4. Configure the firewall: If firewalld is enabled, run sudofirewall-cmd--permanent-add-service=http--add

How to install Docker on CentOS 7 How to install Docker on CentOS 7 Jul 27, 2025 am 01:14 AM

DockercanbesuccessfullyinstalledonCentOS7byfollowingthesesteps:1.RemoveoldDockerversionsusingsudoyumremovedocker*toensureacleansetup.2.Installrequireddependencieswithsudoyuminstall-yyum-utilsdevice-mapper-persistent-datalvm2.3.AddtheofficialDockerCEr

How to configure NTP server on CentOS 7 How to configure NTP server on CentOS 7 Aug 16, 2025 am 08:27 AM

ToconfigureanNTPserveronCentOS7usingchrony,firstinstallandenablechronydwithsudoyuminstallchrony-y,thenstartandenableitviasystemctlstartchronydandsystemctlenablechronyd;next,edit/etc/chrony.conftosetupstreamserverslikeserver0.pool.ntp.orgiburst,allowc

How to configure Iptables in CentOS How to configure Iptables in CentOS Aug 13, 2025 am 07:00 AM

First, confirm the CentOS version. CentOS6 uses iptables by default. CentOS7/8 uses firewalld. By default, iptables-services must be installed to enable traditional iptables; 2. On CentOS7/8, firewalld must be stopped and disabled. After installing iptables-services, start and enable iptables service; 3. Use the iptables command to configure rules, including viewing rules, clearing rules, setting default policies, allowing loopbacks, established connections, SSH, HTTP, HTTPS and ICMP traffic; 4. Pass serviceiptablessave

How to fix 'permission denied' in CentOS How to fix 'permission denied' in CentOS Jul 29, 2025 am 02:23 AM

Checkfilepermissionswithls-landfixusingchmodcautiously;2.Verifyownershipwithls-landcorrectusingchownorchown-R;3.CheckSELinuxstatuswithsestatusandfilecontextwithls-Z,thenfixwithrestorecon,chcon,oraudit2why,andtemporarilytestwithsetenforce0;4.Ensurethe

How to mount a Windows share in CentOS How to mount a Windows share in CentOS Aug 15, 2025 am 03:40 AM

Installcifs-utilsandoptionallysamba-clientusingyumordnf.2.Createamountpointlike/mnt/windows-share.3.ManuallymounttheWindowsshareusingthemount-tcifscommandwithappropriateoptions,preferablyusingacredentialsfileforsecurity.4.Storecredentialssecurelyin/e

See all articles