[Infrastructure as Code (IaC) - Vagrant] FAQs about using Vagrant for building and managing virtual machine environments

FAQs about using Vagrant for building and managing virtual machine environments

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.

There are some FAQs about Vagrant.

Vagrant Up

Error: Unknown repo: ‘C*-base’ on CentOS 8

There is a error occure when run vagrant up command first time.

1
2
3
4
5
6
7
8
9
10
11
12
$ vagrant up
==> default: Attempting graceful shutdown of VM
...
Error: Unknown repo: 'C*-base'
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

yum install -y kernel-devel-`uname -r` --enablerepo=C*-base --enablerepo=C*-updates

Stderr from the command:

Error: Unknown repo: 'C*-base'

Check vm status with vagrant status command.

1
2
3
4
5
6
7
8
9
$ vagrant status
Current machine states:

default running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

Then, ssh into vm with vagrant ssh command.

1
2
3
4
$ vagrant ssh
[vagrant@localhost ~]$
[vagrant@localhost ~]$ sudo yum update -y
[vagrant@localhost ~]$ exit

Last, exit to host to run vagrant reload.

1
2
3
4
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
...
==> default: flag to force provisioning. Provisioners marked to run always will still run.

OK, the vm vagrant up sucessfully.

/sbin/mount.vboxsf: mounting failed with the error: No such device on ubuntu/eoan64

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vagrant up                                                                                                       22.92 Dur  17:32:24
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/eoan64' could not be found. Attempting to find and install...
...
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

First, install vagrant-vbguest plugin.

1
2
3
4
5
$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching: micromachine-3.0.0.gem (100%)
Fetching: vagrant-vbguest-0.23.0.gem (100%)
Installed the plugin 'vagrant-vbguest (0.23.0)'!

Then, run vagrant vbguest command.

1
2
3
4
$ vagrant vbguest
[default] No Virtualbox Guest Additions installation found.
...
Unmounting Virtualbox Guest Additions ISO from: /mnt

Last, exit to host to run vagrant reload.

1
2
3
4
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
...
==> default: flag to force provisioning. Provisioners marked to run always will still run.

OK, the vm vagrant up sucessfully.

Stderr: VBoxManage: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)

1
2
3
4
5
6
7
8
9
10
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "4db5d7b1-1321-4951-81ef-24253d8407e8", "--type", "headless"]

Stderr: VBoxManage: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

Reeboot host then keep pressing DEL key when poweron) enter into BIOS, and enable CPU processor VT-x support.

1
2
3
4
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
...
==> default: flag to force provisioning. Provisioners marked to run always will still run.

OK, the vm vagrant up sucessfully.

Disable default /vagrant synced folder

In the Vagrantfile:

1
2
3
4
Vagrant.configure('2') do |config|
config.vm.synced_folder '.', '/vagrant', disabled: true
# ...
end

References

[1] Vagrant by HashiCorp - https://www.vagrantup.com/