Network Shared Pacman Cache

From ArchWiki

Jump to: navigation, search

In order to share packages between multiple computers you can simply share /var/cache/pacman/ using any network-based mount protocol; for example samba or nfs. Alternatively; you could use sshfs which is probably a bit slower, but has the advantage of being more secure. This guide shows you how to use shfs or sshfs to share a package cache plus the related library-directories between multiple computers on the same local network.

Contents

[edit] Using shared package cache

First, install any network filesystem - sshfs, shfs, ftpfs, smbfs, nfs etc.

[edit] Using sshfs

pacman -S sshfs

Then mount /var/cache/pacman/pkg from your server to /var/cache/pacman/pkg on every client machine.

mount sshfs#root@alpha:/var/cache/pacman/pkg/ /var/cache/pacman/pkg

That's all! Now you have shared package cache. If you want also to have shared package database you will need to mount /var/lib/pacman/{current,extra,testing,community,unstable} in the same way.

Warning: do not mount /var/lib/pacman/local!

You may modify your /etc/fstab like this:

sshfs#root@alpha:/var/cache/pacman/pkg/ /var/cache/pacman/pkg fuse rw,reconnect 0 0
sshfs#root@alpha:/var/lib/pacman/testing/ /var/lib/pacman/testing fuse rw,reconnect 0 0
sshfs#root@alpha:/var/lib/pacman/current/ /var/lib/pacman/current fuse rw,reconnect 0 0
sshfs#root@alpha:/var/lib/pacman/extra/ /var/lib/pacman/extra fuse rw,reconnect 0 0
sshfs#root@alpha:/var/lib/pacman/community/ /var/lib/pacman/community fuse rw,reconnect 0 0

or this:

root@alpha:/var/cache/pacman/pkg/ /var/cache/pacman/pkg shfs rw,preserve,persistent 0 0
root@alpha:/var/lib/pacman/testing/ /var/lib/pacman/testing shfs rw,preserve,persistent 0 0
root@alpha:/var/lib/pacman/current/ /var/lib/pacman/current shfs rw,preserve,persistent 0 0
root@alpha:/var/lib/pacman/extra/ /var/lib/pacman/extra shfs rw,preserve,persistent 0 0
root@alpha:/var/lib/pacman/community/ /var/lib/pacman/community shfs rw,preserve,persistent 0 0

Note: using shared database can be slow, depending on network filesystem type and LAN load.

Tip: if you want to use sshfs or shfs you should consider reading Using SSH Keys.

[edit] sshfs vs. shfs

  • sshfs is FUSE filesystem, shfs is kernel module
  • there were some problems with shfs, I didn't test it recently so please report here your results


[edit] Using nfs

Image:Tango-document-new.png This article is a stub.
It may be confusing, not contain enough information, or be a placeholder for an article to come. People are invited to expand it to full article status and remove this box.
 pacman -S nfs-utils

NFS can be a bit quicker for local networks, as there is no encryption overhead. However, the configuration is more complex.

  • On the "server"
    • Add portmap, nfslock, and nfsd to the rc.conf DAEMONS array (and start them too) in this order
    • In /etc/exports, add:
 #List machines allowed to mount this share.
 # See 'man exports' for details
 #A single machine on the network
 /var/cache/pacman/pkg/ 192.168.1.199(rw,sync,no_root_squash,subtree_check)
 #The entire local network
 /var/cache/pacman/pkg/ 192.168.1.199(rw,sync,no_root_squash,subtree_check)
    • Add the connecting clients to /etc/hosts.allow

For one specific machine:

 ALL : 192.168.1.199 : ALLOW

A bit more proper:

 portmap : 192.168.1.199 : ALLOW
 lockd : 192.168.1.199 : ALLOW
 mountd : 192.168.1.199 : ALLOW
 rquoted : 192.168.1.199 : ALLOW
 statd : 192.168.1.199 : ALLOW
  • On the "client(s)"
    • Add portmap to the rc.conf DAEMONS array (and start it too)
    • Add an entry in /etc/fstab
 # mount the shared cache on 192.168.1.25 (our server)
 192.168.1.25:/var/cache/pacman/pkg/ /var/cache/pacman/pkg/ nfs rw 0 0


[edit] Note:

As of version 3.1 "pacman -Sc" changed behavior. It does no longer remove all outdated package files but all package files which are not installed on the machine the command was issued on. Because Pacman can't predict what packages are installed on all machines that share the cache, you will end up deleting files you don't want to delete. If you want to clean up your cache to only keep the newest packages you will have to do this by yourself. I use this script (as always without any warranty):

# !/bin/bash
# script cleans pacman cache by comparing existing version of a package
# to newest version of package available according to pacman-db
# WARNING! THIS SCRIPT WILL DELETE EVERY FILE IN /var/cache/pacman/pkg
# THAT IS NOT IN THE PACMAN-DB OR THAT DOES NOT FOLLOW THE CURRENT NAMING
# CONVENTIONS: <PACKAGENAME>.<VERSION>.<ARCHITECTURE>.pkg.tar.gz !!!
#
arc=$(uname -m)	
for fn in $(ls /var/cache/pacman/pkg);do 
    # strip off .pkg.tar.gz
    f=${fn/%\.pkg\.tar\.gz/}
    # strip off architecture if given in package name
    if echo $f | grep -q $arc; then
       f=${f/%$arc/};f=${f/%-/}
    fi
    # now divide string into version and package name as used by pacman -Si
    pk=$f;v=$f;pk=${pk%-*};pk=${pk%-*};v=${v/$pk};v=${v/-}
    # query pacman-database to get current version of package and delete cached version if it is older
    if ! pacman -Si $pk | grep -q $v ; then
       rm -v /var/cache/pacman/pkg/$fn
    fi
done
# end of file
Personal tools