When I do something that is not trivial and needs some research, I try to summarize it and write it down, in case that I will need later to do the same thing again. It may also be useful for other people that could be trying to do something similar.

Thursday, August 9, 2012

How to Create a Local Ubuntu Repository

We have about 40 computers installed with Edubuntu, and more than a dozen of servers (most of them running on virtual machines). They all need to be updated time after time with the latest version of packages. Also, time after time, new packages need to be installed. These packages come from some central Ubuntu Repository servers.

All this activity for keeping computers up-to-date (up to the latest version) consumes lots of bandwidth and takes a lot of time. And there are new package updates almost every day! For one computer this can be acceptable, however for lots of computers it may become unbearable.

One solution for this problem is to create a local mirror of the ubuntu repository.

Table of Contents

Creating an APT Mirror

Configure clients for using the local repository

Keeping the APT mirror synchronized

Doing release upgrade from our local ubuntu repository

Referencies:

1 Creating an APT Mirror

Fortunately, creating a local mirror of the APT packages is very easy. There is even a tool that helps to create it, called apt-mirror. So, the first step is to install it:

aptitude install apt-mirror

The next step is to customize its configuration file, /etc/apt/mirror.list. It should look like this:

The URL-s here are the same to what I have on /etc/apt/sources.list on my computers. I am storing the packages on the directory/data/apt-mirror, which has plenty of free disk space (at least 200 GB). I am mirroring the packages for both amd64 and i386 architectures, and i am skipping the source packages (deb-src) to save some space.
Now we can start making the mirror (or updating it) by running apt-mirror.

Note

If the mirroring process is interrupted, start it again by typing apt-mirror. If it refuses to start (claiming that it is already running), look out for/data/apt-mirror/var/apt-mirror.lock and remove it.

Note

Initially it can take a lot of time (several days) to make a full mirror, depending on the speed of the network connection.

After mirroring is done, we can export the mirror by HTTP:

ln -s /data/apt-mirror/mirror /var/www/apt-mirror

Of course, apache has to be already installed (aptitude install apache2).

2 Configure clients for using the local repository

In order to use this mirror from a client, modify /etc/apt/sources.list to use something like this http://192.168.10.50/apt-mirror/archive.ubuntu.com/ubuntu/ instead of http://archive.ubuntu.com/ubuntu/. It should look like this: