Create local repository for Raspbian Stretch, apt-mirror

This method allows to install packages from local storage. Additional 70Gb space needed for this.

This is tested on fresh 2017-09-07-raspbian-stretch.img operating system.

At first I push the image and put my favourite wpa_supplicant.conf in boot partition. This will let me connect to my wifi at system startup.

Also my custom config.txt goes on boot partition.

Now I reload the package list for all repositories:
sudo apt-get update -y
Install the package which will allow me to create local repository:
sudo apt-get install apt-mirror -y
Now I open configuration and edit it to satisfy my needs. Look what already configured in primary repository:
grep -v "^$\|^#" /etc/apt/sources.list
This will probably show:
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
And there is also additional repos:
grep -v "^$\|^#" /etc/apt/sources.list.d/raspi.list
This will report us:
deb http://archive.raspberrypi.org/debian/ stretch main ui
Now let's set both these repos locally. Open apt mirror.list:
vi /etc/apt/mirror.list
Make sure the file looks like:
############# 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  
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

#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://archive.raspberrypi.org/debian/ stretch main ui
deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi

#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
clean http://archive.raspberrypi.org/debian
clean http://mirrordirector.raspbian.org/raspbian
Now execute mirroring utility:
apt-mirror
This will take some day, week or something. It this will download ~70GB.

Now I want to point apt-get to use local repository only. To do it so open file:
vi /etc/apt/mirror.list
Replace the internet repos with local:
#deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
deb file:///var/spool/apt-mirror/mirror/mirrordirector.raspbian.org/raspbian stretch main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspbian.org/raspbian/ stretch main contrib non-free rpi
And modify the second additional repo:
vi /etc/apt/sources.list.d/raspi.list
Make sure it looks like this:
#deb http://archive.raspberrypi.org/debian/ stretch main ui
deb file:///var/spool/apt-mirror/mirror/archive.raspberrypi.org/debian/ stretch main ui
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://archive.raspberrypi.org/debian/ stretch main ui
All done. No need to restart anything. Now you have local internet there :) Every time you still need to update both repositories just run again:
apt-mirror
and free up space and crear old packages that is not anymore the latest:
/var/spool/apt-mirror/var/clean.sh
Good luck with your bandwidth ;)

Appendix
To do all configuration on the fresh system you can risk to execute these commands:
#!/bin/sh
echo "set nthreads 20"> /etc/apt/mirror.list
echo "set _tilde 0">> /etc/apt/mirror.list
grep -v "^$\|^#" /etc/apt/sources.list >> /etc/apt/mirror.list
grep -v "^$\|^#" /etc/apt/sources.list.d/raspi.list >> /etc/apt/mirror.list
grep -v "^$\|^#" /etc/apt/sources.list | cut -d" " -f2 | sed "s/^http/clean http/g;s/\/$//g">> /etc/apt/mirror.list
grep -v "^$\|^#" /etc/apt/sources.list.d/raspi.list | cut -d" " -f2 | sed "s/^http/clean http/g;s/\/$//g">> /etc/apt/mirror.list
sed -i "s/http:\/\//file:\/\/\/var\/spool\/apt-mirror\/mirror\//g" /etc/apt/sources.list
sed -i "s/http:\/\//file:\/\/\/var\/spool\/apt-mirror\/mirror\//g" /etc/apt/sources.list.d/raspi.list

No comments: