Create a local apt-mirror for offline usage

Sep 27, 2019 by Alexandre - 222 views

https://cylab.be/blog/38/create-a-local-apt-mirror-for-offline-usage

In some cases, it is necessary to work on offline machines because of sensitive data for example. To install a Ubuntu version on an offline computer is quite easy. Problems begin when it is needed to install some programs/debian packages for your development. With the default configuration, it is not possible to install anything without an Internet connection.

To avoid this problem, a solution is to install a local apt-mirror (on your machine or on a local network disconnected from the Internet).

Installation

An APT-mirror is a full or partial copy of the official apt packages.

Download packages

On a machine connected to the Internet, run the following command

debmirror -p -v -h ftp.belnet.be -r mirror/ubuntu.com --method ftp --passive -d xenial,xenial-security,xenial-updates -a i386,amd64 --ignore-release-gpg  /path/to/usb-disk/ubuntu-xenial/

This command will download, in ftp, on mirror/ubuntu.com all packages for Ubuntu Xenial (16.04LTS) for architecture i386 and amd64. All packages will be stored on folder /path/to/usb-disk/ubuntu-xenial.

Debmirror has a lot of different options, you can easily adapt the command for other needs.

It is important to have enough space disk to create an apt-mirror. The above example command requires around 300GB of space.

Set up a mirror on the offline machine

On the offline machine, you need to install an Apache server. It is really easy with an Internet connection, but more difficult without... Apache requires several dependencies and it is necessary to install these manually. The following script downloads all deb packages needed to install Apache on Ubuntu 16.04LTS:

#!/bin/sh
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apr/libapr1_1.5.2-3_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apr-util/libaprutil1_1.5.4-1build1_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apr-util/libaprutil1-dbd-sqlite3_1.5.4-1build1_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apr-util/libaprutil1-ldap_1.5.4-1build1_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/l/lua5.1/liblua5.1-0_5.1.5-8ubuntu1_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-bin_2.4.18-2ubuntu3.13_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-utils_2.4.18-2ubuntu3.13_amd64.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-data_2.4.18-2ubuntu3.13_all.deb
wget -c http://nl.archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2_2.4.18-2ubuntu3.13_amd64.deb

Copy all these deb packages on the offline machine and install all packages with the command:

sudo dpkg -i package

After that, simply copy the mirror previously downloaded in the folder /var/www/html/apt

Set up offline machine(s) to use the mirror

On each machine on which you want to use the offline apt-mirror, change the file /etc/apt/sources.list by the following:

deb http://ip.of.srv/apt/ubuntu-xenial xenial main restricted universe
deb http://ip.of.srv/apt/ubuntu-xenial xenial-updates main restricted universe
deb http://ip.of.srv/apt/ubuntu-xenial xenial-security main restricted universe

by replacing ip.of.srv by the IP address of your offline mirror.

You can now update and install all the packages you want!