CAPTCHA
Image CAPTCHA
Enter the characters shown in the image.
This question is for testing whether or not you are human.
  • Create new account
  • Reset your password

User account menu

Home
The Hyperlogos
Read Everything

Main navigation

  • Home
  • My Resumé
  • blog
  • Howtos
  • Pages
  • Contact
  • Search

A custom Ubuntu repository using apt-move

Breadcrumb

  • Home
  • A custom Ubuntu repository using apt-move

Ubuntu is a wonderful Linux distribution based (as are so many others) on Debian, perhaps the most stable and certainly one of the (if not the...) "freest" of all Linux distributions. While Debian's focus is stability and freedom, Ubuntu's is completeness and convenience. Both, however, use the same package management system, apt. Without getting into the issue of why apt is better than the alternatives (for the most part, anyway) let me just launch right into the subject of where packages from from: repositories.

The Situation

From the standpoint of accuracy, saying that packages come from repositories is up there with saying babies come from hospitals; packages come from maintainers who make them from source code. But to the user who selects "Add/Remove..." from the Applications menu, or who runs Synaptic, or who even types apt-get, files come from repositories.

Apt repositories themselves are pretty straightforward things; they're directory structures which contain packages and the files which describe them. The files must include a list of the packages and basic information about them which can be extracted from the header of the .deb packages, but which may also include a list of their contents. Apt is smart enough to use this information to do updates by itself, and it also includes information on conflicts and dependencies. Most of the time the repository is accessible via HTTP, and sometimes via FTP, with a few other methods available and the potential to add more. The simplicity is inherent to the usefulness of apt; since it is based on flat text files and standards-based archives (which are in the arSee the manpage for ar(1). format, and which themselves currently contain a version file and a pair of gzipped tar archivesSee the manpage for deb(5).) the files can be taken apart with relative ease.

I wrote earlier about how to create a simple repository using apt-ftparchive, a tool whose purpose is to create the files which describe the contents of the archive. But apt-ftparchive, while quite functional, is not necessarily the best tool for the job. There are at least two options which are better; one of them is to use an apt proxy (like apt-proxy) which will not only cache package downloads, but which will also build a repository; the other, of course, is to use apt-move. There is also the option to use apt-mirror, which is literally intended to make mirrors from existing repositories.

apt-move

apt-move reads apt's state files and moves files from your /var/cache/apt/archives directory into an apt repository configured by you. It optionally also prunes old archives from the repository, keeping the disk space down. If you run it from cron on a regular basis - which could be nightly, weekly, monthly, or whatever - it will keep your archives directory clean and free from the need to be cleaned, build you a custom repository, and keep that cleaned, too. This is an immensely useful feature for any network with multiple Ubuntu systems on it.

apt-proxy is most definitely on my list of things to set up, but until I get that going, there's apt-move. It creates repositories which you can put at the top of your /etc/apt/sources.list files on other systems as well as the one on which the repository is hosted. This causes archives to be pulled from these files first. Just make sure that every repo configured on a downstream host is also configured on the repository server, and you can move deb files up from the clients to the server pretty easily just by doing an apt-get update on the server, and using rsync to copy the .deb archives there (e.g. rsync -a -e ssh /var/cache/apt/archives/*.deb server:/var/cache/apt/archives/) before running apt-move in order to move those archives into the repository. Having done this, you can safely delete the debs from your client's apt archive cache; Any package unrecognized by apt-move or which it simply cannot handle is just left in the server's /var/cache/apt/archives/ directory (to which you must have write permission, of course.)

There are numerous guides to setting up apt-move, and while some of them got me pretty close to getting it working, all of them seemed to leave something out. Perhaps things are slightly different on Ubuntu, although I doubt it. Perhaps I just had some mental block and eventually worked it out, or some other package was broken, whatever. I suspect, however, that they were all written by people who knew apt far too well, or not well enough (not that I know much about it, to be honest) and there really was always something missing. When I figure out what it was I'll let the authors know, or when I figure out I was a schmuck, I'll revise this document. Until then, here's the steps I went through to get the whole thing moving.

