Difference between revisions of "Howto build VyOS 1.2 ISO image and VMWare .OVF"

From VyOS Wiki
Jump to: navigation, search
Line 29: Line 29:
 
  apt-get install emacs
 
  apt-get install emacs
  
: '''WARNING'''
+
: [[File:lookout.png]] - For some reason the left mouse button does not work with Debian under VMware (at least out of the box). There are a couple of articles on the Internet about this. I was able to login and get a terminal window open using a combination of the keyboard and the right mouse button. Once open-vm-tools was installed the left mouse started working.
:: For some reason the left mouse button does not work with Debian under VMware (at least out of the box). There are a couple of articles on the Internet about this. I was able to login and get a terminal window open using a combination of the keyboard and the right mouse button. Once open-vm-tools was installed the left mouse started working.
 
  
 
Installing sudo and adding your user account to the sudo group is not strictly necessary and it does mean that you can do the build process from a non-root / non-priviledged account, which is a security best practice
 
Installing sudo and adding your user account to the sudo group is not strictly necessary and it does mean that you can do the build process from a non-root / non-priviledged account, which is a security best practice
Line 42: Line 41:
 
There are a few components you will have to download from the Internet in order to build VyOS 1.2:
 
There are a few components you will have to download from the Internet in order to build VyOS 1.2:
  
* HashiCorp Packer - tool to build automated machine images (www.packer.io)
+
* HashiCorp Packer - tool to build automated machine images  
 
* VMWare open-vmdk  
 
* VMWare open-vmdk  
 
* VMWare ovftool
 
* VMWare ovftool
Line 48: Line 47:
 
==== Packer ====
 
==== Packer ====
  
Download Packer. Upload to server. Unzip. Copy to a bin directory.
+
Download Packer (www.packer.io). Upload to server. Unzip. Copy to a bin directory.
  
 
  unzip packer_1.0.2_linux_amd64.zip
 
  unzip packer_1.0.2_linux_amd64.zip
Line 82: Line 81:
 
  === Building qemu image ===
 
  === Building qemu image ===
  
At this point we have a working .iso image and we can proceed with building the qemu image. Before we build the qemu image you will need to create a private ssl key and while not strictly necessary installing vnc (vncviewer specifically) is helpful to monitor the build process.
+
At this point you have a working .iso image and we can proceed with building the qemu image. Before we build the qemu image you will need to create a private SSL key.  
  
 
==== Build privatekey.pem ====
 
==== Build privatekey.pem ====
  
 
  mkdir key
 
  mkdir key
cd key
+
  openssl genrsa -des3 -out key/privatekey.pem 2048
  openssl genrsa -des3 -out privatekey.pem 2048
 
cd ..
 
  
 
==== Install VNC Viewer ====
 
==== Install VNC Viewer ====
  
I installed Tight VNC Viwer using the synaptic package manager.
+
As mentioned previously, you will need a VNC viewer client to monitor the qemu build process. I used the synaptic package manage to install Tight VNC Viwer.
  
 
==== packer.json ====
 
==== packer.json ====
  
One of the steps in building the qemu image is to configure the vyos install. This process boots the .iso image, installs it as a virtual machine and then configures the image to work in a virtualization environment. Basically, it sets the ethernet interface to use dhcp, deletes the hardware id and enables ssh. Part of the packer.json file sends the key commands to Packer to do this. My experuience was that this did not work out of the box. I needed to modify the "boot_command" section of the packer.json file to adjust the wait times such that there was enough delay between keypresses and commands for the process to work.
+
Part of the process of building a qemu image is to boot VyOS, install it in a qemu virtual machine and configure the vm to use DHCP, remove the hardware id for the interface and enable SSH. This is done with packer and a set of boot commands. The boot commands are set/configured in the packer.json file. The packer.json file is located in the scripts directory. The boot commands in the packer.json file relies on somewhat arbitrary timings. My initial experience was that the default timings in the packer.json file did not work with my build machine (the timings were not long enough and the qemu build process failed). I needed to modify the packer.json file and adjust the timings of the boot commands to work with my build environment.
 +
 
 +
Look at the packer.json file. There is a section labelled "boot_command": under that section are the key commands sent to the qemu vm during the install/configuration process. The documentation for the boot commands can be found at https://www.packer.io/docs/builders/qemu.html (scroll down to the bottom of the page).
 +
 
 +
The most relevant boot command for your purposes is the <wait> command:
 +
 
 +
;<wait>
 +
: wait 1 second.
 +
 
 +
;<wait5>
 +
: wait 5 seconds.
 +
 
 +
;<wait10>
 +
: wait 10 seconds.
 +
 
 +
;<waitXX>
 +
: wait some arbitrary time. Examples: <wait15s> - wait 15 seconds. <wait10m> - wait 10 minutes. <wait1m30s> - wait 1 minute 30 seconds.
 +
 
 +
