Vagrant

Trying Linux as a virtual machine with Vagrant

In order to create a stable learning environment, we’re going to have everyone use a Devop tool called Vagrant. Vagrant is typically used to help assist both developers and system engineers in ensuring that their application and system deployments work predictably. For our purposes we’re going to use it as an easy way for new people to get to a Linux prompt quickly with no fear of breaking their system.

Vagrant basically interfaces with hypervisors such as VirtualBox with a unified command line interface. This makes it portable between Mac, Windows and even Linux! Vagrant itself is just a collection of ruby scripts while Virtualbox does all the virtual machine magic.

We will go in more depth with how to install Linux manually, but for now we’ve done all the hard work and have create pre-made Linux images.

Installing Virtualbox

VirtualBox is a free and open source virtual machine manager that you can install on a variety of operating system platforms such as Mac and Windows.

  1. Go to the VirtualBox download page and download the latest copy of VirtualBox.
  2. Go through the installer and use the default settings when prompted.
  3. Once completed, see if you can open up the VirtualBox Manager
  4. If it asks you to download the latest extensions, go ahead and do that.

Installing Vagrant

Vagrant is a free and open source tool used to build complete devops environments.

  1. Go to the Vagrant download page and choose the newest version available.
  2. Choose all the defaults during the install if it asks you any questions

Testing Vagrant

  1. If you’re on a Mac, open up the Terminal. If you’re on windows, open up a DOS prompt (cmd.exe).
  2. Type: vagrant status
  3. If there are no errors then Vagrant was installed correctly!

Cloning the Vagrant Repo

We keep all of our vagrant configuration in a git version controlled repository. If you don’t have git installed, please go download git and install it.

Once you have downloaded and installed git, go to a folder where you want to keep the repository and type the following:

git clone https://github.com/DevOpsBootcamp/devopsbootcamp-vagrant.git

If installing git is too difficult, you can also download a zip file containing the repository. We will teach you more about git later in the year, so don’t worry!

Using Vagrant

Now that we have the entire environment working, lets get to playing with Linux! Open the terminal and get to the directory where the devopsbootcamp-vagrant repo is at. You can run the following commands:

# Start the VM
vagrant up

# SSH into the VM
vagrant ssh

# Stop and halt the VM
vagrant halt

# Destroy and remove the VM
vagrant destroy

Also check out the Vagrant Documentation for more information. You can also always type -h to find out more information about a command.

Troubleshooting

Depending on how your laptop or computer is confused in the BIOS, you may or may not run into issues getting Vagrant and VirtualBox to work properly.

Booting the VM takes forever and never completes

The most common problem is when you type vagrant up the system just waits and waits and never finishes the boot process. The most likely cause is because your system doesn’t have hardware virtualization enabled in the BIOS. You can either enable the feature or you can disable the requirement in the Vagrantfile.

1. Enabling Hardware Virtualization

Reboot your machine and press the appropriate buttons to get into the BIOS or Setup screen. This is usually done by hitting a combination of the escape or function keys.

Once you get into the BIOS, find a screen that has some options for the CPU. Each BIOS is different but you are basically trying to find a feature called Hardware Virtualization. Once you find it, go ahead and enable it and reboot your system.

2. Disabling HW Virtualization in Vagrant

Open the Vagrantfile with your favorite editor of choice. Find the line that says hwvirtex and remove the # from the front of the line. Now run vagrant destroy -f and then vagrant up again. This should boot the VM properly now.