Installing A Local Debian Mirror
A local software mirror can be very useful if you are on a slow/metered connection or if you are managing hundreds of systems at the edge. A local mirror can also be useful for delaying the packages that are released to your fleet until after QA testing has completed as well as allowing you to maintain a copy of packages that are no longer available on public mirrors. The instructions below will guide you through setting up a local mirror on Debian Bullseye using apt-mirror.
First you will need to install required packages. We are installing the apt-mirror package to do the synchronizations and we are installing apache2 as the web server to host these updates on the Local Area Network (LAN).
Install Packages
sudo apt -y install apache2 apt-mirror
Create the data directory.
sudo mkdir /data
Create the mirror user.
sudo /usr/sbin/useradd mirror
Set the permissions for the data directory to the mirror user.
sudo chown -R mirror:mirror /data/apt-mirror/
Edit the mirror list to include the distributions that you would like to have a local miirror of. This file is located at /etc/apt/mirros.list
deb http://ftp.us.debian.org/debian unstable main contrib non-free
deb-src http://ftp.us.debian.org/debian unstable main contrib non-free
deb http://ftp.us.debian.org/debian buster main contrib non-free
deb-src http://ftp.us.debian.org/debian buster main contrib non-free
deb http://ftp.us.debian.org/debian jessie main contrib non-free
deb-src http://ftp.us.debian.org/debian jessie main contrib non-free
Run the initial mirror synchronization. We will use screen to hold the session so the mirror does not stop downloading if we disconnect
sudo su mirror
screen
apt-mirror /etc/apt/mirror.list
References & Further Reading