DEV Community

Aaron Peschel
Aaron Peschel

Posted on

Compiling OpenVPN in an Ubuntu 14.04 Chroot

Originally published by apeschel on July 11, 2016, 6:35 p.m.

Set up chroot build environment

Digital Ocean has a good guide for setting up a build chroot available here:

https://www.digitalocean.com/community/tutorials/how-to-configure-chroot-environments-for-testing-on-an-ubuntu-12-04-vps

The only thing of note is that they recommend putting your chroot in your root / directory on your base host. I suggest using /srv/schroot/ instead.

The instructions provided here are for Ubuntu trusty, which is what we will be using to build OpenVPN.

sudo apt-get update
sudo apt-get install dchroot debootstrap
Enter fullscreen mode Exit fullscreen mode
sudo mkdir -p /srv/schroot/ubuntu14.04
Enter fullscreen mode Exit fullscreen mode
sudo debootstrap --variant=buildd --arch amd64 trusty /srv/schroot/ubuntu14.04/ http://us.archive.ubuntu.com/ubuntu/
Enter fullscreen mode Exit fullscreen mode
proc                        /srv/schroot/ubuntu14.04/proc proc    defaults        0       0
sysfs                       /srv/schroot/ubuntu14.04/sys  sysfs   defaults        0       0
Enter fullscreen mode Exit fullscreen mode
sudo mount proc /srv/schroot/ubuntu14.04/proc -t proc
sudo mount sysfs /srv/schroot/ubuntu14.04/sys -t sysfs
Enter fullscreen mode Exit fullscreen mode
sudo cp /etc/hosts /srv/schroot/ubuntu14.04/etc/hosts
Enter fullscreen mode Exit fullscreen mode
sudo chroot /srv/schroot/ubuntu14.04/ /bin/bash
Enter fullscreen mode Exit fullscreen mode

Set Up Build Environment

https://community.openvpn.net/openvpn/wiki/TesterDocumentation http://packaging.ubuntu.com/html/

Having a text editor in our chroot environment will reduce the number of times we have to leave and enter the chroot, thus it is installed for convenience.

apt-get install vim
Enter fullscreen mode Exit fullscreen mode

Our chroot environment will have a very bare-bones sources.list. We will need to add some entries to it.

vim /etc/apt/sources.list
Enter fullscreen mode Exit fullscreen mode

Add the following text.

deb-src http://us.archive.ubuntu.com/ubuntu trusty main

deb http://us.archive.ubuntu.com/ubuntu trusty universe
deb-src http://us.archive.ubuntu.com/ubuntu trusty universe
Enter fullscreen mode Exit fullscreen mode

We need to update Ubuntu's policy-rc.d to let it know that we are in a chroot environment.

vim /usr/sbin/policy-rc.d
Enter fullscreen mode Exit fullscreen mode

Add the following to the file

#!/bin/sh
exit 101
Enter fullscreen mode Exit fullscreen mode

Now we will install any additional build tools that will be required. We will use bzr (bazzar) to build the OpenVPN package.

cd $HOME
locale-gen en_US.UTF-8
apt-get update
apt-get install net-tools autoconf libtool dialog
apt-get install bzr bzr-builddeb devscripts
Enter fullscreen mode Exit fullscreen mode

Build OpenVPN

apt-get build-dep openvpn
Enter fullscreen mode Exit fullscreen mode

Using Canonical Bazaar

Here we download the 14.04 OpenVPN source in a new package branch.

cd $HOME
bzr branch lp:ubuntu/trusty/openvpn
Enter fullscreen mode Exit fullscreen mode

The TLS keys that are used for the OpenVPN tests in the 14.04 source have expired. This will cause the tests to fail. We can use the keys from the latest OpenVPN release instead to fix this.

apt-get install git
git clone git://git.code.sf.net/p/openvpn/openvpn-testing openvpn-openvpn-testing
cp openvpn-openvpn-testing/sample/sample-keys/* openvpn/sample/sample-keys/
Enter fullscreen mode Exit fullscreen mode

Now to finally build the OpenVPN package.

cd $HOME
cd openvpn
bzr bd -- -b -us -uc
Enter fullscreen mode Exit fullscreen mode

Build Raw binaries using make

This will skip the testing phase, which takes a long time with the OpenVPN package. However, it will not create a package and will require installation via make install

cd $HOME
apt-get source openvpn
cd openvpn-*
autoreconf -vi
./configure
make all
make check
Enter fullscreen mode Exit fullscreen mode

Build openvpn-auth-ldap

This follows the same core process as building the OpenVPN package.

apt-get build-dep openvpn-auth-ldap
Enter fullscreen mode Exit fullscreen mode

Using Canonical Bazaar

cd $HOME
bzr branch lp:ubuntu/trusty/openvpn-auth-ldap
cd openvpn-auth-ldap
bzr bd -- -b -us -uc
Enter fullscreen mode Exit fullscreen mode

Using Make

cd $HOME
apt-get source openvpn-auth-ldap
cd openvpn-auth-ldap-*
./configure
make
Enter fullscreen mode Exit fullscreen mode

Top comments (0)