Utilizing Vagrant with VirtualBox on Debian 12

Utilizing Vagrant with VirtualBox on Debian 12

10:09, 21.02.2024

Article Content
arrow

  • Practical Applications of Vagrant
  • Employing Vagrant in Conjunction with VirtualBox on Debian 12
  • 1. Installing VirtualBox
  • 2. Setting Up Vagrant
  • 3. Implementing Vagrant
  • Accessing Virtual Machines
  • Using Vagrant with KVM
  • 1. Setting Up KVM on Debian 12
  • 2. Installing the vagrant-libvirt Plugin
  • 3. Employing Vagrant via the Libvirt KVM Provider
  • Final Thoughts

A perfect development environment can be created with Vagrant. It creates automation and ideal workflow while at the same time, it is possible to lessen the time spent on setup. Based on our practical experience, we can assure you that Vagrant except for the already mentioned benefits, also improves the level of production and development.

Practical Applications of Vagrant

To reach a certain level of flexibility and higher performance, Vagrant creates an ideal working environment. This environment is reproducible, easy to configure, and rather portable. So, that team can get access to a single consistent process with industry-standard technologies.

Vagrant functions due to such giants as KVM, Docker, VirtualBox, VMware, and other providers. With the help of Puppet, Chef, or shell scripts, the virtual machine can be configured, and automatically installed.

Vagrant use cases:

  • Isolation of development environments.
  • IaC testing.
  • Distributed systems testing.
  • Web app development.
  • Continuous deployment and continuous integration.
  • Collaboration of teams.
  • Cloud testing and development.

In this article, we will try to share our practical knowledge in the field with detailed instructions on how to use Vagrant with KVM and VirtualBox. These are 2 major providers for Vagrant. After reviewing a couple of instructions, you could easily determine the best suit for you.

Employing Vagrant in Conjunction with VirtualBox on Debian 12

Before discussing the actual process of installation on Debian 12, let’s at first get some theoretical information about VirtualBox. To begin with, it is an open-source and free hypervisor that helps to run a VM (virtual machine) on the host machine without actually influencing the host operating system. The OS is called after the installation of VirtualBox as “Host Operating system”. The OS that runs under VirtualBox virtual machine is called “Guest”.

The major benefit of VirtualBox is the exceedance of the technical capabilities of any machine. It’s possible to run several OSs in various VMs at the same time. For instance, users can try and run any Linux and Windows system simultaneously on the MacBook without the need to compromise the system config and apps.

With the help of this tool, it is possible to operate as many VMs as it is possible based on the discs and memory space. For personal usage, it is possible to use a free version, but commercial clients are recommended to get a license for business usage. The price may vary depending on the number of users and the period of the license functioning.       

Now let’s continue with more practical processes. To install Vagrant on Debian 12 with VirtualBox, just follow a couple of simple steps.

1. Installing VirtualBox

Before Vagrant installation, you should install the provider in this case VirtualBox. Once you have completed this step, you can start the next one.

2. Setting Up Vagrant

Vagrant installation starts from the following command:

sudo apt -y install apt-transport-https ca-certificates curl software-properties-common

Once that is done, you can import GPG keys by typing the following:

 wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg

At this point, the official APT repository is on your machine and there is one more step prior to the actual installation of Vagrant.

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list

The installation of Vagrant is done by a simple command:

sudo apt update
sudo apt install vagrant

The last thing to do is to verify the version by:

$ vagrant --version

3. Implementing Vagrant

At the stage of implementation, we decided to share a couple of commands with the help of which you can get a perfect development environment. To begin with, you will need to create a file where you will have the Vagrant file.

mkdir ~/vagrant-project

The following thing is the choice of the box to utilize on your system in order to establish a new Vagrant file. To get this box, you will need to visit an official site and get one. Here we will show what the process looks like with generic/ubuntu2204.

For the file creation use the next command:

cd ~/vagrant-project
vagrant init generic/ubuntu2204

Once everything is completed, you will see a notification that the file was placed in the directory and where to get more inform about the usage of Vagrant.

After the creation of the file, use any text editor for some modifications on the Debian system.

sudo vim Vagrantfile

