Sat, February 10, 2018 ยท 2 min read

Using vagrant with kvm

Using vagrant with kvm

  1. Install Vagrant:
[cipher@server ~]$ sudo dnf install vagrant
  1. Install Vagrant libvirt plugins:
[cipher@server ~]$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Installed the plugin 'vagrant-libvirt (0.0.37)'!

[cipher@server ~]$ vagrant plugin install vagrant-mutate
Installing the 'vagrant-mutate' plugin. This can take a few minutes...
Installed the plugin 'vagrant-mutate (1.2.0)'!
  1. Add CentOS 7 Vagrant box:
[cipher@server ~]$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.

[cipher@server ~]$ vagrant box add https://app.vagrantup.com/centos/boxes/7

==> box: Loading metadata for box 'https://app.vagrantup.com/centos/boxes/7'
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 2
==> box: Adding box 'centos/7' (v1801.02) for provider: libvirt
  1. Verify box download:
[cipher ~]$ vagrant box list
centos/7 (libvirt, 1801.02)
  1. Create a Vagrantfile and start the VM:
[cipher ~/vagrant]$ vagrant init centos/7
[cipher ~/vagrant]$ vagrant up
Bringing machine 'default' up with 'libvirt' provider...
==> 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_default
==> default: -- Domain type: kvm
==> default: -- Cpus: 1
==> default: -- Memory: 512M
==> default: -- Base box: centos/7
==> default: -- Storage pool: default
==> default: -- Image: /var/lib/libvirt/images/vagrant_default.img (41G)
==> default: -- Graphics Type: vnc
==> default: -- Graphics Port: 5900
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /home/cipher/vagrant/ => /vagrant
  1. Connect via SSH:
[cipher ~/vagrant]$ vagrant ssh
[vagrant@localhost ~]$ hostname
localhost.localdomain
[vagrant@localhost ~]$ w
17:11:08 up 2 min, 1 user, load average: 0.67, 0.46, 0.18
USER     TTY     FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
vagrant  pts/0   192.168.121.1    17:11    4.00s  0.20s  0.05s w