TT Lab
Blog Get started
Learn Learning paths Courses

Package Management

A Repository Is, In the End, One Index File

Continue in TT Lab

In one line

The substance of an apt repository is a directory with .deb files in it + an index file called Packages. With just that, even file:/// makes an excellent repository.

Why this exists

Air-gapped networks, air gaps, internal standard images, CI caches — environments that cannot or must not reach the internet are more common than you might think. Here there are two options. Move the needed .deb files one by one by hand, or set up the repository itself on the inside. The first becomes unbearable after about three repetitions, and the second, once built, keeps being used.

How it works

What apt actually reads from a repository is surprisingly simple.

저장소 루트/
  Packages         <- 각 .deb 의 control 필드 + Filename + Size + SHA256
  Packages.gz      <- 위의 압축본 (apt 는 압축본을 선호한다)
  Release          <- 저장소 메타데이터 (Origin, Suite, Components, 체크섬)
  *.deb            <- 실제 패키지 파일

Packages is a text file made by concatenating each package's control fields and adding Filename (a path relative to the repository root), Size, and SHA256. The tools that produce it are dpkg-scanpackages (simple) and apt-ftparchive (large scale).

cd /root/repo
dpkg-scanpackages . /dev/null > Packages
gzip -kf Packages

Then you add one line to sources.list.

deb [trusted=yes] file:/root/repo ./

The ./ at the end means a flat repository (a form with no dists/ hierarchy and Packages at the root). [trusted=yes] is a marker saying to trust a repository that has no GPG signature. It is commonly used in labs and temporary internal repositories, but for a production repository you must sign it. With an unsigned repository, you cannot tell if someone swaps a .deb in the middle.

Here you have to distinguish two layers of verification.

Layer What it guarantees Tool
Checksum (SHA256) There was no corruption in transit sha256sum -c
Signature (GPG) The origin is the one I know gpg --verify, apt-key/signed-by

A checksum stored only on the same medium changes along with it if the whole medium is swapped. So the last bulwark of integrity is always the signature.

What it looks like in the field

"I put a package in the repository but the server can't see it." This is the report that comes in most often in air-gapped operations. Most causes are one of two. Either the index was not rebuilt (you forgot dpkg-scanpackages / createrepo_c --update), or the client did not refresh its cache (it did not run apt-get update). Both create the frustrating situation of "the file is definitely there".

The habit of putting the snapshot date in the repository name. If you write it like name=LabHub local (snapshot 2026-08-15), then six months later the question "as of what point in time was this server's content installed?" can be answered with one apt-cache policy line.

Turning imports into an air-gapped network into a procedure

In the previous module we talked about the USB drive going back and forth several times. To get rid of that, you have to turn the import from an improvised errand into a reproducible procedure. The trick is to compute "what to bring" mechanically on the outside in advance.

Receive the result of solving the dependencies in full. On the outside, in an environment of the same distribution and same version, install the needed packages, and collect every file downloaded at that time. Actually doing the install matters. If you only compute a list, it easily goes off because of the difference between what is already on the inside and what is not. So keeping one container on the outside in the same state as the inside is the core device of this work.

Put a manifest in the bundle. The file list, the checksum of each file, which distribution and which point-in-time repository it was fetched from, and what you were trying to install. Without this document, months later nobody knows what that USB drive is.

Verify and install on the inside. Confirm transfer corruption with the manifest's checksums, and, if possible, confirm the signature too, and then refresh the repository. As we saw earlier, the checksum guarantees only against corruption and the signature guarantees the origin.

Keep a record of the installation result. You need to keep a record of which bundle went into which server and when, so that the next time a problem arises, you can answer "as of which point in time is this server". The habit of putting the snapshot date in the repository name, mentioned earlier, is the cheapest form of this record.

The value of this procedure is not only saved time. The most dangerous thing on an air-gapped network is skipping verification because you are in a hurry, and if the procedure exists as a document, then even in a hurry you know for yourself which steps are the ones to skip.

Where does the chain of trust break: NO_PUBKEY and Hash Sum mismatch

In a signed repository, the order of what apt trusts is linked like a chain. The public key in the keyring verifies the signature of InRelease (or Release + Release.gpg), the hashes written in that Release vouch for Packages, and the SHA256 written in Packages vouches for each .deb. So even for the same report that "it won't install", which link broke is the cause, and that link is revealed by the stage at which apt stopped.

It stops at the index refresh (update): the key link. NO_PUBKEY <키 ID> (key ID) means "there is a signature, but I do not know the key that made it". The most common cases are that the signing key was replaced but the client keyring has only the old key, or that signed-by points to the wrong file. Here apt throws away that repository's index entirely, so the symptom that follows is "Unable to locate package": it looks as if the package does not exist, but in fact the whole repository is invisible. The prescription is to put the new public key, checked against the announced fingerprint, into the keyring file (apt looks only at the file signed-by points to, not at a personal keyring you added to with gpg --import), and to remove the revoked old key.

It stops at download (install): the file link. Hash Sum mismatch or File has unexpected size means the file the signed index describes differs from the file actually received. If the client index is stale, apt-get update fixes it, but if it stays the same after refreshing, then on the repository side a file of the same version was overwritten with different content (rebuilding in a hurry and uploading under the same name is common). Debian's rule is "same version = same content", so the prescription is to restore that approved file. If you really must ship new content, raise the version and build anew, then regenerate the index and Release and sign them with the original key. If you put a rebuild of the same version into the index and re-sign it, apt goes quiet, but from that moment the same "1.2.0-1" means different content on different servers.

Either way, [trusted=yes] is not the answer. It does not mend the chain; it removes the alarm that tells you the chain is broken, and from that moment this server would not notice if someone swapped files in the pool. Creating your own key and re-signing the repository is the same: only this server passes, and every other server using the same repository stops.

Three layers where an import bundle goes wrong

A bundle has three layers: files, manifest, and index. When "it won't install" comes up on the inside, what to check differs per layer. A file that shows FAILED in the manifest check was damaged passing through the media, and there is no way to fix it on the inside: put it on the next import list, and quarantine the broken file outside the bundle. A package whose file and hash are both fine but that apt does not know means the index was made before the files, so just regenerate the index on the inside. A dependency package missing from the bundle entirely is the trace of downloading names one at a time on the outside, as with apt-get download, and this too goes to the next import. If you get this judgment wrong and edit the manifest to match a broken file, or force things in while ignoring dependencies, all that remains is the illusion that there is a verification procedure.

What you will do in the next lab

You do two labs in a row. First you set up a flat repository with a .deb you built yourself and even install from it, and then you download in full the dependencies of an already installed package, make an import bundle with a manifest and checksums, and reproduce an offline install.