For the creation of the set up use the following:

vagrant up

Accessing Virtual Machines

The access and connection to the operating virtual machines are available via SSH. Start with such command:

vagrant ssh

To show the status of virtual machines you will need the:

 vagrant status

To show the status of all virtual environments use:

vagrant global-status

For the shut down you will need the following command:

$ vagrant halt

For the hibernation of virtual machines use:

 $ vagrant suspend

The restoration of virtual machines to their original state looks like this:

$ vagrant destroy

Using Vagrant with KVM

Now you understand the whole process of using Vagrant with VirtualBox, let’s talk about one more possible scenario.

As it is already clear, Vagrant isn’t stand-alone, it is used in combination with several other providers such as Docker, VirtualBox (already discussed), KVM, and VMWare. VirtualBox is considered to be a default provider, so let’s discuss one more great option – KVM.

This open-source technology is specifically designed for Linux users. With this virtualization technology, it is possible to run multiple and isolated environments. KVM is a part of Linux code and that means users will be getting new advancements, features, and fixes without the need for additional engineering.

Because KVM is a part of the Linux kernel, such components as a process scheduler, memory manager, device driver, network stack, and more are already there. Each virtual machine is implemented as a standard process with dedicated hardware, with the usage of a standard scheduler, memory, CPUs, and discs.    

The major benefits of this tool are higher performance, scalability, security, and of course cost-effectiveness. Now when you have some basic understanding, let’s discuss the actual process of installation of KVM. This is a relatively simple process and won’t require much time from the users.   

1. Setting Up KVM on Debian 12

Start with the installation of KVM on your machine. Then add the user with the following command:

sudo usermod -a -G libvirt <realusername>

When the provider is installed, you can continue with the following step.

2. Installing the vagrant-libvirt Plugin

The vagrant-libvirt plugin should be installed before the usage of KVM. This plugin is necessary for machine provisioning and control with Vibvirt.

To start the process, you will first need dependencies:

sudo apt install build-essential

The following command is needed for the actual installation of the plugin:

vagrant plugin install vagrant-libvirt

Also, it is important to have agrant-mutate plugin, that is responsible for changing boxes and working with different providers. So, the following command should be used:

vagrant plugin install vagrant-mutate

3. Employing Vagrant via the Libvirt KVM Provider

First, it is important to determine whether the chosen Vagrant box supports the libvirt provider. This can be done in the cloud repository. Just select “libvirt” to understand what boxes are supported.

Here in this part, we will use CentOS 9 box.

Start with setting up the environment with the following commands:

mkdir my_vagrant
cd my_vagrant
vagrant init generic/centos9s

Then launch the machine with the following command:

vagrant up --provider=libvirt

With this specific command, the virtual machine is running with libvirt KVM. So, the KVM serves as the default option. The output of these commands, usually includes a variety of default characteristics such as CPUs, name, feature, type of domain, description, memory, base box, and others.

For the indefinite usage of this specific default provider, you can type the following command:

export VAGRANT_DEFAULT_PROVIDER=libvirt

For confirmation use such a program as Virt-manager, this is a perfect management GUI program.

Now let’s proceed to a couple of additional helpful commands:

  • For the virtual machine restart use:
vagrant reload
  • For listing boxes use:
vagrant box list
  • To get information on whether the box is outdated, type:
cd my_vagrants/
vagrant box outdated
  • For the updating of the boxes use:
vagrant box update
  • To download boxes use the following:
vagrant box add <box>
  • To check the size of the boxes use the:
ls ~/.vagrant.d/boxes

These are all the basic commands that a user should have in order to install and manage the system successfully. Other things are usually optional.

Final Thoughts

Here in this article, we have mentioned the most important steps that users should follow in order to use Vagrant in KVM and VirtualBox. Hope that our practical knowledge in this field will help you to understand a process a little bit more and you will try to repeat this guide’s instructions. The combination of KVM/VirtualBox and Vagrant creates an ideal environment for testing and development. With the help of these technologies, it is possible to boost efficiency and create a smooth integration for software development.

views 7m, 30s
views 2
Share

Was this article helpful to you?

VPS popular offers

Other articles on this topic

cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.