December 21, 2014

Vagrant – Provisioning your first VM

1. Open up git-bash terminal and create a folder that will contain all your personal vagrant files, in my case I have created a top level folder called “vagrant”:


You can find all my latest posts on medium.
mkdir c:\vagrant\centos

Note: I also create the centos directory in order to keep all my vagrant vms organised.

2. cd into this directory.

3. By default vagrant is designed to automatically download OS images from vagrantcloud. This website is a repository that host hundreds of OS images. The cool thing about this is that it is free to use! On VagrantCloud, search for an image that you are interested in (make sure you pick one that is compatible with your hypervisor, which in my case is virtualbox). In this example, I have searched for centos and will go with the following:

Note, vagrant cloud isn’t the only place to download vagrant boxes, you can also use:

– (official puppetlab boxes)

4. Make a note of the name, which in this case is “puppetlabs/centos-6.5-64-puppet”

5. Now tell vagrant you want to use this image by running the following command:

PS C:\vagrant\centos> vagrant init puppetlabs/centos-6.5-64-puppet

6. You should get the following output:

PS C:\vagrant\centos> vagrant init puppetlabs/centos-6.5-64-puppet
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
`` for more information on using Vagrant.
PS C:\vagrant\centos>

Confirm the existence of the above file and take a look at it’s content. We will cover a lot more about this file later.

7. While in the directory that contains vagrantfile, run the following (and then wait 10-20 mins):

vagrant up

This should end up downloading an in OS image to:

C:\Users\{username}\VirtualBox VMs

You should get an output like this:






9. Now we can log into the vm from our git bash terminal using:

vagrant ssh           

This is helpful because we don’t know the “vagrant” user’s password.

If you did know what the password is, then you can use an ssh client (e.g. putty) to connect to the vm.

10. We can then switch to root like this:

sudo su -

11. Once you have finished with your vm, you can gracefully shutdown your vm using:

vagrant halt

12. Also you can destroy your vm like this if you no longer need it:

vagrant destroy

The particular image we are using above doesn’t come pre-installed with the gnome gui interface. This means that you can only use this vm in command line mode. However you can reconfigure it run in gui mode which we’ll cover in the next lesson. by first isntalling gnome:

yum -y groupinstall "Desktop" "Desktop Platform" "X Window System" "Fonts"

Then you can switch to the gui mode using the telinit command.

You can also change the default runlevel by updating the following file:

vi /etc/inittab