Mirror Configuration

There are two basic methods to synchronize a local client to a remote repository. The rsync command is the traditional method associated with synchronizing local and remote groups of files. The apt-mirror command is more focused, and in my opinion, a better choice at least for the initial mirroring of the remote repository. The focus of this section is on apt-mirror; you could subsequently use the rsync command to keep the repository created up-to-date.

As the apt-mirror package is rarely installed with an Ubuntu installation, you'll need to install it with a command such as:

$ sudo apt-get install apt-mirror

You could use the sudo apt-mirror command immediately, with associated configuration files, as is. However, when I tried it on my Hardy Heron server, it warned me that it would download more than 40GB of files. And that would have overloaded the free space currently available on that system.

So I modified the configuration files associated with the apt-mirror package. The files I changed included /etc/apt/mirror.list and /usr/bin/apt-mirror.


The default version of the /etc/apt/mirror.list configuration file lists default paths in comments, as well as configured repositories. You may also note a new apt-mirror user and group in the /etc/passwd and /etc/group files, respectively. I'll come back to those files shortly.

Now return to the /etc/apt/mirror.list configuration file. The first directive in the file sets the directory where files are copied. The default is /var/spool/apt-mirror; you could create a partition with sufficient space for the /var/ directory.

# set base_path /var/spool/apt-mirror

Because of the demands of an Ubuntu system mirror, I set up a separate partition on a new hard drive, configured it on the /apt-mirror directory, and modified the /etc/apt /mirror.list file accordingly:

set base_path /apt-mirror

The following directives (and associated comment—and privlages is misspelled in the configuration file) list the directories that need to be created, with privileges:

# if you change the base path you must create the directories

# below with write privlages

# set mirror_path $base_path/mirror

# set skel_path $base_path/skel

# set var_path $base_path/var

# set cleanscript $var_path/clean.sh

I suspect that most readers will have already installed the Apache Web server. It's also useful for repositories. You could create repositories in the standard Apache directory tree, /var/www/. But soft links from this directory are also fairly easy to configure. I therefore ran the following commands to create the appropriate directories, as subdirectories of the value of the base_path directive:

$ sudo mkdir /apt-mirror $ sudo mkdir /apt-mirror/mirror

$ sudo mkdir /apt-mirror/skel

$ sudo mkdir /apt-mirror/var $

These commands create the noted directories with write privileges for the owner. But to make this work, I also need to set the owner for all these directories (and subdirectories) as the apt-mirror user and group. One way to do this is with the following command. The chown -R command changes ownership on the /apt-mirror directory, and subdirectories, recursively:

$ sudo chown -R apt-mirror.apt-mirror /apt-mirror

Now I return to the /etc/apt/mirror.list configuration file. The default uses the running host architecture. If I were creating a mirror on a 64-bit system, the following suggests that the default would be to copy from 64-bit repositories:

# set defaultarch <running host architecture>

If the mirror is for clients of a different architecture from the local server, I would have to specify that as well. For example, if I were creating a mirror for 32-bit systems on a 64-bit server, I would add the following directive:

set defaultarch i386

The directives which follow include a series of URLs which specify the repositories to be mirrored. These URLs should be changed to list only those repositories that need to be mirrored. For example, I limit what is mirrored by including only the following URLs and commenting out all others. The clean directive frees space from obsolete packages from associated repositories.

deb http://us.archive.ubuntu.com/ubuntu hardy-updates main restricted clean http://us.archive.ubuntu.com/ubuntu

I specify the national repository that applies to me, substituting us.archive.ubuntu .com for the instances of archive.ubuntu.com shown in the configuration file. I also limit the copying to the main and restricted repositories. I could also add the universe and multiverse repositories to this directive. The repositories you choose to copy depends on available disk space and your willingness to download tens of gigabytes of data.

I don't even consider mirroring the security-related repositories, as it's more important that security updates are based on the latest available releases.

While the http://us.archive.ubuntu.com/ubuntu repository is the most up-to-date, I could substitute a mirror such as http://mirrors.kernel.org/ubuntu. The decision is whether to copy the mirror or the more up-to-date but distant repository. There are good arguments for both, and the decision depends in part on how frequently the selected mirror site is kept up-to-date. I choose to copy from the mirror, so I substitute accordingly in /etc/apt/mirror.list:

deb http://mirrors.kernel.org/ubuntu hardy-updates main restricted clean http://mirrors.kernel.org/ubuntu

Any other URL shown in this file is deactivated by adding a comment character (#) in front. As discussed earlier, if you changed the default base_path defined earlier for the /etc/apt/mirror.list configuration file, a change is also required to the /usr/bin / apt-mirror script. Since I changed it to / apt-mirror, I change it in the / usr/bin/apt-mirror script as well:

Continue reading here: To Mirror an Ubuntu Repository

Was this article helpful?

+2 0