Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old November 1st, 2007   #1
bmk789
5 Cups of Ubuntu
 
bmk789's Avatar
 
Join Date: Sep 2005
Location: Indiana, USA
Beans: 38
Ubuntu 7.10 Gutsy Gibbon
Send a message via AIM to bmk789 Send a message via MSN to bmk789 Send a message via Yahoo to bmk789 Send a message via Skype™ to bmk789
Lightbulb HOWTO: Setup Local Repository Mirror

If your like me, you and your friends have several machines running Ubuntu, Kubuntu, or other *buntu variants. After going through upgrades of all these machines, it can eat a lot of your and Canonical's bandwidth to download all the packages for each machine. There are other solutions such as apt-proxy, apt-cacher, etc. But what works best for me is apt-mirror, which creates a mirror of any Ubuntu, Debian, or any other deb repository. So if you have 20+ GB of hard drive space, you can setup a local repository mirror to speed up the upgrading process and save Canonical some bandwidth.

Step 1: Install apt-mirror

Code:
sudo apt-get install apt-mirror
(Universe repository needed)

Step 2: Configure apt-mirror

Configuring apt-mirror is fairly simple. We just need to modify the /etc/apt/mirror.list file.

Ubuntu users:
Code:
gksudo gedit /etc/apt/mirror.list
Kubuntu users:
Code:
kdesu kate /etc/apt/mirror.list
Ubuntu server users:
Code:
sudo nano /etc/apt/mirror.list
Here's my sample mirror.list configuration:
Code:
# apt-mirror configuration file

##
## The default configuration options (uncomment and change to override)
##
#
set base_path    /var/spool/apt-mirror
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
#set var_path     $base_path/var
set defaultarch  i386
set nthreads     5
#


##
## Sources
##
deb http://archive.ubuntu.com/ubuntu/ gutsy main restricted
deb http://archive.ubuntu.com/ubuntu/ gutsy-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ gutsy universe
deb http://archive.ubuntu.com/ubuntu/ gutsy-updates universe
deb http://archive.ubuntu.com/ubuntu/ gutsy multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu gutsy partner
deb http://security.ubuntu.com/ubuntu gutsy-security main restricted
deb http://security.ubuntu.com/ubuntu gutsy-security universe
deb http://security.ubuntu.com/ubuntu gutsy-security multiverse
deb http://archive.ubuntu.com/ubuntu/ gutsy-proposed restricted main multiverse universe
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy main restricted
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy-updates main restricted
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy universe
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy-updates universe
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy multiverse
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy-updates multiverse
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy-backports main restricted universe multiverse
deb-amd64 http://archive.canonical.com/ubuntu gutsy partner
deb-amd64 http://security.ubuntu.com/ubuntu gutsy-security main restricted
deb-amd64 http://security.ubuntu.com/ubuntu gutsy-security universe
deb-amd64 http://security.ubuntu.com/ubuntu gutsy-security multiverse
deb-amd64 http://archive.ubuntu.com/ubuntu/ gutsy-proposed restricted main multiverse universe
clean http://archive.ubuntu.com/ubuntu
clean http://archive.canonical.com/ubuntu
clean http://security.ubuntu.com/ubuntu
This configuration mirrors all of Ubuntu's repositories for i386 and AMD64 architectures and stores them all in /var/spool/apt-mirror. If you don't need to mirror AMD64, just take all the deb-amd64 lines out of the above configuration and it will only download all the i386 repositories.

NOTE: Make SURE whatever partition stores your /var/spool directory has plenty of space. Trust me, you do NOT want to download 17GB and find out your partition doesn't have enough space. If you use a separate /home partition with storage capacity you want to use for apt-mirror, you can do what I did by creating a /home/apt-mirror and making /var/spool/apt-mirror link to it. That can be done with these two commands:
Code:
ONLY DO THIS IF YOU HAVE THE SAME SITUATION AS ABOVE!
TYPICAL USERS WONT NEED THIS
sudo mkdir /home/apt-mirror
sudo rm -Rf /var/spool/apt-mirror
sudo ln -s /home/apt-mirror /var/spool/apt-mirror
Step 3: Run apt-mirror
To have apt-mirror start downloading the repositories, run:
Code:
sudo apt-mirror /etc/apt/mirror.list
I recommend running this command overnight, as it will take several hours depending on your connection speed and what you setup to mirror. For example, my server is mirroring with the above configuration and downloaded around 35-40GB for i386 and AMD64. This took between 4-10 hours over my 10mbps cable connection.

Step 4: Install apache
For you to be able to use this local mirror normally, you will need a web server to share the directories. In this guide, I will use apache, but you may prefer to use lighthttpd or some other server.
Code:
sudo apt-get install apache2
Step 5: Setup links
We need to now link our local repository folder to our shared apache directory.
Code:
sudo ln -s /var/spool/apt-mirror/mirror/archive.ubuntu.com /var/www/archive-ubuntu
sudo ln -s /var/spool/apt-mirror/mirror/archive.canonical.com /var/www/archive-canonical
sudo ln -s /var/spool/apt-mirror/mirror/security.ubuntu.com /var/www/security-ubuntu
Step 6: Set apt to use local mirror
In this step, we'll edit the /etc/apt/sources.list file and replace Ubuntu's repositories with our local mirror.
First, make a backup of the default sources.list.
Code:
sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
sudo nano /etc/apt/sources.list
This should open a blank file wherein we will paste the following:
Code:
deb http://127.0.0.1/archive-ubuntu/ubuntu gutsy main restricted universe multiverse
deb http://127.0.0.1/archive-ubuntu/ubuntu gutsy-updates main restricted universe multiverse
deb http://127.0.0.1/archive-ubuntu/ubuntu gutsy-backports main restricted universe multiverse
deb http://127.0.0.1/security-ubuntu/ubuntu gutsy-security main restricted universe multiverse
deb http://127.0.0.1/archive-canonical/ubuntu gutsy partner
Then press Ctrl+X then y to save and close the file.
Next, we need to update the repositories to make sure everything is working as expected.
Code:
sudo apt-get update
This should run the same as before we changed the file. Any errors will need to be addressed. Post a reply if you have any errors here.

You should also use this step on other machines you want to setup to use this mirror. You will just need to replace the 127.0.0.1 with the LAN address for machines over LAN or public IP for other machines over the net.

If you have questions, comments, suggestions, feel free to reply, send me a message on IRC (bmk789 on freenode), or send me an email (bmk789@gmail.com)
bmk789 is offline   Reply With Quote
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:12 PM.


vBulletin ©2000 - 2009, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry