How to create a CentOS 8 VM using Vagrant?, how can I run CentOS 8 on KVM/VirtualBox/VMWare using Vagrant?, Can I use Vagrant to manage CentOS 8 virtual machine?. Vagrant enables you to create and configure reproducible, and portable development environments using Virtual machine images called Boxes.
With Vagrant, you can setup your development environments in seconds on various virtualization platforms such as VirtualBox, KVM, VMware, Hyper-V, e.t.c. CentOS 8 has been available for a while now. if you love working with new technologies and already started building your apps from CentOS 8, you can use this guide to setup your Vagrant Lab.
Step 1: Install Vagrant
Check our guides below:
Step 2: Download CentOS 8 Vagrant box
Download Vagrant box for your virtualization environment using one of the commands below:
For KVM users:
$ vagrant box add centos/stream8 --provider=libvirt
==> box: Loading metadata for box 'centos/stream8'
box: URL: https://vagrantcloud.com/centos/stream8
==> box: Adding box 'centos/stream8' (v20210210.0) for provider: libvirt
box: Downloading: https://vagrantcloud.com/centos/boxes/stream8/versions/20210210.0/providers/libvirt.box
Download redirected to host: cloud.centos.org
box: Calculating and comparing box checksum...
==> box: Successfully added box 'centos/stream8' (v20210210.0) for 'libvirt'!
For VirtualBox users:
$ vagrant box add centos/stream8 --provider=virtualbox
==> box: Loading metadata for box 'centos/stream8'
box: URL: https://vagrantcloud.com/centos/stream8
==> box: Adding box 'centos/stream8' (v20210210.0) for provider: virtualbox
box: Downloading: https://vagrantcloud.com/centos/boxes/stream8/versions/20210210.0/providers/virtualbox.box
Download redirected to host: cloud.centos.org
box: Calculating and comparing box checksum...
==> box: Successfully added box 'centos/stream8' (v20210210.0) for 'virtualbox'!
For Parallels:
$ vagrant box add generic/centos8s --provider=parallels
==> box: Loading metadata for box 'generic/centos8s'
box: URL: https://vagrantcloud.com/generic/centos8s
==> box: Adding box 'generic/centos8s' (v4.1.16) for provider: parallels
box: Downloading: https://vagrantcloud.com/generic/boxes/centos8s/versions/4.1.16/providers/parallels.box
box: Calculating and comparing box checksum...
==> box: Successfully added box 'generic/centos8s' (v4.1.16) for 'parallels'!
VMware:
$ vagrant box add generic/centos8s --provider=vmware_desktop
==> box: Loading metadata for box 'generic/centos8s'
box: URL: https://vagrantcloud.com/generic/centos8s
==> box: Adding box 'generic/centos8s' (v4.1.16) for provider: vmware_desktop
box: Downloading: https://vagrantcloud.com/generic/boxes/centos8s/versions/4.1.16/providers/vmware_desktop.box
box: Calculating and comparing box checksum...
==> box: Successfully added box 'generic/centos8s' (v4.1.16) for 'vmware_desktop'!
Docker:
$ vagrant box add generic/rocky9 --provider=docker
==> box: Loading metadata for box 'generic/rocky9'
box: URL: https://vagrantcloud.com/generic/rocky9
==> box: Adding box 'generic/rocky9' (v4.1.16) for provider: docker
box: Downloading: https://vagrantcloud.com/generic/boxes/rocky9/versions/4.1.16/providers/docker.box
box: Calculating and comparing box checksum...
==> box: Successfully added box 'generic/rocky9' (v4.1.16) for 'docker'!
Listing available CentOS 8 boxes:
$ vagrant box list
centos/stream8 (libvirt, 20210210.0)
centos/stream8 (virtualbox, 20210210.0)
generic/centos8s (parallels, 4.1.16)
generic/centos8s (vmware_desktop, 4.1.16)
generic/rocky8 (docker, 4.1.16)
generic/rocky9 (docker, 4.1.16)
Step 3: Create Vagrantfile for CentOS 8
Start by creating a Vagrant file.
mkdir -p ~/vagrant/centos8 && cd ~/vagrant/centos8
vim Vagrantfile
Basic Vagrantfile contents looks like this:
- KVM
# -*- mode: ruby -*-
# vi: set ft=ruby :
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'
Vagrant.configure("2") do |config|
##### DEFINE VMS #####
config.vm.define "centos8" do |config|
config.vm.hostname = "centos8"
config.vm.box = "centos/stream8"
config.vm.box_check_update = false
end
config.vm.provider :libvirt do |v|
v.memory = 1024
v.cpus = 2
end
end
- VirtualBox
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/stream8"
config.vm.box_check_update = false
config.vm.hostname = "centos8"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
vb.memory = "2048"
vb.cpus = 2
end
end
For other providers, visit the official Vagrant documentation. Once the file has been created, start the VM by running:
$ vagrant up
Bringing machine 'centos8' up with 'libvirt' provider...
==> centos8: Uploading base box image as volume into libvirt storage...
==> centos8: Creating image (snapshot of base box volume).
==> centos8: Creating domain with the following settings...
==> centos8: -- Name: centos8_centos8
==> centos8: -- Domain type: kvm
==> centos8: -- Cpus: 2
==> centos8: -- Feature: acpi
==> centos8: -- Feature: apic
==> centos8: -- Feature: pae
==> centos8: -- Memory: 1024M
==> centos8: -- Management MAC:
==> centos8: -- Loader:
==> centos8: -- Nvram:
==> centos8: -- Base box: centos/8
==> centos8: -- Storage pool: default
==> centos8: -- Image: /var/home/jkmutai/.local/share/libvirt/images/centos8_centos8.img (11G)
==> centos8: -- Volume Cache: default
==> centos8: -- Kernel:
==> centos8: -- Initrd:
==> centos8: -- Graphics Type: vnc
==> centos8: -- Graphics Port: -1
==> centos8: -- Graphics IP: 127.0.0.1
==> centos8: -- Graphics Password: Not defined
==> centos8: -- Video Type: cirrus
==> centos8: -- Video VRAM: 9216
==> centos8: -- Sound Type:
==> centos8: -- Keymap: en-us
==> centos8: -- TPM Path:
==> centos8: -- INPUT: type=mouse, bus=ps2
==> centos8: Creating shared folders metadata...
==> centos8: Starting domain.
==> centos8: Waiting for domain to get an IP address...
==> centos8: Waiting for SSH to become available...
centos8:
centos8: Vagrant insecure key detected. Vagrant will automatically replace
centos8: this with a newly generated keypair for better security.
centos8:
centos8: Inserting generated public key within guest...
centos8: Removing insecure key from the guest if it's present...
centos8: Key inserted! Disconnecting and reconnecting using new SSH key...
==> centos8: Setting hostname...
==> centos8: Configuring and enabling network interfaces...
centos8: SSH address: 192.168.122.2:22
centos8: SSH username: vagrant
centos8: SSH auth method: private key
==> centos8: Rsyncing folder: /var/home/jkmutai/vagrant/centos8/ => /vagrant
Try ssh:
$ vagrant ssh
[vagrant@centos8 ~]$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
[vagrant@centos8 ~]$ cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)
[vagrant@centos8 ~]$ exit
logout
Connection to 192.168.122.2 closed.
If you want to destroy the VM, use:
$ vagrant destroy
centos8: Are you sure you want to destroy the 'centos8' VM? [y/N] y
==> centos8: Removing domain...
Whenever you make a change to the Vagrantfile, restart the machine for the changes to take effect.
$ vagrant reload
To stop the instance, use:
$ vagrant halt
If you would like to save the current state of the VM while stopping it, use:
$ vagrant suspend
With this, you’ll return to exactly the same state at a later time when VM is started.
Destroy the Vagrant machine when done by running
$ vagrant destroy
More guides:
Best Linux Books for Beginners & Experts
Best CCNA R&S (200-125) Certification Preparation Books