Tuesday, March 20, 2018

Use a Raspberry Pi as a Slackware Mirror on your Local Area Network

A few weeks ago I began work on updating all the SlackBuilds I maintain on  It had been a while since I did any work.  My usual development environment involved a few virtual machines managed by VirtualBox.  I would use the snapshot feature in VirtualBox to freeze both my x86 and x86_64 installations of Slackware 14.2.  Then I would use git and clone my GitHub SlackBuild repository on each machine.  All SlackBuild changes on the virtual machines would be synchronized to GitHub and back to the host system.  This process used to work great even though it was a bit wasteful of bandwidth.

I've been forced to do things a bit differently now because I no longer have a very fast internet connection.  The 1Gbps connection is now a 100Mbps connection.  With several smart phones, smart televisions, laptops, and Raspberry Pi's, this connection can be a bit slow.  Just the videos streaming and software security updates can be an issue at times.  It is especially an issue if I am running 4-6 virtual machines all accessing the network on top of all the physical devices.  As a result, I've changed my development environment.

I now host a Slackware 14.2 and a Slackware-current (both x86 and x86_64) mirror on a Raspberry Pi 1 B+, which also doubles as a print server on my home network.  That particular Pi has a 10/100 Mbit/s Ethernet port, so it is fast enough for my needs.  Sadly this Pi is running Raspbian instead of Slackware.  On my Raspberry Pi 3 B, which is also my LAN gateway, I host all of my git repositories.  The Slackware mirrors are using the HTTP protocol, are hosted using Apache2, and physically sit on an external USB hard drive connected to the Pi 1 B+.

I took Eric Hameleers's (aka Alien BOB) old script and modified it for my needs, since the newer script does not work with Raspbian.  You can use the latter if your Pi is running Slackware-arm and you will achieve the same results using the below configuration  It is all synced and stored on the USB hard drive at /usb/Slackware-Mirror.  Here is my Apache2 configuration for the curious.  It is a very basic configuration, it could probably be improved, but it works fine for my needs.  See the links at the bottom of this post for information about configuring Apache2 on Slackware.

$ sudo cat  /etc/apache2/sites-available/slackware-mirror.conf
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /usb/Slackware-Mirror/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory "/usb/Slackware-Mirror">
        Options Indexes FollowSymLinks
        IndexOptions FancyIndexing VersionSort NameWidth=*
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted

On each Slackware host I now just have to comment out everything in /etc/slackpkg/mirrors and add a URL pertaining the the Slackware release at the bottom of the file:

# Local Area Network Mirror

If you are following along, be sure the change slackware64-current/ to slackware-current/, or slackware64-14.2/, or slackware-14.2/ for your desired Slackware release.

Then I run the usual commands as root to update slackpkg:

$ slackpkg update gpg && slackpkg update

My router does have the ability to serve DNS on the LAN using dnsmasq.  I chose to opt out of that for the mirror because it adds latency to the process of downloading and installing packages.

The next pieces I added to this puzzle were the cron jobs that run that later email me about any updates to the Slackware tree.  I changed the MAILTO address for privacy reasons.

$ crontab -e
0 4 * * * /bin/sh /usb/Slackware-Mirror/
0 5 * * * ARCH=x86 /bin/sh /usb/Slackware-Mirror/
0 16 * * * REL=14.2 /bin/sh /usb/Slackware-Mirror/
0 17 * * * REL=14.2 ARCH=x86 /bin/sh /usb/Slackware-Mirror/

Finally I installed and configured Postfix for email delivery using a gmail account.  I used the following tutorial to do so:  Configure Postfix to use Gmail as a Mail Relay

Keep in mind that Slackware 14.2 uses the Sendmail service for email services.  Slackware-current uses Postfix.

Now I can provision virtual machines among other various devices on my LAN with Slackware.  The best part is that I am saving bandwidth for myself and for the Slackware mirrors I would otherwise be hammering with file transfers.

Relevant Links: