Create_Ubuntu_VirtualMachine_using_Vagrant

 ​​ ​​ ​​ ​​​​ Create any Virtual Machine using Vagrant​​ 

What you will Learn:

  • What is Vagrant?

  • Download vagrant

  • Install Vagrant

  • Copy VM image from vagrantbox.es

  • Initialize vagrant​​ 

  • vagrant up

  • vagrant ssh

  • vagrant halt

  • Remove vagrant machine

What is Vagrant?

Vagrant is IAAC (Infrastructure as a code) tool. Using Vagrant, we can create a Virtual machine without manually​​ downloading the iso image of an operating system (ubuntu, centos, redhat, windows etc..)​​ 

Download vagrant

https://www.vagrantup.com/downloads​​ 

Download vagrant package for windows

Install Vagrant

After machine restart, open the​​ windows powershell (since you can​​ execute most​​ linux commands over here)​​ and execute the below command to ensure that vagrant is installed successfully

Make​​ any directory, see below

cd to​​ the above directory

Copy VM image from vagrantbox.es

http://www.vagrantbox.es/​​ 

Click ‘Copy’ to copy url of any desired VM image (example, redhat linux image seen below)

Launch the above url and note down the name of virtual box, see below

Initialize vagrant​​ 

Execute​​ vagrant init <box-name> <location url>​​ to initiate vagrant

vagrant up

Execute​​ vagrant up​​ command to launch the VM machine



Execute​​ vagrant box list​​ command to ensure that VM​​ machine is running

Now open oracle virtual box, notice below that VM is running

username of this machine:​​ root
password:​​ vagrant

IMPORTANT: Do NOT click ‘Show’. If by mistake you have clicked it, enter username and password. If you are not able to come out of the redhat window machine, execute​​ reboot​​ command. After sometime you will be able to come out.​​ 

vagrant​​ ssh

From our windows powershell, we​​ can connect the​​ redhat​​ virtual​​ machine using​​ vagrant ssh

Notice above the machine name has changed to vagrant@packer-rhel7

To​​ exit from ssh, execute​​ exit​​ command

vagrant halt

vagrant halt​​ will​​ gracefully shutdown​​ VM

To bring it back up​​ vagrant up.​​ If you get any error, restart your machine and again try​​ vagrant up

Remove vagrant machine

You can execute​​ vagrant box remove <box​​ name>​​ to remove the box.

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 10th Nov 2024