Home Linux How To Add Downloaded .box File To Vagrant In Linux
How To Add Downloaded box File To Vagrant In Linux

How To Add Downloaded .box File To Vagrant In Linux

By sk
544 Views

The Linux distributions are available for download in a range of different formats. The most widely available format is ISO. Apart from ISO, they are also distributed via pre-configured images such as .box for Vagrant, .vbox for virtual box, .vmdk for Vmware, .qcow2 for KVM/openStack, and compressed RAW etc. So you can quickly grab the image of your choice and run it using the respective virtualization application. This brief guide explains how to add downloaded .box file to Vagrant in Linux operating system.

For those who don't know yet, Vagrant is an open source software for building and maintaining virtual software development environments. It provides a clean, easy to configure, reproducible, and portable development environment. The .box is a format and an extension for Vagrant environments. The vagrant boxes are just the base images. Nowadays, many OSes are available in .box image file format.

Add Downloaded .box File To Vagrant In Linux

Today I wanted to try the newly released Fedora 33 OS on my system. Instead of manually downloading and installing it from the ISO file, I've decided to grab the ready-made Fedora 33 Vagrant box and run it for a couple days in VirtualBox to see how it works. So I went to Fedora official download page and downloaded the .box file for Fedora 33. And then I installed Vagrant in my Ubuntu desktop as described in the following guide:

After installing Vagrant, I went to the location where I downloaded the .box file and add it to Vagrant using command:

$ vagrant box add --name fedora33 Fedora-Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box

Here, fedora33 is the name that I assigned to the virtual machine and the "Fedora-Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box" is the .box file that I downloaded from the Fedora download page.

Sample output:

==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'fedora33' (v0) for provider: 
    box: Unpacking necessary files from: file:///home/sk/Vagrant/Fedora-Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box
==> box: Successfully added box 'fedora33' (v0) for 'virtualbox'!
Add Downloaded .box File To Vagrant In Linux
Add Downloaded .box File To Vagrant In Linux

The .box file is added for the provider. In my case, the provider is Oracle VirtualBox.

Let us verify it by listing the available Vagrant boxes as shown below:

$ vagrant box list 
fedora33 (virtualbox, 0)
List Vagrant boxes
List Vagrant boxes

Next initialize the Vagrant box using command:

$ vagrant init fedora33

Sample output:

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Now start the Fedora virtual machine by running the following command:

$ vagrant up

Sample output:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'fedora33'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: Vagrant_default_1606997309282_57379
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    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: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 6.0.0 r127566
    default: VirtualBox Version: 6.1
==> default: Rsyncing folder: /home/sk/Vagrant/ => /vagrant
Start Fedora vagrant box from commandline
Start Fedora vagrant box from commandline

The Fedora 33 vagrant box is up and running under VirtualBox.

Open the Virtualbox manager and check if it is running:

Fedora vagrant box is running under VirtualBox
Fedora vagrant box is running under VirtualBox

You can also check the status of the vagrant box from the Terminal using this command:

$ vagrant status

Sample output:

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`.

Yes, the VM is running!

Connect and access the running VM via ssh as shown below:

$ vagrant ssh

Start using the VM:

Last login: Thu Dec  3 12:13:42 2020
[[email protected] ~]$ cat /etc/redhat-release 
Fedora release 33 (Thirty Three)
[[email protected] ~]$ 

Please note that I downloaded the Virtualbox box image, so the Fedora VM starts automatically in Virtualbox. If you have downloaded the libvirt/kvm image, it will then run under kvm hypervisor.

Well, that's all for now. You learned now how to add downloaded .box file to vagrant in Linux. And also you learned how to start the Vagrant box and how to connect to access it from commandline.

To know more about Vagrant usage, refer the following guide:

Hope this helps.

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More