How To Create An Ubuntu Repository Mirror on Ubuntu 8.04

I was discussing the creation and maintenance of an Ubuntu repository mirror in IRC today and realized that I haven’t blogged about how to do that. Its funny sometimes how topics pop up, and something I’ve been using for months never made it onto the blog. In any event, below I’ll outline how to create your own Ubuntu repository mirror–great for consolidating and saving bandwidth for multiple machines!

Creating the Mirror
To create an Ubuntu repository mirror we’ll use the apt-mirror tool. This can be installed by issuing the following command or clicking the link:

sudo aptitude install apt-mirror

Once this package is installed you’ll need to configure a few items:
1. Where will your mirror be stored?
2. How aggressive will you be about downloading?
3. What do you want to mirror?

To edit these values you’ll want to edit the /etc/apt/mirror.list file. I’ve displayed mine below, and broken it down into the three main sections.

Where Will Your Mirror Be Stored?
I’ve configured my apt-mirror to be stored on an external USB drive. This is defined via the line:

set base_path /media/gurudisk/UBUNTU/MIRROR

This overrides the default value, which stores the data in /var/spool/apt.

How Aggressive Will You Be About Downloading?

This title may be a bit misleading but this is the way I think about it. Technically its the number of download threads you want to use. The higher the number, the more threads, the faster its done. This will depend on your bandwidth connection though. On my home DSL I can’t put this number any higher than 2. In faster locations you’ll be able to put the number much higher. Your milage may vary.

set nthreads 2

What Do You Want To Mirror?
Now, the most important part, is what do you actually want to mirror? The syntax for this section is pretty simple. It looks just like a normal sources.list entry, but for each address you want to mirror. Here is an example of my entry for Ubuntu 8.04, i386:

# Ubuntu 8.04 "Hardy" i386
deb-i386 hardy main restricted universe multiverse
deb-i386 hardy-updates main restricted universe multiverse
deb-i386 hardy-backports main restricted universe multiverse
deb-i386 hardy-security main restricted universe multiverse
deb-i386 hardy-proposed main restricted universe multiverse

If you want amd64 bit mirrored you might add entries like this:

# Ubuntu 8.04 "Hardy" amd64
deb-amd64 hardy main restricted universe multiverse
deb-amd64 hardy-updates main restricted universe multiverse
deb-amd64 hardy-backports main restricted universe multiverse
deb-amd64 hardy-security main restricted universe multiverse
deb-amd64 hardy-proposed main restricted universe multiverse

Notice that I’m mirroring main, restricted, universe and multiverse plus the security, proposed, backports and updates sections. This gives me a complete mirror of everything that would normally be available. If you don’t want/need proposed or backports, etc you can simply remove those lines.

If you want to be able to use your mirror to support network based installations you’ll also need to add the following (depending on your architecture):

deb-amd64 hardy main main/debian-installer
deb-amd64 hardy restricted restricted/debian-installer
deb-amd64 hardy universe universe/debian-installer
deb-amd64 hardy multiverse multiverse/debian-installer


deb-i386 hardy main main/debian-installer
deb-i386 hardy restricted restricted/debian-installer
deb-i386 hardy universe universe/debian-installer
deb-i386 hardy multiverse multiverse/debian-installer

Basically just add the sources.list entry to this file for anything you want to mirror. I also mirror Medibuntu and a few PPA locations. It sure makes for faster installation when I am able to use the LAN as compared to the public tubes.

To keep your mirror updated activate the cron entry in /etc/cron.d/apt-mirror. By default it will try to update your mirror at 4:00am, and it is disabled. To activate it simply uncomment the line and change the 4 to the preferred hour of your choice. Enjoy!

Update: My mirror, including main, restricted, universe, multiverse, -proposed, -backports, -security, Medibuntu and the network installation sections takes up 37G. I do mirror i386 and amd64, so if you just need one architecture you could half-that.


You may also like...