Add and Verify Removable APT Media with apt-cdrom

apt-cdrom registers a disc as an APT source, and getting the scan wrong on the wrong drive is exactly the kind of thing you want a dry run for first. This guide gets you a removable-media source registered in APT, or a read-only test proving what the scan would do. The examples use apt-cdrom from apt 2.8.3, installed on Ubuntu 24.04.

Allow about fifteen minutes for one disc, plus the time needed to insert and scan each disc in a set. You need physical or virtual access to the media, a working mount point, and an account that can use sudo for the state-changing step. Keep an existing network package source available until the removable source has been tested.

1. Check the installed command and mount point

Start with read-only checks. They need no elevated privileges:

$ apt-cdrom --version
apt 2.8.3 (amd64)
$ apt-config dump | grep '^Acquire::cdrom'
Acquire::cdrom "";
Acquire::cdrom::mount "/media/cdrom/";

The version and exact configuration can differ on another host. In this example, APT's configured mount point is /media/cdrom/. The short form of the mount option is -d, so an explicitly configured alternative would look like apt-cdrom -d=/media/my-disc add.

Before continuing, check that the mount point is listed in /etc/fstab and is configured for the removable device. The manpage makes that a requirement when you specify a mount point. Do not invent an arbitrary directory and expect apt-cdrom to mount it correctly.

Checkpoint: make sure the media is available to the system and that the configured mount point is the one you intend to use. If the disc is already mounted elsewhere, sort that out first rather than mounting the same device twice.

2. Preview a scan without changing APT

Adding a disc changes APT's source list and writes index data. Treat that as a configuration change, even though it is normally reversible. First use --no-act, also written as -n, to scan without touching sources.list or writing index files:

$ sudo apt-cdrom --no-act add
Using CD-ROM mount point /media/cdrom/
Identifying... [working]
Scanning disc for index files...

The progress text varies with the media and the APT build. What matters is that the command completes its checks without an error. The preview can still inspect the disc and may prompt for media or a descriptive title, but it does not make the source-list or index-file changes described in the manpage.

Do not treat --no-act as proof the disc will install a package successfully. It checks the disc structure and index files. Package installation still depends on package availability, dependencies, trust configuration and your normal APT policy.

3. Add the first disc

When the preview looks sensible, run the real operation:

$ sudo apt-cdrom add
Using CD-ROM mount point /media/cdrom/
Identifying... [working]
Scanning disc for index files...
Writing new source list
Source list entries for this disc are now available.

The exact messages and progress indicators depend on the disc. During add, apt-cdrom unmounts the device, asks for a disc, scans it and copies the index files. If the disc lacks a usable .disk directory, it asks for a descriptive title. Use a label that distinguishes this disc from the others in the set.

Elevated privileges are appropriate here because the command updates system APT state. Do not run it as root merely to troubleshoot a failed media read before checking the mount point and disc. If the scan fails, record the error and keep the original source configuration intact while investigating.

Checkpoint: inspect the source entries that were added. The exact file layout depends on the host's APT configuration, so use APT's configured source-list locations rather than assuming one filename:

$ grep -R '^deb .*cdrom:' /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null
deb cdrom:[Example Disc]/ noble main

The label, release name and components in the output are media-specific. If the command prints no matching entry, do not proceed as though the disc was registered; review the scan output and APT configuration instead.

4. Add every disc in a multi-disc set separately

Each disc needs its own scan. Insert the next disc only when apt-cdrom asks for it, then run:

$ sudo apt-cdrom add
Using CD-ROM mount point /media/cdrom/
Identifying... [working]
Scanning disc for index files...

Repeat until every disc you need has been added. APT tracks disc identities in /var/lib/apt/cdroms.list. That identity database is why copying a hand-written deb cdrom: line is not a substitute for scanning each disc: it also lets APT tell the disc currently in the drive apart from the other media in the set.

Warning: do not insert the next disc while a scan is still running. A wrong disc can produce a misleading failure or an incomplete source entry. If you lose track of which disc has been scanned, use apt-cdrom ident after inserting the disc you want to identify.

5. Identify the disc currently in the drive

ident is a debugging command. It reports the identity of the current disc and the stored filename:

$ sudo apt-cdrom ident
CD-ROM identity: Example Disc 1
Stored filename: /var/lib/apt/cdroms.list

The output is media-specific, and some builds print different explanatory lines. A non-zero exit status means the operation did not complete normally: the manpage documents zero for normal operation and decimal 100 for an error, so scripts should check the status rather than scrape the human-readable identity.

Recovery: if the current disc cannot be identified, check that it is the disc you expect, that the configured mount point is usable, and that the device is not held open by another process. Reinsert the media and retry before changing APT configuration.

6. Use the slower or faster scan deliberately

The normal scan is the useful default:

$ sudo apt-cdrom --thorough add
$ sudo apt-cdrom --fast add

When diagnosing an unfamiliar disc, prefer the ordinary scan. If it reports read errors, run the scan again after checking the media and drive rather than hiding the problem with --fast.

7. Rename a disc only when its label is wrong

Use --rename, or -r, to replace or override a disc label:

$ sudo apt-cdrom --rename add
Enter the disc label:

This changes the label APT uses, so treat it as persistent source metadata. Choose a stable, descriptive value and record it with the physical media. If the label is already correct, skip this option during a routine add.

8. Undo an unwanted source entry

There is no single apt-cdrom undo command. If you added the wrong disc, disable or remove only the corresponding deb cdrom: entry using your normal APT source management process, then keep the matching entry in /var/lib/apt/cdroms.list consistent with the source configuration. Back up the relevant source file before editing it.

For a cautious rollback, copy the file to a root-owned backup and comment out the unwanted line, then verify the remaining sources:

$ sudo cp -a /etc/apt/sources.list /etc/apt/sources.list.before-apt-cdrom
$ sudoedit /etc/apt/sources.list
$ grep -R '^deb ' /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null

Do not delete the entire source list or the identity database to fix one bad disc: those files may hold unrelated repositories or identities. If you need to restore the previous file, use the backup you just made:

$ sudo cp -a /etc/apt/sources.list.before-apt-cdrom /etc/apt/sources.list

After any source change, run your normal APT metadata refresh and inspect its errors before installing packages. A source entry that points to media not currently inserted may produce an expected media prompt, not proof the disc scan failed.

Done means