Saturday, November 4, 2017

Making vagrant and virtualbox on Ubuntu 16.04

MY ENVIRONMENT

$ grep RELEASE /etc/lsb-release
DISTRIB_RELEASE=16.04
$
$ vagrant --version
Vagrant 2.0.1
$
$ VBoxManage -v
5.0.40_Ubuntur115130
$ vagrant plugin list
vagrant-hostmanager (1.8.7)
vagrant-share (1.1.9, system)
vagrant-vbguest (0.15.0)

$ vagrant plugin list
vagrant-hostmanager (1.8.7)
vagrant-share (1.1.9, system)
vagrant-vbguest (0.15.0)


STEPS TO INSTALL VITUALBOX AND VAGRANT ON UBUNTU 16.04



VIRTUALBOX

sudo apt-get install virutalbox virtualbox-dkms linux-headers-generic virtualbox-guest-x11
VBoxManage --version # if this complains about device /dev/vboxdrv, do following
sudo dpkg-reconfigure virtualbox-dkms
sudo dpkg-reconfigure virtualbox
sudo modprobe vboxdrv
sudo modprobe vboxnetctl
VBoxManage --version
sudo modprobe vboxnetadp # sudo modprobe vboxnetadp
sudo modprobe vboxnetadp #  sudo modprobe vboxnetadp


VAGRANT

sudo apt-get install vagrant
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-hostmanager
sudo apt-get -y install dkms build-essential \
  linux-headers-$(uname -r) virtualbox-guest-additions-iso
apt-get install linux-headers-virtual


ADD A BOX IN VAGRANT
Add a box and start it as mention here 

vagrant status
vagrant ssh


SAMPLE CONFIG FILE TO START 2 VAGRANT BOXES

#Sample Vagrantfile file to start 2 ubuntu boxes
https://www.vagrantup.com/docs/multi-machine/  multi machine configuration reference
# only first machin in below config has been set to start by default

Vagrant.configure("2") do |config|

    config.vm.provider "virtualbox"
    config.vm.network "public_network", bridge: "wlp6s0"

    config.vm.provision 'shell', path: 'install_docker.sh', run: 'always'

   config.vm.define "vm1", primary: true, autostart: true do | vm1 |
      vm1.vm.box = "minimal/xenial64"
      vm1.vm.hostname = 'vm1'

      vm1.vm.provider :virtualbox do |v|
        v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
        v.customize ["modifyvm", :id, "--memory", 1024]
        v.customize ["modifyvm", :id, "--name", "vm1"]
      end
   end

   config.vm.define "vm2", autostart: false do | vm2 |
      vm2.vm.box = "minimal/xenial64"
      vm2.vm.hostname = 'vm2'

      vm2.vm.provider :virtualbox do |v|
        v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
        v.customize ["modifyvm", :id, "--memory", 1024]
        v.customize ["modifyvm", :id, "--name", "vm2"]
      end
    end
end



References:
https://gist.github.com/larsar/1687725
https://github.com/rekibnikufesin