Installation

First, and most obvious, is to install the package apt-move. You can then create a web-accessible repository directoryFor help, see Getting a handle on LTSP in Ubuntu Gutsy and How to use ntop with mapper.pl on Ubuntu Feisty., then create a configuration file for apt-move which will put files in it. Finally, you run apt-move to create your repository.

Here's my actual config file, with blank lines and the initial expository comments removed:

# Configuration for apt-move script --------------------------------------
# The sites in ``/etc/apt/sources.list'' that you wish to mirror.
APTSITES="/all/"
# The absolute path to your debian directory (top of your local mirror).
# This MUST appear as the first entry of your sources.list if you use
# sync or mirror.
LOCALDIR=/var/www/ubuntu
# The default distribution (see the apt-move(8) manpage for details) 
DIST=stable
# The package types you want to mirror. 
# Possible values are: binary, source, and both (use only one).
PKGTYPE=binary
# The full (absolute) path to your local cache of package files. The default
# will work for the apt-get packages, unless you've reconfigured apt.
FILECACHE=/var/cache/apt/archives
# The full (absolute) path to your local cache of Packages files.  The
# default will work for the apt-get Packages, unless you've reconfigured apt.
LISTSTATE=/var/lib/apt/lists
# Do you want apt-move to delete obsolete files from your mirror? (yes/no)
DELETE=yes
# Maximum percentage of files to delete during a normal run.
MAXDELETE=20
# Set this to yes if you wish to keep the originals for move/movefile.
COPYONLY=no
# Set this to 'none gzip' to get uncompressed Packages/Sources files.
PKGCOMP=gzip
# Set this to yes to make apt-move generate Contents files.
CONTENTS=yes
# Set this to key name to be used for signing Release files.
GPGKEY=
# End Configuration ------------------------------------------------------

As you can see, I don't have signing yet. That's coming in the next revision of this document (I hope.) When testing, set COPYONLY=yes and DELETE=no until it looks like things are working; first, try DELETE=yes which will cause pruning of old packages in your repository, and eventually COPYONLY=no once you're sure the system won't delete your hard-downloaded packages without actually adding them to the repo. The more packages you have in the repository or in the apt archive cache, the slower everything is, so you should be motivated to set these options as I have them in the file.

Here's what I add to the top of my /etc/apt/sources.list to use my repository:

deb http://192.168.1.1/ubuntu stable contrib main non-free partner restricted 

It's just that simple. Just remember that this formula doesn't cause the packages, contents, and assorted files from upstream to be expressed to your computer, so if you remove all your other repositories you will only see packages in your mirror.

I have personally avoided this problem by copying the contents of the gutsy alternate server install CD and the edubuntu addons CD to directories under /var/www as well. Also in my sources.list:

deb http://192.168.1.1/ubuntu-server gutsy main restricted
deb http://192.168.1.1/edubuntu-addon gutsy main restricted 

The files were just copied into these directories, as you can see:

$ ls /var/www/ubuntu-server/
cdromupgrade  doc      isolinux    pics  preseed             ubuntu
dists         install  md5sum.txt  pool  README.diskdefines

I had problems with some filenames being terminated, and thus not recognized. I'm not sure exactly how to fix that problem, except manually. Maybe I'll go into it some other time; this is an article on creating a mirror from your downloaded packages. Incidentally, the packages from any other local repositories (like my ubuntu-server repo) will creep into your own mirror over time as they are installed, but unless you disable delete they will creep back out again, too. You can also mount the CDs, but again, I had problems with truncated filenames (which might not be a problem in Hardy, but certainly caused me a great deal of grief while net-installing Gutsy.)

howto
Ubuntu
apt
mirror
  • Log in or register to post comments

Footer menu

  • Contact
Powered by Drupal

Copyright © 2025 Martin Espinoza - All rights reserved