local apt-mirror for debian stretch

If you have more debian systems in your LAN, it makes sense to use apt-mirror or apt-cacher-ng to run your own repository. This help’s to speed up your installs and upgrades and save’s bandwidth when you need it.

apt-mirror downloads all specified repository’s and mirrors them locally. So you will have them available in case of problems with your ISP connection and at greater speeds. Disadvantage: It takes a lot of space to have all packages stored. You probably only need a fraction of the packages downloaded.

Apt-Cacher NG is a caching proxy for downloading packages from Debian-style software repositories.

Often ISP’s or hosting provider already do this for their customers. For example Hetzner has instructions on his wiki, to use their apt-mirror.

I went for the apt-mirror in this tutorial and also use it for my home-lab.

There are only two packages needed without complicate configuration. apt-mirror and apache

root@apt:~# apt-get install apt-mirror

Then edit the mirror.list config file.

root@apt:~# vi /etc/apt/mirror.list

 

In my case i wanted to store the repository on an external disk which was mounted on /mnt/apt-mirror. So it’s necessary to uncomment and edit the path related settings to enable a different path.

root@apt:~# cat /etc/apt/mirror.list 
############# config ##################
#
# set base_path /var/spool/apt-mirror
set base_path /mnt/apt-mirror
#
 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 postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads 20
set limit_rate 100k
set _tilde 0
#
############# end config ##############

deb-amd64 http://ftp.at.debian.org/debian stretch main contrib non-free
deb-amd64 http://ftp.at.debian.org/debian stretch-updates main contrib non-free

clean http://ftp.at.debian.org/debian

The settings for limit_rate and nthreads are multiplied and define how much maximum bandwidth can be used by apt-mirror to download the packages.

20 threads x 100 kByte/s => 2000 kB/s => 16 Mbit/s

I want to mirror the distribution stretch only,  stretch(stable) and stretch-updates repository with components main, contrib and non-free. It’s a common recommendation to not mirror security updates. They can be mirrored but should be downloaded directly.

if you do apt-pinning, you need to skip the clean afterwards.

Run apt-mirror to initally download the archive.

root@apt:~# apt-mirror
Downloading 60 index files using 20 threads...
Begin time: Fri Jul 21 20:36:55 2017
[20]... [19]... [18]... [17]... [16]... [15]...

This will take some hours until everything is fetched from the source repository.

When the download is finished, we will make the repository available via http to our other Debian hosts.

root@apt:~# apt-get install apache2

Apache should create a default vhost in /etc/apache2/sites-available with a DocumentRoot at /var/www/html

root@apt:/etc/apache2/sites-available# ls
000-default.conf default-ssl.conf

So delete the index.html and place a link which points to your local repository.

ln -s /mnt/apt-mirror/mirror/ftp.at.debian.org/debian /var/www/html/debian

Cron the step “apt-mirror” at least once a day, to fetch all updates to your repository. For example in the night, where your Internet Connection should be less in use.

That’s it. Now you can use your own Repository in your LAN. Just update the sources.list on your hosts and replace with your hostname or IP.

As there are no numbers available for the size of a single release and amd64-only, i share here what i have for the size of my mirror.

root@apt:/mnt/apt-mirror# du -hd1
61G ./mirror
145M ./var
138M ./skel
61G .

 

Comments are closed.