apt-mirror

From Mark Furneaux's Wiki
Jump to: navigation, search

apt-mirror is an application which mirrors specific software sources for apt. It can be used in conjunction with a web server to create a software repository on a local network for fast updates. This guide assumes we are creating a mirror for Ubuntu.

Installation

Both Apache and apt-mirror are required. Install them by running:
# apt install apache2 apt-mirror

Configuration

Depending on the number of releases of the distribution you want to mirror, expect the mirror to consume from 100-200GB of disk space.

Create a directory for the packages to be stored. Alternatively, create a ZFS dataset instead. We will assume a location of /tank/aptmirror.

Edit /etc/apt/mirror.list and edit the following lines:

############# config ##################
#
 set base_path    /tank/aptmirror
#
# set mirror_path  $base_path/mirror
 set skel_path    /var/spool/apt-mirror/skel
 set var_path     /var/spool/apt-mirror/var
 set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb http://mirror.csclub.uwaterloo.ca/ubuntu trusty main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu trusty-security main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu trusty-updates main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu trusty-proposed main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu trusty-backports main restricted universe multiverse

deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu trusty main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-security main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-updates main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-proposed main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-backports main restricted universe multiverse

deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu trusty main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-security main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-updates main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-proposed main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu trusty-backports main restricted universe multiverse

deb-src http://mirror.csclub.uwaterloo.ca/ubuntu trusty main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu trusty-security main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu trusty-updates main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu trusty-proposed main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu trusty-backports main restricted universe multiverse

deb http://mirror.csclub.uwaterloo.ca/ubuntu xenial main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu xenial-security main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu xenial-updates main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu xenial-proposed main restricted universe multiverse
deb http://mirror.csclub.uwaterloo.ca/ubuntu xenial-backports main restricted universe multiverse

deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu xenial main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-security main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-updates main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-proposed main restricted universe multiverse
deb-amd64 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-backports main restricted universe multiverse

deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu xenial main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-security main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-updates main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-proposed main restricted universe multiverse
deb-i386 http://mirror.csclub.uwaterloo.ca/ubuntu xenial-backports main restricted universe multiverse

deb-src http://mirror.csclub.uwaterloo.ca/ubuntu xenial main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu xenial-security main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu xenial-updates main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu xenial-proposed main restricted universe multiverse
deb-src http://mirror.csclub.uwaterloo.ca/ubuntu xenial-backports main restricted universe multiverse

clean http://mirror.csclub.uwaterloo.ca/ubuntu

The paths need to be changed as the Ubuntu package uses /var/spool/apt-mirror/ as the default location for the scripts and metadata.
The deb lines should be changed to reflect what should be mirrored. Note that there are separate lines for i386 and amd64.

Start apt-mirror manually by running:
# apt-mirror
This can be interrupted at any time and the download resumed on next run.

Once this has started downloading packages and has created the directory structure, add a symlink to the webserver directory:
# ln -s /tank/aptmirror/mirror/mirror.csclub.uwaterloo.ca/ubuntu/ /var/www/html/ubuntu

Create a script to update and clean the repository and save in in /usr/local/bin/updateaptmirror.

#!/bin/bash

/usr/bin/apt-mirror >> /var/log/apt-mirror.log

cd /var/spool/apt-mirror/var/

./clean.sh > /dev/null

Configure cron to update the mirror daily by adding the following to /etc/crontab:
0 3 * * * root /usr/local/bin/updateaptmirror > /dev/null

Now make sure to update the /etc/apt/sources.list on each client to use the new mirror.

Optionally, commands to run after an update can be put in /var/spool/apt-mirror/var/postmirror.sh.