Note: Almost all content here will eventually be revised and merged into the live-manual. Please do not add new content to the wiki, but contribute to the manual directly.

Little HOWTO to setup a local Debian mirror

Before setting up a local mirror to be used by live-helper, consider that live-helper caches all packages already in cache, so if all you need is package caching, you do not need to go through the following. That being said, a mirror is useful if you do builds in many different directories and/or on different machines and you want to share the packages between them, or to control exactly which versions of packages go into your live systems. So if that describes your needs, read on.

apt-get update
apt-get install debmirror apache2

Put in /usr/local/bin a script named "update-local-apt-mirrors" like that one (modify it to your needs):

#!/bin/sh

set -eu

# Create and update a partial debian mirror, using debmirror for most of the data
# (a partial debian mirror and another unofficial example debian mirror)
# and rsync function for what debmirror still does not handle: #451120

ARCHS="i386,amd64"
DISTS="etch,lenny,sid,experimental"
SECTIONS="main,contrib,non-free,main/debian-installer"

LOCAL_MIRROR_PATH="/srv/apt-mirrors"

MAIN_DEBIAN_MIRROR="ftp.at.debian.org"
MAIN_NAME="debian"
DEST="${LOCAL_MIRROR_PATH}/${MAIN_NAME}"

ANOTHER_DEBIAN_MIRROR="www.debian-multimedia.org"
ANOTHER_NAME="debian-multimedia"
ANOTHER_DEST="${LOCAL_MIRROR_PATH}/${ANOTHER_NAME}"

LOCK="${LOCAL_MIRROR_PATH}/update-in-progress.lock"

OPT_SOURCES="--nosource"
# put OPT_SOURCES as "--source" or leave blank to have sources included

RSYNC_OPTIONS=""
# try e.g. RSYNC_OPTIONS="--bwlimit=120". Units are "KBytes per second"

if [ -f "${LOCK}" ]; then
        echo "E: RUNNING: \"`basename ${0}`\" is already running." >&2
        exit 1
fi

trap "test -f ${LOCK} && rm -f ${LOCK}; exit 0" 0 2 15

touch ${LOCK}

Installer () {
        MIRROR="${MAIN_DEBIAN_MIRROR}"
        for arch in $(echo ${ARCHS} | tr ',' ' ')
        do
                for dist in etch lenny sid
                do
                        if [ ! -d "${DEST}/dists/${dist}/main/installer-${arch}" ]
                        then
                                mkdir -p "${DEST}/dists/${dist}/main/installer-${arch}"
                        fi

                        # store old link
                        old="$(readlink ${DEST}/dists/${dist}/main/installer-${arch}/current)"
                        
                        # get the link first
                        rsync --recursive --links --hard-links --times \
                                -delay-updates --delete-delay \
                                "${MIRROR}::debian/dists/${dist}/main/installer-${arch}/current" \
                                "${DEST}/dists/${dist}/main/installer-${arch}"

                        # then follow it
                        current="$(readlink ${DEST}/dists/${dist}/main/installer-${arch}/current)"
                        rsync \
                                --recursive --links --hard-links --times \
                                --delay-updates --delete-delay \
                                "${MIRROR}::debian/dists/${dist}/main/installer-${arch}/${current}" \
                                "${DEST}/dists/${dist}/main/installer-${arch}"

                        # clean old content
                        if [ -n "${old}" ] && [ "${old}" != "${current}" ]
                        then
                                rm -rf "${old}"
                        fi

                done
        done
}

Debian_main () {
        debmirror \
                --arch="${ARCHS}" \
                --dist="${DISTS}" \
                --section="${SECTIONS}" \
                --host="${MAIN_DEBIAN_MIRROR}" \
                --root=":debian" \
                --pdiff=none \
                --method=rsync \
                --rsync-options "${RSYNC_OPTIONS}" \
                --getcontents \
                --ignore-small-errors \
                --ignore-release-gpg \
                ${OPT_SOURCES} \
                "${DEST}"
}

Debian_other () {
        debmirror \
                --arch="${ARCHS}" \
                --host="${ANOTHER_DEBIAN_MIRROR}" \
                --section="main" \
                --method="http" \
                --root="." \
                --dist="${DISTS}" \
                --pdiff=none \
                --getcontents \
                --ignore-small-errors \
                --ignore-release-gpg \
                ${OPT_SOURCES} \
                "${ANOTHER_DEST}"
}

Debian_main
Debian_other
Installer

Note: If you will realy use the ftp.de.debian.org as a REMOTE_MIRROR you will need the gpg signature:

$ gpg --keyserver wwwkeys.eu.pgp.net --recv-keys 6070D3A1 

Then

$ chmod +x /usr/local/bin/update-local-apt-mirrors

to make it executable. The "if" statements in the above script is here as a bad hack to permit non overlapping crontabs for automatic updates like this (if you want to update it at 23:18 and 6:18 each day, runt as user "marco", without output mails) :

$ su -c "crontab -e"

Then add this below line in the crontab and save & exit:

18 23,6 * * *   su marco -c /usr/local/bin/update-local-apt-mirrors 2>&1 >/dev/null

After the mirror is complete you could make 2 links to have a proper one:

# cd /srv/apt-mirrors/debian/dists
# ln -s unstable sid
# ln -s testing lenny
# ln -s stable etch

Create a file called "apt-mirrors" in /etc/apache2/sites-available :

# This is used for the local debian apt mirrors
#
# Will be available as http://localhost/debian/
#                  and http://<hostname>/debian/
#
Alias /debian /srv/apt-mirrors/debian
<Directory /srv/apt-mirrors/debian>
  order deny,allow
  deny from all
  allow from 127.0.0.0/255.0.0.0 127.0.1.0/255.0.0.0 192.168.1.0/255.255.255.0 ::1/128
  Options Indexes FollowSymlinks MultiViews
</Directory>

Alias /debian-multimedia /srv/apt-mirrors/debian-multimedia
<Directory /srv/apt-mirrors/debian-multimedia>
  order deny,allow
  deny from all
  allow from 127.0.0.0/255.0.0.0 127.0.1.0/255.0.0.0 192.168.1.0/255.255.255.0 ::1/128
  Options Indexes FollowSymlinks MultiViews
</Directory>

This entry above permits also users on the net 192.168.1.0/24 to use the mirrors.

then link it:

# cd /etc/apache2/sites-enabled
# ln -s ../sites-available/apt-mirrors 599-apt-mirrors
# /etc/init.d/apache2 restart

Now see DebianLive/Configuration to set up live-helper to use your mirror.

And in your /etc/apt/sources.list either:

deb http://localhost/debian/ sid main contrib non-free
deb http://localhost/debian-multimedia/ sid main

or

deb file:///srv/apt-mirrors/debian sid main contrib non-free
deb file:///srv/apt-mirrors/debian-multimedia sid main

Have Fun! (And 20 Gb if you do not modify the script)...

20070213 - If you are getting a gpgv error try the below which was posted on the debian-live IRC channel.

cd ~/.gnupg/ && rm trustedkeys* && ln -s pubring.gpg trustedkeys.gpg