How To Create A Local Debian/Ubuntu Mirror With apt-mirror - Page 2

5 Create The Local Repositories

Now that apt-mirror is configured, it's time to run it for the first time and download all the packages that form the local Debian and Ubuntu repository. All we have to do is type

su - apt-mirror -c apt-mirror

apt-mirror tells you how many GB it must download. This can take a few hours, so be patient. The packages will be stored in subdirectories of the /var/spool/apt-mirror/mirror directory, so make sure the partition that holds that directory has enough disk space left.

The Debian repository will be in /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian, and the Ubuntu repository will be in /var/spool/apt-mirror/mirror/de.archive.ubuntu.com/ubuntu. If you used different mirrors in chapter 4, the paths will be a little bit different for you.

 

6 Clean Up The Local Repositories

After apt-mirror has finished downloading all packages, it will most likely tell you can free up some disk space with the /var/spool/apt-mirror/var/clean.sh script. That's what we do now:

/bin/bash /var/spool/apt-mirror/var/clean.sh

The output will look like this:

server1:~# /bin/bash /var/spool/apt-mirror/var/clean.sh
Removing 157 unnecessary files [13316096 bytes]...
[0%]................done.

Removing 18 unnecessary directories...
[0%]..................done.

As you see, some MB have been freed.

 

7 Update The Local Repositories / Create A Daily Cron Job

Updating the local mirror is easy. Simply run

su - apt-mirror -c apt-mirror

again.

If you don't want to do it manually, you can create a daily cron job for it. Simply edit /etc/cron.d/apt-mirror and uncomment the last line in it so that it looks like this:

vi /etc/cron.d/apt-mirror

#
# Regular cron jobs for the apt-mirror package
#
0 4     * * *   apt-mirror      /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log

This will make apt-mirror run at 4.00h each day, and it will log to /var/spool/apt-mirror/var/cron.log.

 

8 Make The Local Mirrors Accessible Over HTTP

The default Apache document root under Debian and Ubuntu is /var/www, but our repositories are stored in /var/spool/apt-mirror/mirror. In order to make our repositories accessible by http://192.168.0.100/debian and http://192.168.0.100/ubuntu (in this tutorial 192.168.0.100 is the IP address of our local mirror), we create the symlinks /var/www/debian and /var/www/ubuntu that point to the real repositories:

ln -s /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian /var/www/debian
ln -s /var/spool/apt-mirror/mirror/de.archive.ubuntu.com/ubuntu /var/www/ubuntu

Remember to adjust these commands if you use different mirrors than ftp.de.debian.org and de.archive.ubuntu.com.

The next thing to consider is that you can refer to Debian Sarge as sarge, but also as stable (at the time of this writing Debian Sarge is stable and the upcoming Debian Etch still testing). When you run

ls -l /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists

you will see that there is a directory called sarge, but not stable. If you use stable instead of sarge in /etc/apt/sources.list or install a new Debian system with the local mirror, this is a problem (the Debian Sarge installer also refers to stable instead of sarge). The solution is to create a symlink:

cd /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists
ln -s sarge/ stable

Remember to adjust this command if you use a different mirror than ftp.de.debian.org.

At the time Debian Etch becomes stable and you decide to mirror Etch as well, don't forget to change the stable symlink, e.g. like this:

cd /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists
rm -f stable
ln -s etch/ stable

We don't have this problem with Ubuntu as there's no stable, only breezy, dapper, edgy, etc.

Share this page:

20 Comment(s)

Add comment

Comments

From: at: 2007-10-25 17:38:25

If you have both 32bit (i386) and 64 bit (amd64) you can have apt-mirror get the packages for both architectures. Just add the architecture after deb on each line.

Example:

deb-amd64 http://ftp.osuosl.org/pub/ubuntu gutsy main restricted universe multiverse

deb-i386 http://ftp.osuosl.org/pub/ubuntu gutsy main restricted universe multiverse

 

From: Anonymous at: 2012-02-10 15:42:59

Thanks for the info. We just create a repo.

 

Thanks,
Ivu Loto Team

From: TCPMeta at: 2014-07-11 15:43:42

I followed your guide to the T for the mirror portion. I am also using the mirror as a PXE server to load the debian install image. My clients do not like the mirror. I select HTTP and point it to my server's IP 192.168.1.100, point it to /debian/ and it asks what version I want and after I select Wheezy it fails. Might give it a shot with FTP next.

From: at: 2007-11-21 11:09:09

Note that su - apt-mirror -c apt-mirror will not work on Ubuntu if you have not set a root password. But sudo apt-mirror -c apt-mirror will always give:

