Disable CD-ROM APT sources
What it does
Disables configured CD-ROM, DVD, and USB-media APT sources on one Debian 13 (Trixie) x86_64 host, then refreshes APT package metadata. It supports both traditional deb cdrom: entries in /etc/apt/sources.list and *.list files, and CD-ROM-only stanzas in Debian 13's deb822 *.sources files. Network, local-file, and other APT sources are left unchanged.
Run the script directly from an account with sudo access; it prompts once for authorization. Before changing a source file, it creates a timestamped archive-preserving backup in the same directory, with a name that APT will not read. It comments traditional CD-ROM source lines and changes a CD-ROM-only deb822 stanza to Enabled: no. It does not remove package caches, install packages, or delete source files.
System: Debian 13 x86_64
bash -c "$(curl -fsSL 'https://hero4hire.com/scripts/debian-13-x86_64/disable-cdrom-apt-sources.sh')"Show script
Loading script…How it works
APT reads the traditional /etc/apt/sources.list file, *.list fragments, and deb822 *.sources fragments under /etc/apt/sources.list.d/. The script examines only those recognized filenames. In one-line files, an active deb or deb-src entry whose URI is cdrom: is prefixed with #. In deb822 files, it disables a stanza only when its URIs: field contains a single CD-ROM URI, avoiding accidental removal of a network mirror bundled in the same stanza.
The script writes each transformed file to a temporary location and compares it to the original. When a change is needed, it makes an archive-preserving, timestamped backup beside the source file, preserves the original file mode, and replaces the source. Backup names do not end in .list or .sources, so APT does not treat them as active configuration. apt-get update runs afterward and will fail visibly if a remaining source is invalid or unavailable.
The cdrom scheme is a supported APT transport for removable media and is normally registered with apt-cdrom. Disable it when the media is not intentionally available to the server; retain the generated backup if it must be restored later.
Commands Used
| Command | Argument | Description |
|---|---|---|
sudo | -v | Prompts once for permission and refreshes the credential used for privileged source-file changes. |
awk | Adds or changes Enabled: no only for CD-ROM-only deb822 source stanzas. | |
sed | -E | Comments active deb cdrom: and deb-src cdrom: entries in traditional source files. |
cmp | -s | Detects whether a transformed source file differs before creating a backup or replacing it. |
cp | --archive | Creates a metadata-preserving backup beside each changed source file. |
stat | -c %a | Reads the original source file's permission mode. |
install | -m | Replaces a changed source file while preserving its permission mode. |
apt-get | update | Refreshes package metadata and verifies that active APT sources can be read. |
References
Debian's APT sources.list manual documents source-file locations, recognized filename extensions, one-line and deb822 formats, and the cdrom URI scheme. Debian's APT CD-ROM manual documents how optical-media sources are registered. The Debian 13 release notes describe Trixie's deb822 source-file convention.