Local mirror

From ArchWiki
Revision as of 09:37, 24 July 2005 by Pholie (talk | contribs) (Added initial page content)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

How to set up a local mirror

This document describes how to create a mirror on your local machine of all the files on the Arch mirrors of the "current" and "extra" directories, how to make it update periodically and how to set up pacman to use the local files.

  1. Of course, make sure that you're up-to-date:
  pacman -Syu
  1. Now, install rsync:
  pacman -S rsync
  1. Create a directory to host the mirrored files. As of March 2005, "current" requires a little over 500 MB while "extra" weighs around 2.2 GB. You can also mirror "testing" (800 MB) and "unstable" (350 MB) if you wish to. Also change permissions so an unprivileged user (in our example "chris") owns the folders.
  mkdir -p /mirror/{current,extra}
  # mkdir /mirror/{testing,unstable}
  chown -R chris /mirror
  1. Fire up your favourite editor and create a file named /mirror/sync.sh with the following content. If you want to mirror "testing" and "unstable" as well, comment out the corresponding lines. You may also adjust the address of the mirror to one geographically close to you.
  rsync -avz --delete rsync.archlinux.org::current /mirror/current/
  rsync -avz --delete rsync.archlinux.org::extra /mirror/extra/
  # --delete to delete old files remove it if you want to keep them
  # rsync -avz --delete rsync.archlinux.org::ftp/testing /mirror/
  # rsync -avz --delete rsync.archlinux.org::ftp/unstable /mirror/
  1. Make the newly created script executable:
  chmod a+x /mirror/sync.sh
  1. Make sure dcron is installed (it should already be):
  pacman -Q dcron
  1. Create a cron script with the name /etc/cron.daily/sync and the following content, and replace "chris" with the name of an unprivileged user on your system:

  if [[ -f $SYNCLOCKFILE ]]; then
    # lock file already present, bail
    exit 1

  echo -n ">>> Sync log for " > $SYNCLOGFILE
  date >> $SYNCLOGFILE

  cd /mirror
  su - chris -c "/mirror/sync.sh" >> $SYNCLOGFILE

  1. Set permissions:
  chmod 744 /etc/cron.daily/sync

Now the mirror will be synchronized at 00:02 AM everyday. What's now left to do is to tell our system to actually make use of the local mirror.

  1. Modify the file /etc/pacman.d/current so that it looks like this:
  # CURRENT: Arch Linux core repository
  Server = file:///mirror/current/os/i686
  Server = ftp://ftp.archlinux.org/current/os/i686
  # Also include the rest of the mirrors if you want
  1. Modify the file /etc/pacman.d/extra so that it looks like this:
  # The Extra Repository
  Server = file:///mirror/extra/os/i686
  Server = ftp://ftp.ibiblio.org/pub/linux/distributions/archlinux/extra/os/i686
  # Also include the rest of the mirrors if you want
  1. Do the same for the "testing" and "unstable" files if you decided to mirror those as well.
  1. Wait for the first sync to finish (check /var/log/sync.log), then try and see if it works:
  pacman -Sy
  1. That should yield something like this:
  :: Synchronizing package databases...
   current                  [[/mirror/current/os/i686/]] 100%    LOCAL
   extra                    [[/mirror/extra/os/i686/]] 100%    LOCAL

That's it!

I'd appreciate any comments and suggestions in IRC, my nick is busfahrer and I'm on #archlinux on irc.freenode.net

(This document is released under the [GFDL].)

To go further, try [[ http://wiki2.archlinux.org/index.php/How%20To%20Upgrade%20Via%20Home%20Network | this |]]