Add an Ubuntu Repository Mirror to Your LAN

My mirror currently runs on a local server using the Lighttpd package. I have also used Apache2 and Boa, both work but I switched to Lighttpd because I want to use the same package here that I’m using on my Pogoplug.

Lighttpd

So, begin by installing Lighttpd:

sudo apt-get install lighttpd

Now create the directory where you are planning to hold your mirror as well as the required sub-directories. The default location is /var/www, but remember you are building an Ubuntu repository which is in the vicinity of 80gb per release. In my case I’m hosting three, Lucid, Maverick and Natty which means I need about 240gb. My case the server has a single 640gb disk with about 16gb for the root partition and the remainder for my /home partition. Clearly my root partition doesn’t have the space for my mirror so I keep it in the /home partition.

So

sudo mkdir /home/debian
sudo mkdir /home/debian/spool
sudo mkdir /home/debian/spool/apt-mirror
sudo mkdir /home/debian/spool/apt-mirror/mirror
sudo mkdir /home/debian/spool/apt-mirror/var
sudo mkdir /home/debian/spool/apt-mirror/skel

And then create a symbolic link to your directory in /var/www

sudo ln -s /home/debian /var/www/debian

The next step is to set up a virtual host in Lighttpd pointing to your repository. To accomplish that:

sudo cp /etc/lighttpd/lighttpd.conf /etc/lighttpd.conf.stock
/etc/gksudo gedit /etc/lighttpd/lighttpd.conf

and add the following lines to the end of the file.

#
# This handles my apt-mirror ... a symlink in /var/www/debian points to the actual location
$HTTP["host"] == "debian.turriehome.com" {
  server.document-root = "/var/www/debian"
  alias.url = ( "/debian" => "/var/www/debian" )
}

Then save, exit gedit and

sudo /etc/init.d/lighttpd restart
Finally, restart lighttpd once more:

    /etc/init.d/lighttpd restart

If you’ve setup a local domain names erver to point to your site you should be able to call up you site with your browser.

Otherwise you should be able to call it up from your browser at:

http://your-mirrors-ip-address/mirror

If all is well you should see something like this:

At that point you are ready to install apt-mirror which will fetch the repositories you want on your mirror.

sudo apt-get install apt-mirror

Then open the configuration file


cp /etc/apt/mirror.list /etc/apt/mirror.list.stock
gksudo gedit /etc/apt/mirror.list

here is my mirror.list

############# apt-mirror config ##################
#
# tell apt-mirror where to put your repositories
#
set base_path    /home/debian/spool/apt-mirror
#
# 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
# set defaultarch  
set nthreads     20
set _tilde 0
#
############# end config ##############

############# Begin Debian ##############
#
# leftover from when I had a mirror for Debian Lenny--remove pound signs to activate
#
#deb http://ftp.us.debian.org/debian lenny main contrib non-free 
#deb-src http://ftp.us.debian.org/debian lenny main contrib non-free

# security updates is always good thing to install

#deb http://security.debian.org/debian-security lenny/updates main contrib non-free
#deb-src http://security.debian.org/debian-security lenny/updates main contrib non-free


#deb http://ftp.us.debian.org/debian lenny main/debian-installer

# deb http://kde4.debian.net/ lenny main

#clean http://ftp.us.debian.org/debian
# clean http://kde4.debian.net/
#clean http://security.debian.org/
############# End Debian ##############

############# Begin Ubuntu 10.04##############
# 10.04 packages including main, restricted, universe, multiverse for base, updates, security, proposed and backports
deb http://us.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid main restricted
deb http://us.archive.ubuntu.com/ubuntu/ lucid universe multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid universe multiverse
# 10.04 updates
deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb http://us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
# 10.04 Security
deb http://security.ubuntu.com/ubuntu lucid-security main restricted
deb-amd64 http://security.ubuntu.com/ubuntu lucid-security main restricted
deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted
deb http://security.ubuntu.com/ubuntu lucid-security universe
deb-amd64 http://security.ubuntu.com/ubuntu lucid-security universe
deb-src http://security.ubuntu.com/ubuntu lucid-security universe
deb http://security.ubuntu.com/ubuntu lucid-security multiverse
deb-amd64 http://security.ubuntu.com/ubuntu lucid-security multiverse
deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse
# 10.04 backports
deb http://us.archive.ubuntu.com/ubuntu/ lucid-backports main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-backports main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-backports main restricted
deb http://us.archive.ubuntu.com/ubuntu/ lucid-backports universe
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-backports universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-backports universe
deb http://us.archive.ubuntu.com/ubuntu/ lucid-backports multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-backports multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-backports multiverse

# 10.04 proposed
deb http://us.archive.ubuntu.com/ubuntu/ lucid-proposed main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-proposed main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-proposed main restricted
deb http://us.archive.ubuntu.com/ubuntu/ lucid-proposed universe
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-proposed universe
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-proposed universe
deb http://us.archive.ubuntu.com/ubuntu/ lucid-proposed multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ lucid-proposed multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-proposed multiverse

