How to create a mirror server - for local (network) use with Debian 12, to update Debian, Ubuntu and Mint?

nettux

New Member
Joined
Jul 27, 2020
Messages
6
Reaction score
2
Credits
41
Guys.
I am creating a server (using Debian 12) to update VMs and terminals (PC's) that have Debian 12, Ubuntu and Mint, locally, to avoid consuming traffic during working hours.
And all the tutorials I tried didn't help.
If anyone can help me, I'd appreciate it!
 


Could someone please walk us trough, step by step, I've made several attempts to create an apt mirror, using rsync apt-mirror and ftpsync. I've asked chatgpt with no success. I've tried to use a "Trixie" Debian because someone said, that the newer apt-mirror package would work. I really don't ask often to get spoonfeeded, bit here I am lost. Walk us please trough the steps. so that I just have to enter my apt-mirror server to /etc/sources.list and can install my software.
 

This assumes you already have a web server like nginx or apache running.

1. Install apt-mirror​

First, ensure your system is up to date:
Code:
 sudo apt update
Then, install the apt-mirror package:
Code:
 sudo apt install apt-mirror

2. Configure apt-mirror​

Edit the configuration file /etc/apt/mirror.list to specify the repositories you want to mirror. Open the file with your preferred text editor:
Code:
 sudo nano /etc/apt/mirror.list
Here’s an example configuration for Ubuntu 22.04:
Code:
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 cleanscript $var_path/clean.sh 
set defaultarch amd64 set nthreads 20 set _tilde 0

deb http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse

clean http://archive.ubuntu.com/ubuntu

Adjust the URLs and distribution names according to your needs.

3. Run apt-mirror​

To start the mirroring process, simply run:
Code:
 sudo apt-mirror
This will download the specified repositories to your local machine.

4. Serve the mirrored repository​

You can use a web server like Apache to serve the mirrored repository. Install Apache:
Code:
 sudo apt install apache2
Create a symbolic link to the mirror directory in the web server’s root directory:
Code:
 sudo ln -s /var/spool/apt-mirror/mirror /var/www/html/ubuntu

5. Configure clients to use the mirror​

On the client machines, edit the /etc/apt/sources.list file to point to your local mirror. For example:
Code:
 deb http://your-server-ip/ubuntu jammy main restricted universe multiverse deb http://your-server-ip/ubuntu jammy-security main restricted universe multiverse deb http://your-server-ip/ubuntu jammy-updates main restricted universe multiverse deb http://your-server-ip/ubuntu jammy-backports main restricted universe multiverse
Replace your-server-ip with the IP address of your server.

6. Update and upgrade​

Finally, update the package list and upgrade the packages on the client machines:
Code:
 sudo apt update sudo apt upgrade

That's it! Your clients should now be able to use the local mirror for package updates.
 
To add custom packages, or create a custom repo.

  1. Install Required Packages: First, you need to install the dpkg-dev package, which includes tools for managing Debian packages.
    Code:
    sudo apt update
    sudo apt install dpkg-dev

  2. Create a Directory for Your Repository: Choose a directory where you will store your .deb files.
    Code:
    mkdir -p /path/to/your/repo
    cd /path/to/your/repo

  3. Add Packages to the Directory: Copy your .deb files into this directory.
  4. Create the Repository Metadata: Use dpkg-scanpackages to generate the necessary metadata files.
    Code:
    dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

  5. Create a Release File: This step is optional but recommended for better repository management.
    Code:
    dpkg-scanpackages . /dev/null > Release

  6. Configure Your Web Server: Make sure your web server is configured to serve the directory where your repository is located.
  7. Add the Repository to Your Sources List: On the client machines, add the repository to the /etc/apt/sources.list file.
    Code:
    deb [trusted=yes] http://yourserver/path/to/your/repo ./

  8. Update and Install Packages: Finally, update the package list and install packages from your new repository.
    Code:
    sudo apt update
    sudo apt install your-package-name
 
okay, I'll spin up a vm and test it. reporting back
 
What is the best option: apt-cacher-ng, debmirror or apt-mirror?
 
From CoPilot.

Choosing the best tool depends on your specific needs and environment. Here's a brief comparison of apt-cacher-ng, debmirror, and apt-mirror to help you decide:

apt-cacher-ng

  • Purpose: Acts as a caching proxy for Debian packages.
  • Use Case: Ideal for environments where multiple machines need to download the same packages, reducing bandwidth usage and speeding up updates.
  • Advantages:
    • Efficient caching mechanism.
    • Supports HTTP and HTTPS repositories.
    • Easy to set up and manage.
  • Disadvantages:
    • Does not create a full mirror of the repository.
    • Limited to caching packages that have been requested by clients.

debmirror

  • Purpose: Creates a partial or full mirror of a Debian repository.
  • Use Case: Suitable for creating a local mirror of specific sections of a repository.
  • Advantages:
    • Flexible in terms of what parts of the repository to mirror.
    • Can mirror only the packages you need.
  • Disadvantages:
    • Requires more configuration compared to apt-cacher-ng.
    • Can consume significant storage if mirroring large sections.

apt-mirror

  • Purpose: Creates a full mirror of a Debian or Ubuntu repository.
  • Use Case: Best for environments where you need a complete local copy of the repository.
  • Advantages:
    • Provides a complete mirror, ensuring all packages are available locally.
    • Useful for isolated networks with no internet access.
  • Disadvantages:
    • Requires significant storage space.
    • Can be overkill if you only need a subset of the repository.

Summary​

  • apt-cacher-ng: Best for reducing bandwidth and speeding up updates in environments with multiple machines.
  • debmirror: Good for creating partial mirrors tailored to your needs.
  • apt-mirror: Ideal for creating a full local mirror of the repository, especially in isolated networks.
 
I hope that VM has a very large hard drive. :cool:



One repo alone can be over 50 gig, all three together... I don't know.
I am just in this moment downloading 247GB of Debian packages alone, could take a while. I tried it numerious times and am pretty sure, i already tried @dos2unix way without success. but let's document it step by step and solve this mystery together
 
I am just in this moment downloading 247GB of Debian packages alone,

How are you downloading them? With mirror, or just individually?
 
I hope that VM has a very large hard drive. :cool:



One repo alone can be over 50 gig, all three together... I don't know.
no problem!
We have a server that was unused and I decided to use it.
Put 1 2TB disk, but maybe do a raid of 4 disks, because we have a lot of disks left, because we exchanged them for SSDs, in the terminals.
 
Soo, this is my /etc/apt/mirror.list

Code:
############# config ##################
#
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 cleanscript $var_path/clean.sh
set defaultarch amd64 set nthreads 20 set _tilde 0
#
############# end config ##############

deb http://ftp.us.debian.org/debian bookworm main contrib non-free
deb-src http://ftp.us.debian.org/debian bookworm main contrib non-free

# mirror additional architectures
#deb-alpha http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-amd64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-armel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-hppa http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-i386 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-ia64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-m68k http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mips http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mipsel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-powerpc http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-s390 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-sparc http://ftp.us.debian.org/debian unstable main contrib non-free

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

I downloaded via
Code:
apt-mirror

did an

Code:
ln -s /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian/ /var/www/html/debian

this is now my
Code:
/var/www/html/debian

Code:
root@mirror:~# ls /var/www/html/debian
dists  pool

I've installed apache2


Bildschirmfoto vom 2025-01-13 18-28-29.png



my clients
Code:
/etc/apt/sources.list

Code:
deb http://192.168.178.101/debian bookworm main contrib
deb http://192.168.178.101/debian bookworm-updates main contrib
deb http://192.168.178.101 bookworm-security main contrib

here's my
Code:
apt update

Code:
root@apt-mirror-client:~# apt update
Hit:1 http://192.168.178.101/debian bookworm InRelease
Ign:2 http://192.168.178.101/debian bookworm-updates InRelease
Ign:3 http://192.168.178.101 bookworm-security InRelease
Err:4 http://192.168.178.101/debian bookworm-updates Release
  404  Not Found [IP: 192.168.178.101 80]
Err:5 http://192.168.178.101 bookworm-security Release
  404  Not Found [IP: 192.168.178.101 80]
Reading package lists... Done
E: The repository 'http://192.168.178.101/debian bookworm-updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://192.168.178.101 bookworm-security Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
 
Soo, this is my /etc/apt/mirror.list

Code:
############# config ##################
#
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 cleanscript $var_path/clean.sh
set defaultarch amd64 set nthreads 20 set _tilde 0
#
############# end config ##############

deb http://ftp.us.debian.org/debian bookworm main contrib non-free
deb-src http://ftp.us.debian.org/debian bookworm main contrib non-free

# mirror additional architectures
#deb-alpha http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-amd64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-armel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-hppa http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-i386 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-ia64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-m68k http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mips http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mipsel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-powerpc http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-s390 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-sparc http://ftp.us.debian.org/debian unstable main contrib non-free

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

I downloaded via
Code:
apt-mirror

did an

Code:
ln -s /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian/ /var/www/html/debian

this is now my
Code:
/var/www/html/debian

Code:
root@mirror:~# ls /var/www/html/debian
dists  pool

I've installed apache2


View attachment 23618


my clients
Code:
/etc/apt/sources.list

Code:
deb http://192.168.178.101/debian bookworm main contrib
deb http://192.168.178.101/debian bookworm-updates main contrib
deb http://192.168.178.101 bookworm-security main contrib

here's my
Code:
apt update

Code:
root@apt-mirror-client:~# apt update
Hit:1 http://192.168.178.101/debian bookworm InRelease
Ign:2 http://192.168.178.101/debian bookworm-updates InRelease
Ign:3 http://192.168.178.101 bookworm-security InRelease
Err:4 http://192.168.178.101/debian bookworm-updates Release
  404  Not Found [IP: 192.168.178.101 80]
Err:5 http://192.168.178.101 bookworm-security Release
  404  Not Found [IP: 192.168.178.101 80]
Reading package lists... Done
E: The repository 'http://192.168.178.101/debian bookworm-updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://192.168.178.101 bookworm-security Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
Here, too, is the same error.
 
Maybe tree helps here
Code:
root@mirror:/var/www/html/debian# tree -L 2
.
|-- dists
|   `-- bookworm
`-- pool
    |-- contrib
    |-- main
    `-- non-free
 
In post #6, did you do steps 3, 4, and 5?
 
In post #6, did you do steps 3, 4, and 5?
No, I thought I only have to do that, if I want to add custom packages. Do I have to do that for an offline mirror as well?
 

Members online


Top