Setting up your own Ubuntu mirror is quite easy thanks to a nifty little tool called apt-mirror. And it’s very rewarding too… super fast installations and the convenience of not needing an internet connection when you want to install most applications. We’ll need a few things to get the job done though - apt-mirror, a high speed internet connection and some 45GB of disk space. It’s more than likely that you won’t need all of it - my mirrors (binaries only) take up about 22GB - but we’d rather not be caught with too little space. I describe how to mirror the Ubuntu 7.10 repositories here in this guide but it can be applied to other versions of Ubuntu… in fact, the instructions here will work with any debian based distribution.
1) Okay, to start things off, let’s tap into the apt-mirror repository. Back up your sources.list file like so:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
This way, if you mess things up badly you can restore from the back up and start all over.
2) Edit the sources.list file like so:
gksudo gedit /etc/apt/sources.list
3) And insert the following on a new line:
deb http://apt-mirror.sourceforge.net/ apt-mirror
4) Let’s update the package index
sudo aptitude update
5) And install apt-mirror
sudo aptitude install apt-mirror
6) Apt-mirror is now nicely set up so let’s tell it what servers to mirror:
sudo cp /etc/apt/mirror.list /etc/apt/mirror.list.old
gksudo gedit /etc/apt/mirror.list
The default configuration will put your downloaded files in the /var/spool/apt-mirror folder but if you’re like me, you probably have a huge partition where you store all kinds of stuff and you’ll want to put the mirror(s) on that partition. The third line (where it says set base_path) is where you set your default download directory (mine is /media/silo/repo). Here’s how my mirror.list file looks like:
############# config ##################
#
set base_path /media/silo/repo
#
# 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 <running host architecture>
set nthreads 20
set tilde 0
#
############# end config ##############
deb http://archive.ubuntu.com/ubuntu gutsy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu gutsy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu gutsy-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu gutsy-security main restricted universe multiverse
clean http://archive.ubuntu.com/ubuntu
I’m mirroring only binary packages but if you want source packages, you should insert the appropriate lines. They usually take the form:
deb-src http://gh.archive.ubuntu.com/ubuntu/ feisty main restricted
7) Now, we need to run apt-mirror for the first time. This is going to take quite a while so be prepared to wait for several hours… seriously, *several* hours.
Don’t worry if you cannot download all the files in one go, apt-mirror can resume downloads (kill it with the Ctrl+C key combination and re-run it when you want to continue). Okay, run apt-mirror like so:
sudo apt-mirror /etc/apt/mirror.list
Right, it took a week but we finally finished the download.
Apt-mirror will tell you how to clean up unnecessary files when it exits… follow those instructions to reclaim some disk space. There are several ways to use your new mirror but we’ll look at two of the most common. The first involves just telling apt the physical location of the mirror on your hard disk and the other involves passing the mirror through a web server - Apache in this case. So let’s get to it.
Method One
I) Edit your sources.list file like so:
gksudo gedit /etc/apt/sources.list
II) And insert the following on a new line:
deb file:<path_to_mirror> gutsy main restricted universe multiverse
Replace <path_to_mirror> with the path to the downloaded files - /media/silo/repo/archive.ubuntu.com/ubuntu, in my case. You have to repeat this for all the other mirrors (gutsy-updates, gutsy-backports, gutsy-security, et cetera). In the end, the entries for your local mirror in /etc/apt/sources.list will resemble this:
deb file:/media/silo/repo/mirror/archive.ubuntu.com/ubuntu gutsy main restricted universe multiverse
deb file:/media/silo/repo/mirror/archive.ubuntu.com/ubuntu gutsy-updates main restricted universe multiverse
deb file:/media/silo/repo/mirror/archive.ubuntu.com/ubuntu gutsy-security main restricted universe multiverse
deb file:/media/silo/repo/mirror/archive.ubuntu.com/ubuntu gutsy-backports main restricted universe multiverse
As long as the entries here reflect the actual folder structure in your repository, nothing should break. Incidentally, you will want to comment out (place # in front of) the lines that point apt to Canonical’s online servers.
III) Update your package index like so:
sudo aptitude update
You can now start installing stuff. Simple, huh?
Method Two
This method is more useful if you want access to the mirror from other machines on your network. In this example, let’s say the machine with the downloaded files is called ithilien on the middle-earth.com network. There’s another machine - gondor - on the same network. I’m going to assume Apache is installed on ithilien.middle-earth.com. Hey, if you haven’t installed Apache, you have all the packages from the Ubuntu servers on your hard disk… follow Method One and install Apache like so:
sudo aptitude install apache2
Okay let’s roll.
i) We need to tell the Apache server on ithilien.middle-earth.com where to find the downloaded files:
ln -s /media/silo/repo/mirror/archive.ubuntu.com/ubuntu /var/www/ubuntu
If you’ve not tinkered with Apache’s configuration files, /var/www is usually the default virtual host.
ii) Right, now let’s make sure gondor.middle-earth.com can see our beautifully set up mirror. Edit the sources.list file on gondor.middle-earth.com like so:
gksudo gedit /etc/apt/sources.list
And insert the following on a new line:
deb http://ithilien.middle-earth.com/ubuntu gutsy main restricted universe multiverse
Alternatively, I could use ithilien’s IP address, in which case the above line would look like so:
deb http://192.168.3.144/ubuntu gutsy main restricted universe multiverse
Create similar lines for the other mirrors (gutsy-updates, gutsy-security, gutsy-backports, et cetera) and remember to comment out (place # in front of) the lines that point apt to Canonical’s online servers.
iii) Let’s update gondor’s package index:
sudo aptitude update
That’s it! Install as much as you can use. ![]()
Tags: APT, apt-mirror, aptitude, debian, ubuntu