LocalRepositoriesHowto

If you’ve got a little bit of bandwidth and a bunch of Ubuntu machines to update, it’s almost a no-brainer to set up your own local ubuntu repositories.

I’ve got my own repositories set up and it makes for an incredibly fast install of a new system and updates for existing systems.

What you’ll need is a high speed connection and about 40GB of disk space on a current Ubuntu install. I’ve got my repositories on an older machine runing Ubuntu 6.06. The mirrors are for Edgy.

How to set it up? I use a neat tool called apt-mirror. Here’s how to install it.

Do this on a machine that has at least 40 GB of free disk space. You probably won’t use that much but it’s better safe than out of space. Also this tutorial is for Ubuntu but it’s easily modified for Debian or other debian based installs.

First, we’re going to modify our current sources.list to include the repository for apt-mirror. In a terminal session:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

gksudo gedit /etc/apt/sources.list

Now add this to the bottom of your sources.list file.

deb http://apt-mirror.sourceforge.net/ apt-mirror

Save your sources.list file and do this in a terminal session:

sudo apt-get update
sudo apt-get install apt-mirror

Now you’ve got apt-mirror installed, let’s configure it. Back in a terminal session type:

gksudo gedit /etc/apt/mirror.list

Here’s where you can enter the repositories that your local mirror will get all of it’s sources and debs from.

I personally mirror a whole bunch of stuff. Here’s what my mirror.list file looks like. Feel free to modify it to include or exclude what you will. Also, you may be able to find a closer and thus faster repository site. If you’re in the US, you could try us.archive.ubuntu.com.

#set base_path /var/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 ##############

deb http://archive.ubuntu.com/ubuntu edgy main restricted universe
multiverse
deb http://archive.ubuntu.com/ubuntu edgy-updates main restricted
universe multiverse
deb http://archive.ubuntu.com/ubuntu edgy-backports main restricted
universe multiverse
deb http://archive.ubuntu.com/ubuntu edgy-security main restricted
universe multiverse
deb http://archive.ubuntu.com/ubuntu edgy-proposed main restricted
universe multiverse

deb-src http://archive.ubuntu.com/ubuntu edgy main restricted universe
multiverse
deb-src http://archive.ubuntu.com/ubuntu edgy-updates main restricted
universe multiverse
deb-src http://archive.ubuntu.com/ubuntu edgy-backports main restricted
universe multiverse
deb-src http://archive.ubuntu.com/ubuntu edgy-security main restricted
universe multiverse
deb-src http://archive.ubuntu.com/ubuntu edgy-proposed main restricted
universe multiverse

clean http://archive.ubuntu.com/ubuntu

Now to run it for the first time. This will take some time as it’s going to download a whole ton of stuff! Make sure you budget at least a few hours for this.

sudo apt-mirror /etc/apt/mirror.list

Phew. Once that’s done you’ll get some instructions on how to clean up unneeded files. Follow those. They’ll probably ask you to run the below command, but double check with your output.

sudo /var/spool/apt-mirror/var/clean.sh

This is a great way to start. Let’s set up apt-mirror to check every night for new additions so you’ll always get the latest updates. To do this we’re going to modify a file thoughtfully provided by apt-mirror.

gksudo gedit /etc/cron.d/apt-mirror

Uncomment the last line (remove the #) and your repositories will update at 4am every day.

Now, how do you access your newly formed mirror? The easiest way I’ve found is through Apache, a great web server. Let’s install that now.

sudo apt-get install apache2

Now that you’ve got a web server installed, let’s make a link so that apache will know where to look to serve out your mirror.

ln -s /var/spool/apt-mirror/mirror/archive.ubuntu.com/ubuntu /var/www/ubuntu

Wow. You’re mirror is set up and you should now be able to reach it by going to yourcomputer.yourdomain.whatever/ubuntu. If you’re computer was called tribble and you onwed startrek.net, then it would be tribble.startrek.net/ubuntu.

For purposes of this example, I’ve got this installed on a machine called Arsgeek. It’s located at Arsgeek.com. (Not really, so trying to get your updates from here will be pointless.) If I wanted to reach it, I’d use the following address:

http://arsgeek.arsgeek.com/ubuntu

So to set up a machine to use my the new mirror, you’ll want to first back up and then edit your /etc/apt/sources.list file.

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

gksudo gedit /etc/apt/sources.list

Now, with the mirrors I’ve set up you can add the following repository based on my bogus example of arsgeek.arsgeek.com

deb http://arsgeek.arsgeek.com/ubuntu edgy main restricted universe
multiverse

And a lot more. Depending on what you’re mirroring on your local mirror, you can add a whole bunch of repositories. Feel free to go through your sources.list file and change the default (http://archive.ubuntu.com/ubuntu) to your local mirror’s address.

UbuntuMagazine/HowTo/LocalRepositoriesHowto (last edited 2008-08-06 17:00:20 by localhost)