'''Note:''' - the default delay between keypresses is 100ms.
  
 
==== Actually building qemu image ====
 
==== Actually building qemu image ====
  
Open vnc viewer on your build machine
+
Open vnc viewer on your build machine.
  
 
  sudo make qemu
 
  sudo make qemu
Line 112: Line 127:
 
  qemu-image: vnc://127.0.0.1:59xx
 
  qemu-image: vnc://127.0.0.1:59xx
  
Type 127.0.0.1:59xx in your vnc viewer client (replace xx with whatever shows up on your build. It changes each time.) This will allow you to monitor the Packer boot commands and determine if you need to make any modifications.
+
Type 127.0.0.1:59xx in your VNC viewer client (replace xx with whatever shows up on your build. It changes each time.) This will allow you to monitor the Packer boot commands and determine if you need to make any modifications. If your VNC viewer is configured to use a password or encryption, then turn it OFF.
 
 
This will take a while.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
== Executive Summary ==
 
 
 
This HowTo describes how to build VyOS 1.2 from source. It assumes you are familiar with installing Linux and are comfortable working in a Unix shell/command line. The HowTo is based upon the readme file from the VyOS github site and adds some details and other observations which might not be that obvious.
 
 
 
== Step 1: Create Build Machine Setup ==
 
 
 
For my testing I created a Debian 8 "jesse" virtual machine for building VyOS 1.2. You could use VMWare Workstation, VMWare Fusion, Virtual Box, HyperV or similar. For my testing I used an ESXi server in my lab environment.
 
 
 
# Download Debian 8 "jesse" (https://www.debian.org/releases/jessie/)
 
# Install Debian either on a dedicated machine or as a virtual machines.
 
 
 
<br>
 
----
 
'''Note:''' Install Gnome, KDE or your favorite windowing system. Most of the build process can be done via the command line. However, troubleshooting the qemu build process requires vncview, so it is recommended that you install a windowing system when you install Debian. I think I used Cinnamon.
 
----
 
<br>
 
 
 
Once Debian was installed I logged and ran the following commands as root:
 
 
 
apt-get install sudo
 
apt-get install open-vm-tools
 
apt-get install emacs
 
 
 
=== Comments ===
 
 
 
* sudo is not strictly necessary, but is useful.
 
* open-vm-tools was needed for running my build machine under ESXi.
 
* emacs any text editor will do. I think nano is installed by default with Debian. Install your editor of choice.
 
 
 
At this point you should have a pretty clean install of Debian. If you are running a virtual machine and your environment allows for snapshooting now might be a good time to take a snapshot in case you make a mistake and need to revert.
 
 
 
== Install Required Software ==
 
 
 
In addition to all the "standard" tools required to build VyOS there are a few others which are required to build VyOS 1.2:
 
 
 
* Packer
 
* VMWare open-vmdk
 
* VMWare ovftool
 
 
 
First install the git and all the other linux tools needed:
 
 
 
sudo apt-get install git autoconf automake dpkg-dev syslinux genisoimage qemu jq libz-dev zip python3 live-build pbuilder devscripts python3-pystache
 
 
 
=== Download & Install Packer ===
 
 
 
Never heard of Packer before, neither had I...it is a pretty cool tool. You can download it here form https://www.packer.io/
 
 
 
* Transfer .zip to your build machine
 
* unzip
 
* copy to /usr/local/bin
 
 
 
 
 
 
 
  
=== Download & Compile VMWare open-vmdk ===
+
The qemu build process will take a while (about 10 minutes). Good time to clean up the kitchen, respond to an email, make a cup of coffee, etc.
  
=== Download & Install VMWare ovftool ===
+
==== Build VMWare image ====
  
=== Download VyOS Source ===
+
Type:
  
=== Generate Private Key ===
+
sudo make vmware
  
== Build VyOS ==
+
The VMware build is fairly quick. When complete the VMware files are located in packer_build/vmware

Revision as of 11:16, 2 July 2017

Background

I have been interested in getting VyOS to run as a Google Cloud Compete instance for quite sometime. Unfortunately, the current version of VyOS 1.1.x is based upon Debian 6 which just does not work (unless you jump through many more hoops then I am willing to jump through), so I became curious to see if this would be possible with VyOS 1.2. As I began my investigation into what it would take to compile VyOS 1.2 I noticed that all the documentation was present, but it was not that easy to use (IMHO) and I discovered several "gotchas". The purpose of this HowTo is provide a complete set of instructions on how to compile VyOS 1.2 and point out some of the issues I encounter so that others can do what I did easier and faster.

This HowTo assumes you are familiar with installing Linux and are comfortable working in the Linux shell/command line.

Enjoy.

--Max Abramowitz.

Building VyOS 1.2

Create Build Machine

The first step is to download and build a Debian 8 build machine. You can download Debian 8 "Jesse" from:

