Table of Contents
Introduction
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: https://vagrantcloud.com/centos/7
==> box: Adding box 'centos/7' (v2004.01) for provider: libvirt
box: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/2004.01/providers/libvirt.box
Download redirected to host: cloud.centos.org
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|
config.vm.box = "centos/7"
config.vm.provider :libvirt do |libvirt|
libvirt.cpus = 1
libvirt.memory = 1024
end
end
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: 127.0.0.1
==> 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:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
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: 192.168.122.97:22
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
localhost.localdomain
[vagrant@localhost ~]$ pwd
/home/vagrant
Conclusion
You have to install and run Vagrant using Qemu-KVM. I hope will this your helpful. Thank you for reading the DevopsRoles page!
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?
Hi Oludare Eniola
I use Windows OS 10.
Thanks