How can I create local repository which will have sub repositories main, non-free and generate key.gpg for it?
I have prepared folder /srv/dists/buster
How can I create local repository which will have sub repositories main, non-free and generate key.gpg for it?
I have prepared folder /srv/dists/buster
Please check out this related Stack Exchange post. If you think it applies we can mark this question as a duplicate. If not you can follow this answer:
debmirrorThis task is quite straightforward with the use of the tool debmirror, a cronjob, and a webserver.
I will be referencing this third party wiki for this answer. I would recommend you look at the manpage, as well as any additional manpages for tools you are not familiar with in this answer.
Install
debmirroranddebian-keyring.apt install debmirror debian-keyringCreate a directory for the mirror. (In your case,
/srv/dists/buster)Create a mirror user to run the sync scripts and maintain the mirror.
groupadd mirror useradd -d /srv/dists/buster -c "Debmirror" -g mirror mirror chown -R mirror.mirror /srv/dists/busterSet up gpg keys. Please make sure you understand that if something goes wrong it is because the official keyring has been updated and the new keys are missing locally. Take the necessary steps to update the keys, as you would encountering these types of issues. Check out this guide here for more information on how to fix gpg keys.
# Become the mirror user su - mirror # Import the keys gpg --no-default-keyring --keyring trustedkeys.gpg --import /usr/share/keyrings/debian-archive-keyring.gpg # Periodically you will update keys, just like this: (Hint: its the same as before.) gpg --no-default-keyring --keyring trustedkeys.gpg --import /usr/share/keyrings/debian-archive-keyring.gpg #Verify that you have the right keyrings for your system. (Hint: they should mention Buster. Information on the Debian keyrings can be found here: https://ftp-master.debian.org/keys.html) gpg --list-keys --keyring trustedkeys.gpgIf you have are missing
~/.gnupg/trustedkeys.gpgyou can copy it over with this:cp /usr/share/keyrings/debian-archive-keyring.gpg ~/.gnupg/trustedkeys.gpg
Setup a cronjob to sync the mirror.
#!/bin/bash # sourcehost: choose a mirror in your proximity! HOST=ftp.us.debian.org; # destination directory DEST=/srv/dists/buster/localmirror # Debian version(s) to mirror DIST=buster # architecture, use what is applicable here. ARCH=amd64 # log timestamp logger -t mirror[$$] updating Debian mirror su mirror -c \ "debmirror ${DEST} \ --nosource \ --host=${HOST} \ --root=/localmirror \ --dist=${DIST} \ --section=main,non-free \ --i18n \ --arch=${ARCH} \ --passive --cleanup \ $VERBOSE" logger -t mirror[$$] finished updating Debian mirrorCronjob file should look like this:
#Edit /etc/cron.d/local-debmirror: # debmirror 38 04 * * 1-5 root /root/scripts/mirror
Make the mirror available via a web server. I will leave this to you what you need or works best. I like nginx and flask. I know python has a oneliner to spin up a site, but if you are more familiar with apache or already have some infrastructure or policy for web servers use that. Use a solution that fits your needs best, whether you need high availability, security, or something quick for a homelab/simple network. The wiki I linked provides a solution you can use.
Add to your
sources.listyour mirror. For a client Debian server to pull from the mirror you will need to edit your Debian client's/etc/apt/sources.listfile to reference your local mirror. Do not forget to runapt updateto update apt.deb http://debmirror.example.com/localmirror/ buster main contrib non-freePay attention to what directories you are referencing. It should be the root where the mirror is being synced. In your case
/srv/dists/buster/localmirrorbut whatever works best for you. It just needs to be consistent.
Please read over each link I have provided carefully before doing this. Remember that this can be used for one Debian server to sync the mirror, run the web server to serve the content, and update itself, however this solution is more for running a local mirror that other Debian instances can update from.
Please check out the Official Debian Wiki for information about mirroring.
If you have any questions or there are any errors with my post please comment and I can edit this answer.
Best of Luck!