6.6. Local Repositories and Disconnected Systems
Between "one machine installs from Debian's mirrors" and "an air-gapped machine installs from nothing" lies the middle ground most organizations actually operate: several machines sharing downloaded packages, local software published as real packages, and machines that receive updates through media rather than networks. This section builds that middle ground from the parts the chapter already has - the signed archive of Section 6.2.3, the download cache, and apt's ability to point its whole state at another directory.
6.6.1. Caching Package Downloads and Choosing a Mirror Scope
Every fetched archive lands in /var/cache/apt/archives/ before dpkg
unpacks it, and the cache persists after installation - a reinstall
does not re-download, and a botched transaction can re-run from the
cached copy. The behavior is easiest to see by filling and emptying the
cache deliberately:
# apt-get clean
# apt-get install --download-only hello
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
hello
0 upgraded, 1 newly installed, 0 to remove and 29 not upgraded.
Need to get 53.2 kB of archives.
After this operation, 287 kB of additional disk space will be used.
Get:1 https://deb.debian.org/debian trixie/main amd64 hello amd64 2.10-5 [53.2 kB]
Fetched 53.2 kB in 1s (50.8 kB/s)
Download complete and in download only mode
apt-get clean empties the archive cache and prints nothing; the
--download-only run then resolves and fetches hello exactly as an
install would, stopping at the last line - the archives are staged, the
system unchanged. Look at what is staged:
$ ls -l /var/cache/apt/archives/hello_*.deb
-rw-r--r-- 1 root root 53228 Apr 16 2025 /var/cache/apt/archives/hello_2.10-5_amd64.deb
A real install of hello would now fetch nothing. Clear the cache again
(apt-get clean, silent as before) and verify the emptiness rather
than assume it:
# find /var/cache/apt/archives -maxdepth 1 -name "*.deb" -print
The find prints one path per matching archive and nothing when none
match - here it prints nothing, which is the expected result.
(apt-get autoclean is the subtler variant: it removes only archives
that can no longer be downloaded, keeping recent ones for reinstall.)
For staging downloads without touching the cache at all, apt can print what it would fetch, in a form designed to be consumed:
$ apt-get --print-uris --yes install hello
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
hello
0 upgraded, 1 newly installed, 0 to remove and 29 not upgraded.
Need to get 53.2 kB of archives.
After this operation, 287 kB of additional disk space will be used.
'https://deb.debian.org/debian/pool/main/h/hello/hello_2.10-5_amd64.deb' hello_2.10-5_amd64.deb 53228 MD5Sum:205bff7f0368ca10574c658af3cbb572
Each line is one archive: quoted URL, filename, size, and checksum.
--yes matters more here than usual - it answers the confirmation so
the command runs to the listing at all. This is the primitive the
disconnected-machine procedure of Section 6.6.4 builds on: a list of
every archive a transaction needs, computable on any machine with the
same indexes.
Choosing where machines fetch from is a scope decision, and the options form a small ladder:
| Approach | What it saves | Costs and limits | When it fits |
|---|---|---|---|
Direct to deb.debian.org |
Nothing to run. | Each machine downloads everything; the CDN is fast and geo-routed. | A few machines on ordinary links. |
| Country or ISP mirror | Regional bandwidth. | Mirror lag varies; one more party to trust. This option is legacy: the CDN serves most regions well. | Links where the CDN is slow. |
Caching proxy (e.g. apt-cacher-ng, approx) |
One download serves many machines, transparently. | A service to run and monitor; cache hits depend on machines staying in sync. | Many machines, same suites, one site. |
Full internal mirror (e.g. ftpsync, debmirror) |
Complete local copy of chosen suites. | Tens to hundreds of GB, mirroring discipline, storage to run. | Large sites, strict egress control, or install farms. |
The proxy and full-mirror rows are documented tooling rather than demonstrations here - nothing in this chapter exercises them - and the chapter's own practice archive is deliberately the smallest possible special case of the last row: a repository of locally built packages. The CDN row is the example system's own choice, and its sources in Section 6.2.1 show it.
6.6.2. Building and Signing an Internal APT Repository
Section 6.2.3 built a complete signed repository in four moves - pool
the archives, index them with apt-ftparchive packages, describe the
suite with apt-ftparchive release, sign the Release file - and
everything an internal archive adds is a matter of doing those same
moves deliberately at scale. What changes with scale, item by item:
The Release file is the contract between publisher and client, and each field has a client-side meaning the build of Section 6.2.3 already set:
Release field |
Client-side meaning |
|---|---|
Origin |
Identity pins match with Pin: release o=…; unattended-upgrades allows or excludes by it. |
Label |
Second identity key, used by pins and origin patterns. |
Suite / Codename |
What a source's Suites: line matches; also a= and n= pin selectors. |
Components |
Which component indexes clients will fetch. |
Architectures |
Which architecture indexes exist; clients fetch those they have enabled. |
Description |
Human text shown by some tools. |
Date |
When this metadata was generated; freshness checks read it. |
Valid-Until |
Hard expiry of the whole index set; the field Section 6.6.5 relies on and Section 6.7.2 shows failing. |
MD5Sum:/SHA256: blocks |
Checksums of every index; clients verify each fetched index against them. |
The pool gains real structure. A flat pool/main/ served the practice
archive fine, but Debian's own layout - and any archive that will hold
many sources or share files between suites - groups archives by source
package: pool/main/c/ch06-tool/ch06-tool_1.0_all.deb. The prefix
directory keeps pools navigable at thousands of entries, and grouping by
source (not binary) name is what lets one file serve several binary
packages and several suites at once.
Serving is any file transport. file: URIs suit one machine or
examples; production archives serve the identical tree over https:
from any web server, which adds transport authentication on top of the
end-to-end signature verification that never depends on the transport.
Two disciplines carry over from the local case: the tree must be
readable by the unprivileged _apt user, and updates should be staged
into the served directory atomically - build the new indexes and
signature, then switch - so clients never observe a half-updated
InRelease pointing at indexes that are not yet there.
Key hygiene is where the practice archive cut corners that a real one
must not: its key is passphrase-less, lives on the same machine, and
will expire quietly in two years. A production signing key keeps its
secret half offline or on restricted storage, protected by a passphrase
where automation permits; its public half is distributed with the
archive and pinned per source with Signed-By; expiry and rotation are
planned events, with the new key published before the old one retires;
and the revocation certificate GnuPG wrote at creation
(Section 6.2.3's output showed its path) is stored somewhere it can be
used even if the key itself is lost.
The tooling choice determines how much of the above is manual.
apt-ftparchive is the primitive: it generates indexes and Release
files but tracks nothing, knows nothing about prior contents, and
never deletes anything - removing a package from an
apt-ftparchive-built archive means editing the pool by hand and
regenerating. Repository managers wrap that primitive:
| Tool | Model | Strengths | Limits |
|---|---|---|---|
apt-ftparchive + scripts |
Stateless regeneration. | Nothing to install beyond apt-utils; transparent; what this chapter used. |
No removals, no pool tracking; release fields rest entirely on the script. |
reprepro |
Stateful: one database per archive directory. | Manages pool and indexes; signed export; handles removals; the walkthrough below. | One directory, one set of suites; not a general mirror tool. |
aptly |
Stateful with snapshotting. | Full mirror management, snapshots, published repos from snapshots. | Heavier model; its own service conventions. |
The comparison's practical summary: apt-ftparchive is right for
scripted one-shot publication; reprepro is the working tool for a
repository that changes over time; aptly adds snapshot workflows for
archives that need controlled promotion between stages.
6.6.3. Publishing Local Packages with reprepro
reprepro turns the previous section's manual moves into managed ones:
it keeps a database under the repository directory, places archives
into a structured pool, regenerates and signs the indexes, and - the
feature apt-ftparchive lacks - removes packages cleanly. The example
system has it installed (apt-get install reprepro once); its one
configuration file describes each suite the repository carries. Create
/srv/ch06-reprepro/conf/distributions with this content:
Origin: Debian Handbook Lab
Label: Debian Handbook Lab
Codename: trixie
Suite: trixie
Architectures: amd64
Components: main
Description: Debian handbook reprepro repository
SignWith: lab@example.org
The fields are the Release fields of Section 6.6.2's table - what
reprepro writes into the Release file it generates - plus SignWith,
which names the signing key and turns every export into a signed one.
The key lives in the GnuPG home from Section 6.2.3, so every reprepro
command below carries GNUPGHOME=/srv/ch06-gnupg to point there.
Export the (still empty) suite to produce the signed skeleton:
# install -d /srv/ch06-reprepro/conf
# GNUPGHOME=/srv/ch06-gnupg reprepro --basedir /srv/ch06-reprepro export
# find /srv/ch06-reprepro/dists -maxdepth 3 -type f | sort
/srv/ch06-reprepro/dists/trixie/InRelease
/srv/ch06-reprepro/dists/trixie/Release
/srv/ch06-reprepro/dists/trixie/Release.gpg
export prints nothing on success; the find confirms the three files
a signed suite needs, exactly the set Section 6.2.3 built by hand. Now
add the one fixture built for this purpose, ch06-tool:
# GNUPGHOME=/srv/ch06-gnupg reprepro --basedir /srv/ch06-reprepro includedeb trixie /home/john/debian-handbook/package-management/local-packages/ch06-tool_1.0_all.deb
Exporting indices...
# find /srv/ch06-reprepro/pool -type f | sort
/srv/ch06-reprepro/pool/main/c/ch06-tool/ch06-tool_1.0_all.deb
includedeb reads the archive's control data, files it into the
pool under its source-grouped path (main/c/ch06-tool/ - the layout
Section 6.6.2 described, managed rather than hand-made), records it in
the database, regenerates the indexes, and re-signs the suite; the
Exporting indices... line is its entire progress report. The
repository is now a functioning source. Add it as a second local
source - /etc/apt/sources.list.d/ch06-reprepro.sources:
Types: deb
URIs: file:/srv/ch06-reprepro
Suites: trixie
Components: main
Signed-By: /etc/apt/keyrings/ch06-lab.asc
Both practice archives now serve a suite named trixie, which is
normal: a suite name is not exclusive, and each source's Signed-By
binds its own key. Refresh and confirm the new source verifies:
$ sudo apt-get update
Get:1 file:/srv/ch06-repo trixie InRelease [1874 B]
Get:1 file:/srv/ch06-repo trixie InRelease [1874 B]
Get:2 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Get:2 file:/srv/ch06-reprepro trixie InRelease [1219 B]
Get:3 file:/srv/ch06-reprepro trixie/main amd64 Packages [346 B]
Hit:4 https://security.debian.org/debian-security trixie-security InRelease
Hit:5 https://deb.debian.org/debian trixie InRelease
Hit:6 https://deb.debian.org/debian trixie-updates InRelease
Hit:7 https://deb.debian.org/debian trixie-backports InRelease
Reading package lists...
The new source contributes one InRelease and one Packages - 346
bytes of index for one package, against the first archive's 2686 for
twelve. The policy report shows where the new package comes from:
$ apt-cache policy ch06-tool
ch06-tool:
Installed: (none)
Candidate: 1.0
Version table:
1.0 500
500 file:/srv/ch06-reprepro trixie/main amd64 Packages
Only the reprepro archive offers it, so it is the candidate by default - the third-party containment of Section 6.2.4 is unnecessary here because nothing competes. Install and run it:
$ sudo apt-get install ch06-tool
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
ch06-tool
0 upgraded, 1 newly installed, 0 to remove and 29 not upgraded.
Need to get 0 B/924 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 file:/srv/ch06-reprepro trixie/main amd64 ch06-tool all 1.0 [924 B]
Selecting previously unselected package ch06-tool.
(Reading database ... 111159 files and directories currently installed.)
Preparing to unpack .../ch06-tool_1.0_all.deb ...
Unpacking ch06-tool (1.0) ...
Setting up ch06-tool (1.0) ...
Selected output; progress lines and needrestart report omitted.
$ ch06-tool
ch06-tool 1.0 from the Debian handbook lab repository
A package published once by reprepro is managed from then on: a new
version arrives as another includedeb (the database replaces the old
index entry and pool file), and reprepro remove trixie ch06-tool
withdraws it as cleanly - the removal command is documented tooling
rather than a demonstration here, and it is the capability that decides
the tool comparison of Section 6.6.2 in practice.
reprepro usage |
Description |
|---|---|
--basedir dir |
Work on the repository rooted at dir. |
includedeb suite file.deb |
Add or replace a binary package. |
includedsc suite file.dsc |
Add a source package. |
export [suite] |
Regenerate and sign all indexes. |
remove suite pkg |
Withdraw a package and its files. |
list suite |
List recorded packages. |
dumpreferences |
Show which files the database references. |
6.6.4. Staging Complete Dependencies for a Disconnected Machine
A machine with no network still needs updates, and apt's design makes that a solvable problem: everything a machine needs to update is files - signed index metadata and archives - and every one of them can be staged, moved on media, and consumed offline. The procedure has three parts, staged here on the connected machine, and the section gives the disconnected side its own treatment next.
Choose the update content first. For the demonstration the target is one
fixture pair with a real dependency: ch06-leaf depends on
ch06-dep (= 1.0), and the plan is to install ch06-leaf on a machine
that has neither. Stage the archives, as john, into the staging
workspace - the cd is bookkeeping and prints nothing:
$ cd ~/debian-handbook/package-management/offline-stage
$ apt-get download ch06-leaf ch06-dep
Get:1 file:/srv/ch06-repo trixie/main amd64 ch06-dep all 1.0 [828 B]
Get:2 file:/srv/ch06-repo trixie/main amd64 ch06-leaf all 1.0 [852 B]
$ ls -1 ch06-*.deb
ch06-dep_1.0_all.deb
ch06-leaf_1.0_all.deb
apt-get download fetches exactly the archives named - it does not
resolve dependencies - so the completeness of a real staging set is
someone's explicit responsibility. Two tools make that responsibility
manageable: apt-get --print-uris --yes install … (Section 6.6.1)
lists every archive the transaction would fetch, dependencies included,
and a simulation of the install on a machine with matching indexes
shows the full set. The two-name case here is closed by construction:
the ch06-leaf control file's own Depends: line named its companion,
which is how the staging set was known to be complete.
Second, build a repository around the staged files. The tree is the same
one Section 6.2.3 built, generated here with its own Label so the
offline copy identifies itself in policy output. Save this as
/srv/ch06-offline-build.sh:
#!/bin/sh
set -e
rm -rf /srv/ch06-offline
install -d /srv/ch06-offline/repo/pool /srv/ch06-offline/repo/dists/trixie/main/binary-amd64
cp /home/john/debian-handbook/package-management/offline-stage/*.deb /srv/ch06-offline/repo/pool/
cd /srv/ch06-offline/repo
apt-ftparchive packages pool > dists/trixie/main/binary-amd64/Packages
gzip -kf dists/trixie/main/binary-amd64/Packages
apt-ftparchive \
-o APT::FTPArchive::Release::Origin="Debian Handbook Lab" \
-o APT::FTPArchive::Release::Label="Debian Handbook Lab Offline" \
-o APT::FTPArchive::Release::Suite="trixie" \
-o APT::FTPArchive::Release::Codename="trixie" \
-o APT::FTPArchive::Release::Architectures="amd64 all" \
-o APT::FTPArchive::Release::Components="main" \
release dists/trixie > dists/trixie/Release
printf "Valid-Until: %s\n" "$(date -u -d "+7 days" "+%a, %d %b %Y %H:%M:%S UTC")" \
>> dists/trixie/Release
GNUPGHOME=/srv/ch06-gnupg gpg --batch --yes --pinentry-mode loopback --passphrase "" \
--default-key lab@example.org --clearsign -o dists/trixie/InRelease dists/trixie/Release
GNUPGHOME=/srv/ch06-gnupg gpg --batch --yes --pinentry-mode loopback --passphrase "" \
--default-key lab@example.org -abs -o dists/trixie/Release.gpg dists/trixie/Release
grep -E "^(Origin|Label|Date|Valid-Until):" dists/trixie/Release
Run it in the root shell:
# bash /srv/ch06-offline-build.sh
gpg: using "lab@example.org" as default secret key for signing
gpg: using "lab@example.org" as default secret key for signing
Date: Wed, 18 Nov 2026 21:43:27 +0000
Label: Debian Handbook Lab Offline
Origin: Debian Handbook Lab
Valid-Until: Wed, 25 Nov 2026 21:43:27 UTC
The two gpg lines arrive on standard error as the signatures are made;
the four closing lines are the script's final grep on the Release
file it generated. The Valid-Until is the load-bearing field for this
use: it gives the offline copy a seven-day life, chosen because the
transfer and the offline update are planned inside that window.
Section 6.7.2 shows exactly what an offline machine says when it is
handed an expired release.
Third, describe the source for the disconnected machine -
/etc/apt/sources.list.d/ch06-offline.sources:
Types: deb
URIs: file:/srv/ch06-offline/repo
Suites: trixie
Components: main
Signed-By: /etc/apt/keyrings/ch06-lab.asc
On a genuinely disconnected machine, the URI would name wherever the media is mounted and the key file would have been carried over by the same channel as the repository. The verification property survives the change of transport: the signature is over the content, and Section 6.6.5 checks it on the receiving side explicitly.
6.6.5. Transferring Signed Metadata, Checking Freshness, and Updating Offline
The receiving half of the procedure is an apt that reads only the offline repository. Rather than a second machine, the demonstration uses apt's own directory options to build that apt state in isolation - the same files, same signature, same commands, with none of the host's other sources visible. The source file from the previous subsection is the only one this apt reads:
# apt-get -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/ch06-offline.sources -o Dir::Etc::sourceparts=- -o Dir::State::lists=/srv/ch06-offline/lists -o Dir::Cache=/srv/ch06-offline/cache update
Get:1 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:1 file:/srv/ch06-offline/repo trixie InRelease [1828 B]
Get:2 file:/srv/ch06-offline/repo trixie/main amd64 Packages [676 B]
Reading package lists...
Each -o moves one piece of apt's state, and together they are the
whole isolation:
-o option |
Effect |
|---|---|
Dir::Etc::sourcelist=… |
Read only this source file. |
Dir::Etc::sourceparts=- |
Disable /etc/apt/sources.list.d/ scanning. |
Dir::State::lists=… |
Keep fetched indexes in this directory, not the host's. |
Dir::Cache=… |
Keep downloaded archives there, not in the host cache. |
On a real disconnected machine none of this redirection is needed -
that machine's own /etc/apt/sources.list.d/ contains only the
offline source, and plain apt-get update is the command; the
directory options are how one machine rehearses the procedure end to
end, and how the captures below are the genuine offline behavior rather
than a description of it. Confirm what the isolated state knows:
$ apt-cache -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/ch06-offline.sources -o Dir::Etc::sourceparts=- -o Dir::State::lists=/srv/ch06-offline/lists policy ch06-leaf
ch06-leaf:
Installed: (none)
Candidate: 1.0
Version table:
1.0 500
500 file:/srv/ch06-offline/repo trixie/main amd64 Packages
The offline index answers: one version, one candidate, the offline Label's origin. The install, in the same isolated state:
# apt-get -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/ch06-offline.sources -o Dir::Etc::sourceparts=- -o Dir::State::lists=/srv/ch06-offline/lists -o Dir::Cache=/srv/ch06-offline/cache install ch06-leaf
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
ch06-dep
The following NEW packages will be installed:
ch06-dep ch06-leaf
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1680 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 file:/srv/ch06-offline/repo trixie/main amd64 ch06-dep all 1.0 [828 B]
Get:2 file:/srv/ch06-offline/repo trixie/main amd64 ch06-leaf all 1.0 [852 B]
Selecting previously unselected package ch06-dep.
(Reading database ... 111162 files and directories currently installed.)
Preparing to unpack .../repo/pool/ch06-dep_1.0_all.deb ...
Unpacking ch06-dep (1.0) ...
Selecting previously unselected package ch06-leaf.
Preparing to unpack .../pool/ch06-leaf_1.0_all.deb ...
Unpacking ch06-leaf (1.0) ...
Setting up ch06-dep (1.0) ...
Setting up ch06-leaf (1.0) ...
Selected output; progress lines and the needrestart report omitted. The "0 upgraded … and 0 not upgraded" line differs from every earlier capture because this apt state sees only the offline repository - the host's twenty-nine pending updates do not exist here.
The transaction resolved ch06-dep from the offline index and fetched
both archives from the offline pool - the staged dependency closure
from the previous subsection, consumed exactly as staged. Verify from
the host's database, where the install really happened:
$ dpkg-query -W -f='${Package} ${Version} ${Status}\n' ch06-leaf ch06-dep
ch06-dep 1.0 install ok installed
ch06-leaf 1.0 install ok installed
Two checks close the procedure on the receiving side. Freshness first - the receiver reads the same fields the publisher set:
$ grep -E "^(Date|Valid-Until):" /srv/ch06-offline/repo/dists/trixie/Release
Date: Wed, 18 Nov 2026 21:43:27 +0000
Valid-Until: Wed, 25 Nov 2026 21:43:27 UTC
If the transfer took longer than the window, the honest options are to
re-sign a fresh release on the connected side or, where a longer cycle
is the plan, to generate the release with a Valid-Until that covers
it; a receiver skipping the check instead of refreshing the data would
give up exactly the property that makes offline updates safe. Second,
signature verification, done directly with gpgv - the same engine
apt uses, invoked by hand:
$ gpgv --keyring /etc/apt/keyrings/ch06-lab.gpg /srv/ch06-offline/repo/dists/trixie/InRelease
gpgv: Signature made Wed Nov 18 21:43:27 2026 UTC
gpgv: using EDDSA key D5766FD3D63C13312FFB0B51BAB298F419FF7A9B
gpgv: issuer "lab@example.org"
gpgv: Good signature from "Debian Handbook Lab <lab@example.org>"
The verification report goes to standard error, and its content is the
whole trust decision in four lines: when the signature was made, which
key made it, and the verdict. The key fingerprint matches the one
gpg --show-keys printed when the key was created in Section 6.2.3 -
that cross-check, published fingerprint against received file, is what
turns "a good signature from somebody" into "a good signature from
the archive we intended". On a real receiving machine, running this
check before the first apt-get update establishes the key the same way
a first SSH connection does; afterwards apt itself re-verifies the
signature on every update, and the manual gpgv is an audit tool.
The procedure as a whole, then: stage the complete closure and a signed repository on a connected machine; move the repository tree and its key by any medium; on the disconnected machine, verify the signature, read the freshness fields, and update from the offline source. The same discipline scales from this two-package fixture to a staged security update - the content changes, and none of the trust steps do.