Compiling OpenVPN in an Ubuntu 14.04 Chroot
Tags: ubuntu, openvpn, buildtools, linux
Published: 2023-11-07 22:02:10

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](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.

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

## Set Up Build Environment

[https://community.openvpn.net/openvpn/wiki/TesterDocumentation](https://community.openvpn.net/openvpn/wiki/TesterDocumentation) [http://packaging.ubuntu.com/html/](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.

```bash
apt-get install vim
```

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

```bash
vim /etc/apt/sources.list
```

Add the following text.

```bash
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
```

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

```bash
vim /usr/sbin/policy-rc.d
```

Add the following to the file

```bash
#!/bin/sh
exit 101
```

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

```bash
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
```

## Build OpenVPN

```bash
apt-get build-dep openvpn
```

## Using Canonical Bazaar

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

```bash
cd $HOME
bzr branch lp:ubuntu/trusty/openvpn
```

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.

```bash
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/
```

Now to finally build the OpenVPN package.

```bash
cd $HOME
cd openvpn
bzr bd -- -b -us -uc
```

### 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`

```bash
cd $HOME
apt-get source openvpn
cd openvpn-*
autoreconf -vi
./configure
make all
make check
```

## Build openvpn-auth-ldap

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

```bash
apt-get build-dep openvpn-auth-ldap
```

### Using Canonical Bazaar

```bash
cd $HOME
bzr branch lp:ubuntu/trusty/openvpn-auth-ldap
cd openvpn-auth-ldap
bzr bd -- -b -us -uc
```

### Using Make

```bash
cd $HOME
apt-get source openvpn-auth-ldap
cd openvpn-auth-ldap-*
./configure
make
```