Added additional information relating to a workaround for Ubutu and
vagrant. Also converted from dos to unix mode.
Change-Id: If5e22976df414a7c731738901db8c02308284e75
diff --git a/BuildingVolthaUsingVagrantOnKVM.md b/BuildingVolthaUsingVagrantOnKVM.md
index 8adf3c3..b982a62 100755
--- a/BuildingVolthaUsingVagrantOnKVM.md
+++ b/BuildingVolthaUsingVagrantOnKVM.md
@@ -1,125 +1,153 @@
-# Building a vOLT-HA Virtual Machine Using Vagrant on QEMU/KVM
-***
-**++Table of Contents++**
-
-[TOC]
-***
-##Bare Metal Setup
-Start with an installation of Ubuntu16.04LTS on a bare metal server that is capable of virtualization. How to determine this is beyond the scope of this document. When installing the image ensure that both "OpenSSH server" and "Virtualization Machine Host" are chosen in addition to the default "standard system utilities". Once the installation is complete, login to the box and type ``virsh list``. If this doesnt work then you'll need to troubleshoot the installation. If it works, then proceed to the next section.
-
-##Create the base ubuntu/xenial box
- Though there are some flavors of ubuntu boxes available but they usually have additional features installed or missing so it's best to just create the image from the ubuntu installation iso image.
-
- ```
-
- voltha> wget http://releases.ubuntu.com/xenial/ubuntu-16.04.2-server-amd64.iso
- voltha> echo "virt-install -n Ubuntu16.04 -r 1024 --vcpus=2 --disk size=50 -c ubuntu-16.04.2-server-amd64.iso --accelerate --network network=default,model=virtio --connect=qemu:///system --vnc --noautoconsole -v" > Ubuntu16.04Vm
- voltha> . Ubuntu16.04Vm
- voltha> virt-manager
-```
-Once the virt manager opens, open the console of the Ubuntu16.04 VM and follow the installation process.
-When promprompted use the hostname ``voltha``. Also when prompted you should create one user ``Vagrant Vagrant`` and use the offered up userid of ``vagrant``. When prompted for the password of the vagrant user, use ``vagrant``. When asked if a weak password should be used, select yes. Don't encrypt the home directory. Select the OpenSSH server when prompted for packages to install.
-Once the installation is complete, run the VM and log in as vagrant password vagrant and install the default vagrant key (this can be done one of two ways, through virt-manager and the console or by uing ssh from the hypervisor host, the virt-manager method is shown below):
-```
-vagrant@voltha$ mkdir -p /home/vagrant/.ssh
-vagrant@voltha$ chmod 0700 /home/vagrant/.ssh
-vagrant@voltha$ wget --no-check-certificate \
- https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
- -O /home/vagrant/.ssh/authorized_keys
-vagrant@voltha$ chmod 0600 /home/vagrant/.ssh/authorized_keys
-vagrant@voltha$ chown -R vagrant /home/vagrant/.ssh
-```
-Also create a .ssh directory for the root user:
-```
-vagrant@voltha$ sudo mkdir /root/.ssh
-```
-Add a vagrant file to /etc/sudoers.d/vagrant with the following:
-```
-vagrant@voltha$ echo "vagrant ALL=(ALL) NOPASSWD:ALL" > tmp.sudo
-vagrant@voltha$ sudo chown root.root tmp.sudo
-vagrant@voltha$ sudo mv tmp.sudo /etc/sudoers.d/vagrant
-```
-
-That's all that's required to prepare the VM imsage to be vagrant enabled. Before proceeding to the next step, shut down the vm.
-
-```
-vagrant@voltha$ sudo telinit 0
-```
-
-## Install and configure vagrant
-Vagrant comes with the Ubuntu 16.04 but it doesn't work with kvm. Downloading and installing the version from hashicorp solves the problem.
-```
-voltha> wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.3_x86_64.deb
-voltha> sudo dpkg -i vagrant_1.9.3_x86_64.deb
-voltha> vagrant plugin install vagrant-cachier
-voltha> sudo apt-get install libvirt-dev
-voltha> vagrant plugin install vagrant-libvirt
-```
-## Create the default vagrant box
-
-When doing this, be careful that you're not in a directory where a Vagrantfile already exists or you'll trash it. It is recommended that a temporary directory is created to perform these actions and then removed once the new box has been added to vagrant.
-```
-voltha> cp /var/lib/libvirt/images/Ubuntu16.04.qcow2 box.img
-voltha> echo '{
-"provider" : "libvirt",
-"format" : "qcow2",
-"virtual_size" : 50
-}' > metadata.json
-voltha> cat <<HERE > Vagrantfile
-Vagrant.configure("2") do |config|
- config.vm.provider :libvirt do |libvirt|
- libvirt.driver = "kvm"
- libvirt.host = 'localhost'
- libvirt.uri = 'qemu:///system'
- end
-config.vm.define "new" do |custombox|
- custombox.vm.box = "custombox"
- custombox.vm.provider :libvirt do |test|
- test.memory = 1024
- test.cpus = 1
- end
- end
-end
-HERE
-voltha> tar czvf ubuntu1604.box ./metadata.json ./Vagrantfile ./box.img
-voltha> vagrant box add --name ubuntu1604 ubuntu1604.box
-```
-##Download the voltha tree
-The voltha tree contains the Vagrant files required to build a multitude of VMs required to both run, test, and also to deploy voltha. The easiest approach is to download the entire tree rather than trying to extract the specific ``Vagrantfile(s)`` required.
-
-Create a .gitconfig file using your favorite editor and add the following:
-```
-# This is Git's per-user configuration file.
-[user]
- name = Your Name
- email = your.email@your.organization.com
-[color]
- ui = auto
-[review "https://gerrit.opencord.org/"]
- username=yourusername
-[push]
- default = simple
-
-```
-
-Now you can install the repo command and pull the voltha repo.
-```
-voltha> sudo apt-get install repo
-voltha> mkdir cord
-voltha> cd cord
-voltha> repo init -u https://gerrit.opencord.org/manifest -g voltha
-voltha> repo sync
-```
-
-## Run vagrant to Create a Voltha VM
-First create the voltah VM using vagrant.
-```
-voltha> cd cord/incubator/voltha
-voltha> vagrant up
-```
-Finally, log into the vm using vagrant.
-```
-voltha> vagrant ssh
-```
-
-That's it! Enjoy voltha running in QEMU/KVM virtual machines.
\ No newline at end of file
+# Building a vOLT-HA Virtual Machine Using Vagrant on QEMU/KVM
+***
+**++Table of Contents++**
+
+[TOC]
+***
+##Bare Metal Setup
+Start with an installation of Ubuntu16.04LTS on a bare metal server that is capable of virtualization. How to determine this is beyond the scope of this document. When installing the image ensure that both "OpenSSH server" and "Virtualization Machine Host" are chosen in addition to the default "standard system utilities". Once the installation is complete, login to the box and type ``virsh list``. If this doesnt work then you'll need to troubleshoot the installation. If it works, then proceed to the next section.
+
+##Create the base ubuntu/xenial box
+ Though there are some flavors of ubuntu boxes available but they usually have additional features installed or missing so it's best to just create the image from the ubuntu installation iso image.
+
+ ```
+
+ voltha> wget http://releases.ubuntu.com/xenial/ubuntu-16.04.2-server-amd64.iso
+ voltha> echo "virt-install -n Ubuntu16.04 -r 1024 --vcpus=2 --disk size=50 -c ubuntu-16.04.2-server-amd64.iso --accelerate --network network=default,model=virtio --connect=qemu:///system --vnc --noautoconsole -v" > Ubuntu16.04Vm
+ voltha> . Ubuntu16.04Vm
+ voltha> virt-manager
+```
+Once the virt manager opens, open the console of the Ubuntu16.04 VM and follow the installation process.
+When promprompted use the hostname ``voltha``. Also when prompted you should create one user ``Vagrant Vagrant`` and use the offered up userid of ``vagrant``. When prompted for the password of the vagrant user, use ``vagrant``. When asked if a weak password should be used, select yes. Don't encrypt the home directory. Select the OpenSSH server when prompted for packages to install.
+Once the installation is complete, run the VM and log in as vagrant password vagrant and install the default vagrant key (this can be done one of two ways, through virt-manager and the console or by uing ssh from the hypervisor host, the virt-manager method is shown below):
+```
+vagrant@voltha$ mkdir -p /home/vagrant/.ssh
+vagrant@voltha$ chmod 0700 /home/vagrant/.ssh
+vagrant@voltha$ wget --no-check-certificate \
+ https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
+ -O /home/vagrant/.ssh/authorized_keys
+vagrant@voltha$ chmod 0600 /home/vagrant/.ssh/authorized_keys
+vagrant@voltha$ chown -R vagrant /home/vagrant/.ssh
+```
+Also create a .ssh directory for the root user:
+```
+vagrant@voltha$ sudo mkdir /root/.ssh
+```
+Add a vagrant file to /etc/sudoers.d/vagrant with the following:
+```
+vagrant@voltha$ echo "vagrant ALL=(ALL) NOPASSWD:ALL" > tmp.sudo
+vagrant@voltha$ sudo chown root.root tmp.sudo
+vagrant@voltha$ sudo mv tmp.sudo /etc/sudoers.d/vagrant
+```
+
+That's all that's required to prepare the VM imsage to be vagrant enabled. Before proceeding to the next step, shut down the vm.
+
+```
+vagrant@voltha$ sudo telinit 0
+```
+
+## Install and configure vagrant
+Vagrant comes with the Ubuntu 16.04 but it doesn't work with kvm. Downloading and installing the version from hashicorp solves the problem.
+```
+voltha> wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.3_x86_64.deb
+voltha> sudo dpkg -i vagrant_1.9.3_x86_64.deb
+voltha> vagrant plugin install vagrant-cachier
+voltha> sudo apt-get install libvirt-dev
+voltha> vagrant plugin install vagrant-libvirt
+```
+## Create the default vagrant box
+
+When doing this, be careful that you're not in a directory where a Vagrantfile already exists or you'll trash it. It is recommended that a temporary directory is created to perform these actions and then removed once the new box has been added to vagrant.
+```
+voltha> cp /var/lib/libvirt/images/Ubuntu16.04.qcow2 box.img
+voltha> echo '{
+"provider" : "libvirt",
+"format" : "qcow2",
+"virtual_size" : 50
+}' > metadata.json
+voltha> cat <<HERE > Vagrantfile
+Vagrant.configure("2") do |config|
+ config.vm.provider :libvirt do |libvirt|
+ libvirt.driver = "kvm"
+ libvirt.host = 'localhost'
+ libvirt.uri = 'qemu:///system'
+ end
+config.vm.define "new" do |custombox|
+ custombox.vm.box = "custombox"
+ custombox.vm.provider :libvirt do |test|
+ test.memory = 1024
+ test.cpus = 1
+ end
+ end
+end
+HERE
+voltha> tar czvf ubuntu1604.box ./metadata.json ./Vagrantfile ./box.img
+voltha> vagrant box add --name ubuntu1604 ubuntu1604.box
+```
+***Important Note:*** Because of a known issue with Ubuntu 16.04 LTS, it is likely the VM booted by vagrant may be assigned a different interface name (ens5 instead of ens3 for example). If this happens, vagrant will hang waiting for an IP address. The following workaround needs to be applied.
+
+#### Woraround if your vagrant VM hangs
+
+From virt-manager open the console and log into the running vagrant box and do the following. Remember the userid is `vagrant` and the password is vagrant `vagrant`. First check the name that the interface was assigned:
+```
+vagrant@voltha$ ifconfig -a
+```
+There should be 2 interfaces ensX and lo. Make note of what X is for the ensX interface, log out, and close the console window.
+
+Now using virt manager again, boot up Ubuntu16.04 and open the console window for it. Remember the userid is `vagrant` and the password is `vagrant`. Use your favorite editor (vi in this case)
+```
+vagrant@voltha$ sudo vi /etc/network/interfaces
+```
+In there you should see references to ensY which doesn't correspond to the ensX you saw earlier. Find and replace all instances of ensY with ensX then shutdown the VM.
+```
+vagrant@voltha$ telinit 0
+```
+
+Now go back to where you were running vagrant up and hit ctrl-c to kill vagrant and shutdown the VM it can't coonect to.
+
+Issue the following vagrant command to blow away the defective box.
+```
+vagrant box remove Ubuntu1604
+```
+
+Now go back to create the default vagrant box and repeat those steps and the problem will no longer occur.
+
+##Download the voltha tree
+The voltha tree contains the Vagrant files required to build a multitude of VMs required to both run, test, and also to deploy voltha. The easiest approach is to download the entire tree rather than trying to extract the specific ``Vagrantfile(s)`` required.
+
+Create a .gitconfig file using your favorite editor and add the following:
+```
+# This is Git's per-user configuration file.
+[user]
+ name = Your Name
+ email = your.email@your.organization.com
+[color]
+ ui = auto
+[review "https://gerrit.opencord.org/"]
+ username=yourusername
+[push]
+ default = simple
+
+```
+
+Now you can install the repo command and pull the voltha repo.
+```
+voltha> sudo apt-get install repo
+voltha> mkdir cord
+voltha> cd cord
+voltha> repo init -u https://gerrit.opencord.org/manifest -g voltha
+voltha> repo sync
+```
+
+## Run vagrant to Create a Voltha VM
+First create the voltah VM using vagrant.
+```
+voltha> cd cord/incubator/voltha
+voltha> vagrant up
+```
+Finally, log into the vm using vagrant.
+```
+voltha> vagrant ssh
+```
+
+That's it! Enjoy voltha running in QEMU/KVM virtual machines.