10

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?

4
  • Exclude Kubuntu? You mean exclude the Kubuntu ISOs or exclude any package that is being used by Kubuntu?
    – muru
    Commented Nov 18, 2014 at 16:17
  • Exclude the Kubuntu and Xubuntu ISOs, for example. Perhaps there are an awful lot of them (Precise Kubuntu ARM, Precise Kubuntu i386, Quantal Kubuntu ARM, Quantal Kubuntu i386...) and the initial mirror download could be finished more rapidly without those ISOs. But if it is only a few more Gigabytes, perhaps it doesn't matter so much.
    – user75798
    Commented Nov 18, 2014 at 16:26
  • 1
    The ISOs are hosted separately from the packages. So you can use apt-mirror as you normally would to mirror the package repositories, and use some other tool for the ISOs. The question then becomes finding appropriate exclude filters for that tool (say rsync).
    – muru
    Commented Nov 18, 2014 at 17:02
  • "you can use apt-mirror as you normally would" I am sorry, I don't know how to do that. This is exactly what I would like to be explained.
    – user75798
    Commented Dec 13, 2014 at 21:27

2 Answers 2

11

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 of rm 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.

3
  • 1
    Is it really deb-amd64 or deb arch=amd64? I can only find the latter one in manpage
    – Anwar
    Commented Nov 20, 2016 at 17:18
  • 1
    @Anwar the former. The latter is for sources.list, which has a similar but not identical format. See manpages.ubuntu.com/manpages/trusty/en/man1/apt-mirror.1.html, where deb-powerpc is in the example.
    – muru
    Commented Nov 20, 2016 at 17:21
  • Oh! I didn't have experience with apt-mirror. Thought it was for sources.list. Thanks
    – Anwar
    Commented Nov 20, 2016 at 17:22
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .