Thursday, June 20, 2019

networking - Is there a simple way to configure apt-get to optimize downloads using a lan apt-mirror when available?


I have a laptop and a local copy of several repositories in an external hard drive connected to my router. My router provides access to those files (with credentials) as samba shares and/or ftp server.


I would like to configure apt-get to check those repositories when they are available and download updates from them to speed up the process when possible.


To be more clear: I want apt-get to check both the regular repositories in the internet and my local one when my laptop is connected to my wifi. If files in the external repositories are newer than the ones in my local mirror or if the mirror is not available, apt-get should download the files from the internet.



I finally managed to solve this and it's working pretty well, so I want to share it with people that want to implement something similar.


My first problem was that my system supports multi-arch, so the mirrored repositories should contain both i386 and amd64 packages (I did not mirrored sources) to avoid downloading errors. This is done in /etc/apt/mirror.list like this example shows:


deb-i386  http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-amd64 http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse

My base_path defined in that file is /mnt/apt-mirrors, and I run a script that mounts an external hard drive connected to the USB port of my router as a Samba share (you can see the script here:
how to use apt-mirror to save files in HDD connected to LAN router


I wanted to access the mirrored repositories from other computers in the LAN, so the other part of the solution is adding the FTP repositories definitions at the beginning in /etc/apt/sources.list. This setup makes apt-get to use the FTP repositories first when downloading files and then use the ones defined in /etc/apt/sources.list.d, provided the mirrored ones are up to date.


The local repositories are defined like this:


deb [arch=amd64,i386] ftp://user:password@lan-resource/apt-mirrors/mirror/archive.ubuntu.com/ubuntu trusty main restricted universe multiverse

where you replace user with the user name that has access granted to the FTP server, :password with its password if required to connect (otherwise remove), and lan-resource with the address of the FTP server in your LAN (I decided to edit /etc/hosts to avoid repeating hard-coded IP address, where I defined 192.168.0.1 as lanftpserver to use in this field).


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...