apt-mirror: invalid config file specified at /usr/bin/apt-mirror line 101.

There is almost NO information regarding this error but found that the ArsGeek  Blog uses sudo apt-mirror /etc/apt/mirror.list which works perfectly! Only way I could start downloading the repo's.

From: Anonymous at: 2009-01-18 02:04:05

sudo su - apt-mirror -c apt-mirror

From: aussieseb at: 2009-06-03 14:34:20

This worked for me on ubuntu 9.04

sudo apt-mirror

Downloading 48 index files using 20 threads...
Begin time: Thu Jun  4 00:22:02 2009
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Thu Jun  4 00:25:19 2009

Proceed indexes: [PPP]

24.2 GiB will be downloaded into archive.
Downloading 27083 archive files using 20 threads...
Begin time: Thu Jun  4 00:25:23 2009
[20]... 

From: Anonymous at: 2009-07-10 09:10:04

sudo chown -R apt-mirror /var/spool/apt-mirror

# to be sure that user apt-mirror is the owner

sudo chmod -R u+w /var/spool/apt-mirror

# to be sure that user apt-mirror has write access

sudo -u apt-mirror apt-mirror

# to launch the command apt-mirror as user apt-mirror

 

 

From: nbensa at: 2009-07-31 20:01:31

Hello,

how do I  configure apt-mirror to mirror more than one architecture? Is it even possible?

 Thanks!

 

From: Anonymous at: 2009-12-20 21:53:18

Hi, yes you can have multiple architectures. I use apt-mirror to mirror the current ubuntu release with i386 and the proxmox repos with amd64. Simply use deb-amd64 instead of deb in the mirror list file. Niels

From: Anonymous at: 2009-08-31 09:46:52

nbensa I had the same problem as you. By typing sudo apt-mirror the command executed for me but for some reason the command with -c in it in the tutorial didn't work for me..

From: at: 2008-03-08 22:20:07

Wow. This is extensive. I've only got one question (not asking for help, just clarification).

When downloading, say, for Ubuntu's Gutsy repositories (this one was designed for Edgy, but it's all the same) does apt-sources download all the architectures (i386, amd64, powerpc and sparc) as well?

I don't see any text that just calls for a single one such as just i386.

From: Anonymous at: 2008-10-17 16:31:15

add this to you /etc/apt/mirrors.list

set defaultarch  i386

From: CyberCowboy at: 2009-10-20 21:08:57

How would you do multiple architectures, for me specifically I need x64 and i386

From: AtesComp at: 2009-12-14 17:12:19

You use "deb-i386" and "deb-amd64" instead of just "deb" at the beginning of each mirror line.  Examples:

deb-i386 http://us.archive.ubuntu.com/ubuntu karmic main restricted universe multiverse
deb-amd64 http://us.archive.ubuntu.com/ubuntu karmic main restricted universe multiverse

From: Dan at: 2010-05-12 01:55:31

I had a question.  My apt repository is located at

/var/spool/apt-mirror/mirror/ftp.us.debian.org/debian/pool

and it contains contrib main and non-free packages

 The thing I cannot figure out is I am working with a pool and not a specific dist.

How would I setup my Debian lenny clients to pull in my needed packages since the examples above seem to be for a specific distro if you understand what I mean?

The pool is confusing me.

Thanks,

Dan

From: Anonymous at: 2010-07-31 08:45:45

When you specify a dist, that tells is what packages list to read (arranged by dist and architecture).

 These package list tell it what packages to read from the pool.  Apt-mirror will only download the specified packages, but have a browse around one of the primary mirrors.  It is logically laid out, and explains a lot about the working of apt.

 So, pool/ contains all the packages, and dists/ contains lists of packages.

From: Rebeca at: 2011-03-15 19:05:56

in my case, I mirrored the three last versions of ubuntu. apt-mirror has created the pool but did not create the folder /dists... so my local computers are unable to pull from the mirror in sources.list. what i did wrong? and how fix that? Thanks..and sorry my "google english"!

From: Joe at: 2014-07-30 18:10:29

I have the same question as the previous comment, after running apt-mirror I only have the ubuntu/pool directory, I don't have ubuntu/dists and such.  This causes clients to fail apt-get update when they cannot find files. What would cause that and how do you fix it?

From: Anonymous at: 2010-12-13 03:40:41

Thanks for the write up!

From: Anonymous at: 2012-05-01 18:29:42

i followed the procedure in this doc. 

the apt-get update and apt-get upgrade works fine in the client server.

but the do-release-upgrade always complain there is no new release found.

but i did put the 10.04/10.10/11.04... in the mirror-list file.

and i did edit the /etc/update-manager/meta-release file.