Most coders is large companies are facing the same situation: We develop for Linux servers, but we are running on Windows or MacOS boxes.
Things are working mostly the same at best, at worst, it’s broken.
We need a solution and Vagrant is a quick way to provision a Linux VM on your local desktop.
This will be a series of posts starting with these 4 topics:
For those who don’t know, Vagrant by HashiCorp is a VM provisioning tool targeted at spawning software development boxes. I’ve used Vagrant for the last 3-4 years to quickly get a Linux development VM running on my Windows Desktop.
Vagrant support various VM/Hypervisor platforms like libvirt/KVM (Linux), MS HyperV (Win), Oracle VM VirtualBox (both), VMWare
Vagrant primary file is a VagrantFile which describes how the VM must be configured. It goes from which OS to use, how many memory/cpu to use, disk size, shared drive between Host and Guest, and much more.
There are couple of reasons to use this setup to configure a Linux development environment:
There are couple of choices of virtualization platform:
In most cases, Virtualbox is the best solution due to it’s Guest Additions integration and USB2.0/3.0 support.
In short, why others are lesser capable IMHO:
The aim of this first part is to get a prompt on the Guest OS of choice, in this case Arch, but it could be any other Linuxes.
To make things fast, we need to use Virtualization implemented using Hardware virtualization capabilities of your PC. In theory, software based virtualization could work, but it’s far from being usable if you want to run X and a window manager (ie: way too slow).
Most PC these days support Hardware virtualization (even my old x220 from 2012), but it may not be enabled.
You can enable virtualization by going to your BIOS and enabling hardware virtualization. It can have various names, VT-x, Virtualization, or something similar. If not enabled, Virtualbox wont be able to give you hardware virtualization. If this is on your work PC, you may need your IT department to enable this if they password protected your BIOS.
Install Oracle VM VirtualBox. In my case, I install the VirtualBox for Windows Host.
You can optionally install the Oracle VM VirtualBox Extension Pack which gives you host bridging with USB 2.0/3.0 devices. This is required if you want to pass-through a USB 2.0 or 3.0 device connected to your host directly to your VM.
Vagrant requires newer version of Powershell to be able to install. Windows 10 has the right version and I’ll assume you are on Windows 10 since other versions are EOL.
Head over Vagrant by HashiCorp and download vagrant.
Installation should be trivial.
Time for box selection. A vagrant box is a pre-configured bare VM that you can download and start. It’s the VM equivalent to a docker image.
Head over to Discover Vagrant Boxes - Vagrant Cloud page to search for boxes.
Like any community contributed software, take special care to select a box you can trust.
Disclaimer: The box I’m going to select here is based on my own evaluation. I’m not flawless, and also things could change over time (ie: what is safe today may not be in the future). You should do your own assessment. You’ve been warned, don’t blame me if this breaks your system.
I would recommend to take boxes from reputable sources, or build you own (which is way beyond the scope of this series).
To test the setup, I’ll just select a small VM for alpine: generic/alpine38
Vagrant is configured in a similar way to docker, with a VagrantFile used to “build” your VM.
To create the simplest VagrantFile for a new setup, open a cmd prompt or powershell and type:
BTW, Vagrant is written in ruby and the VagrantFile is a ruby file.
Here is the equivalent of your Vagrantfile:
Now that your configuration file is created, run the following command in a powershell in the created directory:
In the end of the process, you should have a VM provisioned and started.
From the same vagrant folder, you can connect to your box using ssh with keys generated for your:
You are now connected to your box using SSH.
You can now disconnect from SSH (ie: exit or ^d)
You may have noted that vagrant mounted /vagrant to your local vagrant folder. In your box, you can share files from that folder. There are ways to mount additional folders and we’ll go over this in a later post.
Another useful command, is you can tell vagrant to shutdown the VM using:
Since this is just a test box, you may want to delete the VM:
As you can see, Vagrant helps you setup a minimal Linux OS running in a VM in just a few steps.
This is way more efficient than installing from ISO and going through the installation.
Coming next will be part 2, addressing basic X setup as well as tweaking the VM configuration using the same VagrantFile.
This is day 3 of my #100DaysToOffload. You can read more about the challenge here: https://100daystooffload.com.