#10.04 other
deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu lucid main
#
# 10.10 packages including main, restricted, universe, multiverse for base, updates, security, proposed and backports
# 10.10 main
deb http://us.archive.ubuntu.com/ubuntu/ maverick main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick main restricted
deb http://us.archive.ubuntu.com/ubuntu/ maverick universe multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick universe multiverse
# 10.10 updates
deb http://us.archive.ubuntu.com/ubuntu/ maverick-updates main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-updates main restricted
deb http://us.archive.ubuntu.com/ubuntu/ maverick-updates universe
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-updates universe
deb http://us.archive.ubuntu.com/ubuntu/ maverick-updates multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-updates multiverse
# 10.10 Security
deb http://security.ubuntu.com/ubuntu maverick-security main restricted
deb-amd64 http://security.ubuntu.com/ubuntu maverick-security main restricted
deb-src http://security.ubuntu.com/ubuntu maverick-security main restricted
deb http://security.ubuntu.com/ubuntu maverick-security universe
deb-amd64 http://security.ubuntu.com/ubuntu maverick-security universe
deb-src http://security.ubuntu.com/ubuntu maverick-security universe
deb http://security.ubuntu.com/ubuntu maverick-security multiverse
deb-amd64 http://security.ubuntu.com/ubuntu maverick-security multiverse
deb-src http://security.ubuntu.com/ubuntu maverick-security multiverse
# 10.10 backports
deb http://us.archive.ubuntu.com/ubuntu/ maverick-backports main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-backports main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-backports main restricted
deb http://us.archive.ubuntu.com/ubuntu/ maverick-backports universe
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-backports universe
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-backports universe
deb http://us.archive.ubuntu.com/ubuntu/ maverick-backports multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-backports multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-backports multiverse

# 10.10 proposed
deb http://us.archive.ubuntu.com/ubuntu/ maverick-proposed main restricted
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-proposed main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-proposed main restricted
deb http://us.archive.ubuntu.com/ubuntu/ maverick-proposed universe
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-proposed universe
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-proposed universe
deb http://us.archive.ubuntu.com/ubuntu/ maverick-proposed multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu/ maverick-proposed multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-proposed multiverse

#cleanup
clean http://us.archive.ubuntu.com/ubuntu
clean http://security.archive.ubuntu.com/ubuntu

Please note, my repository mirrors 3 complete Ubuntu distributions, Lucid, Maverick, and Natty. I don’t necessarily recommend this. I’ll delete Lucid and Maverick as soon as I’ve migrated all of my systems to Natty. This will mean deleting the Lucid and Maverick directories from the mirror and removing the corresponding lines from mirror.list. If you do not want all three releases I suggest you delete those lines now or comment them out by adding a # at the beginning of each line you do not want.

Now you are ready to run apt-mirror the first time:

sudo apt-mirror

This will take many hours to complete the first time, don’t be surprised if it takes more than a full day. After your repository is loaded, only two things remain, telling your other systems where to find your mirror, and scheduling apt-mirror to fetch updates periodically.

To tell your other systems where to find your mirror, use gedit on those systems:

cp /etc/apt/sources.list /etc/apt/sources.list.stock
gksudo gedit /etc/apt/sources.list

Change your file to look something like this:

deb http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid universe
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid universe
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid-updates universe
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid multiverse
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid multiverse
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/us.archive.ubuntu.com/ubuntu/ lucid-updates multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://us.archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse
# deb-src http://us.archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
deb http://archive.canonical.com/ubuntu lucid partner
deb-src http://archive.canonical.com/ubuntu lucid partner

deb http://your-mirror-ip-address/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu lucid-security main restricted
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu lucid-security main restricted
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu lucid-security universe
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu lucid-security universe
deb http://your-mirror-ip-address/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu lucid-security multiverse
deb-src http://your-mirror-ip-address/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu lucid-security multiverse

Save the file and then test your mirror using:

sudo apt-get update

Assuming everything works, you should schedule apt-mirror to fetch updates periodically–say once a week. The apt-mirror program needs to run as root. One way to do this is to schedule it in the /etc/crontab file.

gksudo gedit /etc/crontab

and add a lines similar to the following to the end of the file:

# m h dom mon dow user	command 
# this runs apt-mirror and then clean.sh at 15 minutes past 2 AM, every week, every month, on Wednesday
15 02 * * 3 root  apt-mirror && cd /media/disk1/debian/spool/apt-mirror/var && .clean.sh

The lines shown will run apt-mirror on Wednesday (day 3) starting at 2:15 AM. When apt-mirror finishes, the script changes directory and runs a cleanup script (clean.sh).

Advertisements
  1. Hi, many thanks for sharing your opinions in Add an Ubuntu Repository Mirror to Your LAN Ubuntu&Pogoplug howtos. This is actually an awesome blog.

  2. fantatsic.. Will try this sometime. I have more than 140 Ubuntu computers running on Precise

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: