Vagrant using Qemu-KVM provider


In this tutorial, How to install and run Vagrant using Qemu-KVM. You use Vagrant for DevOps professionals, coder sysadmin. I will be installing and be running Vagrant on My Laptop is Fedora 32. Now, let’s go Vagrant using Qemu-KVM provider.

Installing and running Vagrant using Qemu-KVM

Check the machine supports virtualization

[HuuPV@DevopsRoles ~]$ sudo lscpu | grep Virtualization
Virtualization:                  VT-x

Install qemu-kvm

[HuuPV@DevopsRoles ~]$ sudo dnf install qemu-kvm libvirt libguestfs-tools virt-install rsync
[HuuPV@DevopsRoles ~]$ sudo systemctl enable --now libvirtd

Install Vagrant and vagrant libvirtd plugin

[HuuPV@DevopsRoles ~]$ sudo dnf install vagrant
[HuuPV@DevopsRoles ~]$ sudo vagrant plugin install vagrant-libvirt

Using the vagrant box command to Add a box

Link download box here

[HuuPV@DevopsRoles vagrant-test]$ vagrant box add centos/7 --provider=libvirt

==> box: Loading metadata for box 'centos/7'
    box: URL:
==> box: Adding box 'centos/7' (v2004.01) for provider: libvirt
    box: Downloading:
Download redirected to host:
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'centos/7' (v2004.01) for 'libvirt'!

Test: Create a minimal Vagrantfile

$ mkdir vagrant-test
$ cd vagrant-test
$ vi Vagrantfile
# An example which also sets the amount memory and number of CPUs in Vagrantfile file

Vagrant.configure("2") do |config| = "centos/7"
  config.vm.provider :libvirt do |libvirt|
    libvirt.cpus = 1
    libvirt.memory = 1024

Start the box

vagrant up

The output is an example below:

[HuuPV@DevopsRoles vagrant-test]$ vagrant up
Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Uploading base box image as volume into libvirt storage...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default:  -- Name:              vagrant-test_default
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              1
==> default:  -- Feature:           acpi
==> default:  -- Feature:           apic
==> default:  -- Feature:           pae
==> default:  -- Memory:            1024M
==> default:  -- Management MAC:    
==> default:  -- Loader:            
==> default:  -- Nvram:             
==> default:  -- Base box:          centos/7
==> default:  -- Storage pool:      default
==> default:  -- Image:             /home/HuuPV/.local/share/libvirt/images/vagrant-test_default.img (41G)
==> default:  -- Volume Cache:      default
==> default:  -- Kernel:            
==> default:  -- Initrd:            
==> default:  -- Graphics Type:     vnc
==> default:  -- Graphics Port:     -1
==> default:  -- Graphics IP:
==> default:  -- Graphics Password: Not defined
==> default:  -- Video Type:        cirrus
==> default:  -- Video VRAM:        9216
==> default:  -- Sound Type:	
==> default:  -- Keymap:            en-us
==> default:  -- TPM Path:          
==> default:  -- INPUT:             type=mouse, bus=ps2
==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Configuring and enabling network interfaces...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /home/HuuPV/Vagrant_VMS/vagrant-test/ => /vagrant

Connect to your new machine

vagrant ssh

The output as the example below

[HuuPV@DevopsRoles vagrant-test]$ vagrant ssh
[vagrant@localhost ~]$ hostname
[vagrant@localhost ~]$ pwd


You have to install and run Vagrant using Qemu-KVM. I hope will this your helpful. Thank you for reading the DevopsRoles page!


About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

2 thoughts on “Vagrant using Qemu-KVM provider

  1. Can we do this on a Windows OS directly? I mean by creating a folder in drive, then open a terminal in the window and change to the folder that I created to install QEMU VM and install Vagrant?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.