How to create a local repository using apt-mirror and mirrorkit?
Having a local repository can be very useful. It is possible to use rsync
to create a repository mirror, but this results in all the releases being downloaded, even older ones and would include files for architectures that might not be needed.
apt-mirror
allows one to selectively choose parts of the repository. mirrorkit
provides a front-end to apt-mirror.
What is the best way to create a local repository mirror for selected parts of the Ubuntu archives?
For example, one might wish to include:
Main, Restricted, Universe, Multiverse, All Ubuntu and Lubuntu but exclude other derivatives, such as Kubuntu and Xubuntu.
Only AMD64 and i386 but exclude other architectures.
Only Trusty Tahr, but not Precise Penguin or Utopic Unicorn.
One might wish to configure the process so that it downloaded from a local mirror, rather than the main archives.
How can I create local repository using apt-mirror
and mirrorkit
for a selected architecture, release, or Ubuntu variant?
Solution 1:
The CD repository and software repository are two distinct components (they even have separate Launchpad pages: cdmirrors and archivemirrors). Therefore, mirroring them are two distinct tasks. Further, while the various flavours have different folders on the CD repository, they share a software repository. So you can selectively mirror the images per flavour, but not the software. For the software repository, you can selectively mirror based on:
- release (
trusty
,precise
, etc.) - architecture (
amd64
,i386
, etc.) - package type (binary [
deb
] vs source [deb-src
]) - channels (
trusty
,trusty-updates
,trusty-backports
, etc.) - sections (
main
,multiverse
, etc.)
To mirror the software repository, use apt-mirror
.
apt-mirror
is configured using /etc/apt/mirror.list
. It has a format very similar to sources.list
. The configuration file installed by the package has a few commented out options which list their defaults. If you wish, you can uncomment and change them.
To mirror a repository, you need to add a line to mirror.list
like you would for sources.list
:
deb http://us.archive.ubuntu.com/ubuntu trusty main multiverse restricted universe
The default is to mirror only the host's architecture, so if you're on a 64-bit Ubuntu, only amd64
will be mirrored. You need to add another line of the form:
deb-i386 http://us.archive.ubuntu.com/ubuntu trusty main multiverse restricted universe
And for source packages:
deb-src http://us.archive.ubuntu.com/ubuntu trusty main multiverse restricted universe
If you're looking for a reasonably complete mirror, these lines would be the minimum (I would also recommend -updates
channel):
deb http://us.archive.ubuntu.com/ubuntu trusty main multiverse restricted universe
deb http://us.archive.ubuntu.com/ubuntu trusty-security main multiverse restricted universe
deb-i386 http://us.archive.ubuntu.com/ubuntu trusty main multiverse restricted universe
deb-i386 http://us.archive.ubuntu.com/ubuntu trusty-security main multiverse restricted universe
Finally, you need to add a clean
line so that packages no longer available in the repository are filtered for removal:
clean http://us.archive.ubuntu.com/ubuntu
Say your variables are thus (the defaults):
set base_path /var/spool/apt-mirror
set mirror_path $base_path/mirror
set skel_path $base_path/skel
set var_path $base_path/var
set cleanscript $var_path/clean.sh
Then:
- The repository will be mirrored to
$mirror_path/parent-hostname/directory
(so/var/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu
) - The
clean.sh
(which will be a set ofrm
commands to delete obsolete packages and directories) will be/var/spool/apt-mirror/var/clean.sh
. - The logs will go to
/var/spool/apt-mirror/var
.
The apt-mirror
package installs a cron job (/etc/cron.d/apt-mirror
), which you should edit to enable (by uncommenting the line containing /usr/bin/apt-mirror
). You should also add a cron job for running clean.sh
(I run it weekly).
Of course, you should replace http://us.archive.ubuntu.com./ubuntu
with whichever mirror you prefer.
Solution 2:
I recommend apt-cacher for those with limited space or those having exhorbitant internet prices in their countries.
apt-mirror, allegedly, requires at least 15GB for each flavour (32/64 bit) of the distro you want. apt-cacher only uses the packages you have installed.
Read Create a Local Ubuntu Repository using Apt-Mirror and Apt-Cacher for more details/instructions please.