Visit Jeremy's Blog.
Go Back > Blogs > Notes on Linux
User Name


I leave notes here that I find particularly worth remembering myself.
Rate this Entry

Howto build your own Debian repository

Posted 06-01-2010 at 06:04 AM by bittner
Updated 06-07-2010 at 08:08 AM by bittner (added reference (background reading))

If you write software for Linux and you write them for Debian systems (Debian, Ubuntu, and others) you may want to provide your software as .deb installation packages. And one day eventually you will want to set up a repository so others can download and install your software without fuzz.

If you look at a Debian mirror (e.g. you will find out one day that packages and meta information is split up into two main directories on the root level:
  • dists ... contains meta information split up in releases, target platforms (architecture), etc.
  • pool ... contains the actual pool of software installation packages (.deb files)
We will do the same thing with our repository. I assume you already have your software packed in .deb files (read this article to find out how to do this).

To build our repository we need to
  1. set up the necessary directory structure
  2. put our (updated) .deb files into the pool tree
  3. run two commands using the apt-ftparchive tool to generate the repository meta data files (Release file, and Packages files for each architecture)

Directory Structure
If you have it simple your directory structure will look like this:
(repository root)
 + dists
 | + stable  (= suite)
 |   + main  (= section)
 |     + binary-i386  (= architecture)
 + pool
   + main  (= section)
     + m  (= first letter of your software's name)
       + mysoftware  (= umbrella name of your packages)
Your .deb Files
For each software you will eventually add directories in pool, if you love hierarchical order. But those subdirectories are optional. If you provide packages for different architectures give them distict names (e.g. mysoftware-common_0.1.0-4_i386.deb, mysoftware-common_0.1.0-4_amd64.deb, etc.) and put them into the same directory in the pool subtree.

Metadata Generation
For the last step we need to prepare a configuration file for apt-ftparchive, let's call it personal-archive.conf:

APT::FTPArchive::Release {
  Version		"1.0";
  Origin		"Peter Bittner Linux Hacking";
  Label			"Personal Debian Repository";
  Suite			"personal";
  Codename		"personal";
  Architectures		"i386";
  Components		"main";
  Description		"My personal repository for Debian/Lenny";

APT::FTPArchive::Contents "no";

Default {
  Packages::Extensions	".deb";
  Packages::Compress	". gzip bzip2";
  Sources::Compress	". gzip bzip2";
  MaxContentsChange	25000;

Dir {
  ArchiveDir		"/home/bittner/Development/debian/mirror";

Tree "dists/personal" {
  Sections		"main";
  Architectures		"i386";

TreeDefault {
  Directory		"pool/personal/main";

BinDirectory "pool/personal" {
  Packages		"dists/personal/main/binary-i386/Packages";
You can use this configuration almost right away, the only unfortunate thing here is the ArchiveDir option (= your repository root): This must be an absolute path name. So, unless you're also called bittner change it.

Then run the following two commands to generate the metadata files of your repository:
$ apt-ftparchive generate --contents=off personal-archive.conf
$ apt-ftparchive -c personal-archive.conf release dists/personal > dists/personal/Release
Now you have all your files in place in the dists subtree as well (check for Release and the Packages* files, and see what is in there!). Running these commands will be necessary again each time you copy an updated version of any .deb file into the pool tree of your repository.

Providing Web Access To Your Repository
If you want others to access your repository over the web you can set up an Apache web server and place your personal repository in a Virtual Host in there. But that's another story... (a rather simple one)

P.S.: It's interesting to note that apt-ftparchive will not descend your pool subtree if you forget about the Tree section in the configuration file. Also, the --contents=off shouldn't be necessary, but the APT::FTPArchive::Contents directive seems to be ignored. I believe these are bugs of the tool, correct me if I'm wrong...

Posted in Uncategorized
Views 19609 Comments 1
« Prev     Main     Next »
Total Comments 1


  1. Old Comment

    "generate" silently fails sometimes (workaround)

    Sometimes, for some reason I have not yet fully figured out apt-ftparchive generate puts old (probably cached) data into the Packages file. You only note this problem when, e.g., the .deb file size has changed and the old size doesn't match the new size anymore. In this special case apt-get will then complain:
    E: Failed to fetch http://....
      Size mismatch
    You can work around this issue using the packages command:
    $ cd /home/bittner/Development/debian/mirror
    $ apt-ftparchive -c personal-archive.conf packages \
      pool/personal/main > dists/personal/main/binary-i386/Packages
    $ apt-ftparchive -c personal-archive.conf release \
      dists/personal > dists/personal/Release
    Of course, if your mirror hosts several components and architectures you have to loop over all of them to generate separate Packages files.
    Posted 08-06-2010 at 09:22 AM by bittner bittner is offline


All times are GMT -5. The time now is 01:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration