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?
Best Answer
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:
trusty
,precise
, etc.)amd64
,i386
, etc.)deb
] vs source [deb-src
])trusty
,trusty-updates
,trusty-backports
, etc.)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 tosources.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 forsources.list
: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:And for source packages:
If you're looking for a reasonably complete mirror, these lines would be the minimum (I would also recommend
-updates
channel):Finally, you need to add a
clean
line so that packages no longer available in the repository are filtered for removal:Say your variables are thus (the defaults):
Then:
$mirror_path/parent-hostname/directory
(so/var/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu
)clean.sh
(which will be a set ofrm
commands to delete obsolete packages and directories) will be/var/spool/apt-mirror/var/clean.sh
./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 runningclean.sh
(I run it weekly).Of course, you should replace
http://us.archive.ubuntu.com./ubuntu
with whichever mirror you prefer.