Lookout.png Most of the build process can be done from the Linux shell. However, troubleshooting the qemu build process requires vncviewer which requires a graphical desktop environment. The screenshot below show the settings using in my testing.
VyOS build machine initial software configuration

Preliminary Build Machine Configuration

Before installing software you will want to perform some basic configuration of your build machine. Install sudo, add your user account to the sudo group, install open-vm-tools (if your build machine is a VMware virtual machine and install your preferred text editor). Below are the configuration commands I used (these commands were run as root user):

apt-get install sudo
adduser <username> sudo
apt-get install open-vm-tools
apt-get install emacs
Lookout.png - For some reason the left mouse button does not work with Debian under VMware (at least out of the box). There are a couple of articles on the Internet about this. I was able to login and get a terminal window open using a combination of the keyboard and the right mouse button. Once open-vm-tools was installed the left mouse started working.

Installing sudo and adding your user account to the sudo group is not strictly necessary and it does mean that you can do the build process from a non-root / non-priviledged account, which is a security best practice

Installing Required Software Components

Install the basic softare needed:

sudo apt-get install git autoconf automake dpkg-dev syslinux genisoimage qemu jq libz-dev zip python3 live-build pbuilder devscripts python3-pystache

There are a few components you will have to download from the Internet in order to build VyOS 1.2:

  • HashiCorp Packer - tool to build automated machine images
  • VMWare open-vmdk
  • VMWare ovftool

Packer

Download Packer (www.packer.io). Upload to server. Unzip. Copy to a bin directory.

unzip packer_1.0.2_linux_amd64.zip
sudo cp packer /usr/local/bin/

VMWare open-vmdk

git clone https://github.com/vmware/open-vmdk
cd open-vmdk/
make
sudo make install

VMWare ovftool

You will need a VMWare account to download VMWare ovftool. Goto https://www.vmware.com/support/developer/ovf/. Click Software Download. Download the VMware OVF tool for Linux 64-bit. Upload the bundle to your build machine.

chmod 755 VMware-ovftool-4.2.0-4586971-lin.x86_64.bundle
sudo ./VMware-ovftool-4.2.0-4586971-lin.x86_64.bundle
Follow the prompts to complete the installation
=== Building ISO image ===
At this point all the software for building an ISO image should be installed on your build system and you can proceed with downloading the source code and building an ISO image
 git clone https://github.com/vyos/vyos-build.git
 cd vyos-build
 ./configure
 sudo make iso
Go get a cup of coffee. Once the build process is complete the .iso file will be in the build folder
=== Building qemu image ===

At this point you have a working .iso image and we can proceed with building the qemu image. Before we build the qemu image you will need to create a private SSL key.

Build privatekey.pem

mkdir key
openssl genrsa -des3 -out key/privatekey.pem 2048

Install VNC Viewer

As mentioned previously, you will need a VNC viewer client to monitor the qemu build process. I used the synaptic package manage to install Tight VNC Viwer.

packer.json

Part of the process of building a qemu image is to boot VyOS, install it in a qemu virtual machine and configure the vm to use DHCP, remove the hardware id for the interface and enable SSH. This is done with packer and a set of boot commands. The boot commands are set/configured in the packer.json file. The packer.json file is located in the scripts directory. The boot commands in the packer.json file relies on somewhat arbitrary timings. My initial experience was that the default timings in the packer.json file did not work with my build machine (the timings were not long enough and the qemu build process failed). I needed to modify the packer.json file and adjust the timings of the boot commands to work with my build environment.

Look at the packer.json file. There is a section labelled "boot_command": under that section are the key commands sent to the qemu vm during the install/configuration process. The documentation for the boot commands can be found at https://www.packer.io/docs/builders/qemu.html (scroll down to the bottom of the page).

The most relevant boot command for your purposes is the <wait> command:

<wait>
wait 1 second.
<wait5>
wait 5 seconds.
<wait10>
wait 10 seconds.
<waitXX>
wait some arbitrary time. Examples: <wait15s> - wait 15 seconds. <wait10m> - wait 10 minutes. <wait1m30s> - wait 1 minute 30 seconds.

Note: - the default delay between keypresses is 100ms.

Actually building qemu image

Open vnc viewer on your build machine.

sudo make qemu

You will see:

qemu-image: Starting VM, booting from CD-ROM
qemu-image: The VM will be run headless, without a GUI. If you want to
qemu-image: view the screen of the VM, connect via VNC without a password to
qemu-image: vnc://127.0.0.1:59xx

Type 127.0.0.1:59xx in your VNC viewer client (replace xx with whatever shows up on your build. It changes each time.) This will allow you to monitor the Packer boot commands and determine if you need to make any modifications. If your VNC viewer is configured to use a password or encryption, then turn it OFF.

The qemu build process will take a while (about 10 minutes). Good time to clean up the kitchen, respond to an email, make a cup of coffee, etc.

Build VMWare image

Type:

sudo make vmware

The VMware build is fairly quick. When complete the VMware files are located in packer_build/vmware