October 1, 2025

Debian APT ソースの書式

CLIで操作するDebianの /etc/apt/sources.list/etc/apt/sources.list.d/debian.sources の中身というか書式について調べてみた。

参照元の1次情報源はこちら

sources.list (debian.sources) とは

DebianのパッケージマネージャーであるAPT(Advanced Package Tool)が参照する設定ファイル。

ローカルディレクトリやCD/DVDも利用できるが、一般的には公式Debianリポジトリのようなネットワーク上のサーバーを利用することが多い。

注意事項

参照元にも書いてあるとおり、間違えるとシステムを破壊する可能性があるので慎重に修正すること。

編集するには

rootとしてテキストエディタで編集する。

$ sudo vi /etc/apt/sources.list
$ sudo vi /etc/apt/sources.list.d/debian.sources

カスタムソースを追加するなら、sources.list に書くよりも /etc/apt/sources.list.d/ にファイルを作成することが望ましい。

公式手順を元にDockerMySQLのリポジトリを追加すると、このディレクトリにdocker.list やmysql.listが置かれる。

データソースファイルの書式

新旧2つの書式がある。

  • DEB822スタイル形式
    • 新しい複数行のスタイル
    • 拡張子は “.sources”
    • 以下のように、今後はこちらの書式を使うことが推奨されている
    • 例: /etc/apt/sources.list.d/debian.sources
      Types: deb
      URIs: http://deb.debian.org/debian
      Suites: bookworm bookworm-updates
      Components: main
      Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
      
  • 1行スタイル形式
    • 従来の1行スタイル
    • 拡張子は “.list”
    • 例: /etc/apt/sources.list
      deb http://ftp.jp.debian.org/debian/ bookworm main non-free-firmware
      deb http://ftp.jp.debian.org/debian/ bookworm-updates main non-free-firmware
      

新フォーマットへの変換

apt modernize-sources で変換してくれる。

Bookworm 12.12ではエラー

$ apt -v
apt 2.6.1 (amd64)
$ apt -h | grep modern
$ apt modernize-sources
E: 不正な操作 modernize-sources

Trixie 13.1では実行できる

$ apt -v
apt 3.0.3 (amd64)
$ apt -h | grep modern
  modernize-sources - modernize .list files to .sources files

実行するとこんな感じ

  1. 変換前
    nissy@debian13:~$ cat /etc/apt/sources.list
    #deb cdrom:[Debian GNU/Linux 13.1.0 _Trixie_ - Official amd64 NETINST with firmware    20250906-10:22]/ trixie contrib main non-free-firmware
    
    deb http://ftp.jp.debian.org/debian/ trixie main non-free-firmware
    deb-src http://ftp.jp.debian.org/debian/ trixie main non-free-firmware
    
    deb http://security.debian.org/debian-security trixie-security main non-free-firmware
    deb-src http://security.debian.org/debian-security trixie-security main    non-free-firmware
    
    # trixie-updates, to get updates before a point release is made;
    # see https://www.debian.org/doc/manuals/debian-reference/ch02.en.   html#_updates_and_backports
    deb http://ftp.jp.debian.org/debian/ trixie-updates main non-free-firmware
    deb-src http://ftp.jp.debian.org/debian/ trixie-updates main non-free-firmware
    
    # This system was installed using small removable media
    # (e.g. netinst, live or single CD). The matching "deb cdrom"
    # entries were disabled at the end of the installation process.
    # For information about how to configure apt package sources,
    # see the sources.list(5) manual.
    
  2. 変換実行
    nissy@debian13:~$ sudo apt modernize-sources
    The following files need modernizing:
      - /etc/apt/sources.list
    
    Modernizing will replace .list files with the new .sources format,
    add Signed-By values where they can be determined automatically,
    and save the old files into .list.bak files.
    
    This command supports the 'signed-by' and 'trusted' options. If you
    have specified other options inside [] brackets, please transfer them
    manually to the output files; see sources.list(5) for a mapping.
    
    For a simulation, respond N in the following prompt.
    Rewrite 1 sources? [Y/n] y
    Modernizing /etc/apt/sources.list...
    - Writing /etc/apt/sources.list.d/debian.sources
    
  3. 元のファイルは sources.list.bak にリネームされる
    nissy@debian13:~$ ls -l /etc/apt/sources.list*
    -rw-r--r-- 1 root root 1048  9月 24 19:01 /etc/apt/sources.list.bak
    
    /etc/apt/sources.list.d:
    合計 4
    -rw-r--r-- 1 root root 648  9月 30 19:29 debian.sources
    
  4. 変換されたファイルの中身
    nissy@debian13:~$ cat /etc/apt/sources.list.d/debian.sources
    # Modernized from /etc/apt/sources.list
    Types: deb deb-src
    URIs: http://ftp.jp.debian.org/debian/
    Suites: trixie
    Components: main non-free-firmware
    Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
    
    # Modernized from /etc/apt/sources.list
    Types: deb deb-src
    URIs: http://security.debian.org/debian-security/
    Suites: trixie-security
    Components: main non-free-firmware
    Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
    
    # Modernized from /etc/apt/sources.list
    Types: deb deb-src
    URIs: http://ftp.jp.debian.org/debian/
    Suites: trixie-updates
    Components: main non-free-firmware
    Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
    
  5. 再度確認、変換対象が無い場合は以下のメッセージが表示される
    nissy@debian13:~$ apt modernize-sources
    All sources are modern.
    

インストール直後

ISOからインストールしたDebianは1行スタイル形式、Dockerやクラウド上のDebianはDEB822スタイル形式だったけど、Debian 13.2かDebian 14.0からはDEB822に変わるのではないだろうか。

ISOからインストール

Debian 12.12の場合、必要な行だけ残すとこんな感じ。

nissy@debian12:~$ grep -v ^# /etc/apt/sources.list

deb http://ftp.jp.debian.org/debian/ bookworm main non-free-firmware
deb-src http://ftp.jp.debian.org/debian/ bookworm main non-free-firmware

deb http://security.debian.org/debian-security bookworm-security main non-free-firmware
deb-src http://security.debian.org/debian-security bookworm-security main non-free-firmware

deb http://ftp.jp.debian.org/debian/ bookworm-updates main non-free-firmware
deb-src http://ftp.jp.debian.org/debian/ bookworm-updates main non-free-firmware

Debian 13.1はこんな感じ。

nissy@debian13:~$ grep -v ^# /etc/apt/sources.list

deb http://ftp.jp.debian.org/debian/ trixie main non-free-firmware
deb-src http://ftp.jp.debian.org/debian/ trixie main non-free-firmware

deb http://security.debian.org/debian-security trixie-security main non-free-firmware
deb-src http://security.debian.org/debian-security trixie-security main non-free-firmware

deb http://ftp.jp.debian.org/debian/ trixie-updates main non-free-firmware
deb-src http://ftp.jp.debian.org/debian/ trixie-updates main non-free-firmware

Docker

Debian 12.12

nissy@server01:~$ docker run --rm debian:12.12 cat /etc/apt/sources.list
cat: /etc/apt/sources.list: No such file or directory
nissy@server01:~$ docker run --rm debian:12.12 cat /etc/apt/sources.list.d/debian.sources
Types: deb
# http://snapshot.debian.org/archive/debian/20250908T000000Z
URIs: http://deb.debian.org/debian
Suites: bookworm bookworm-updates
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb
# http://snapshot.debian.org/archive/debian-security/20250908T000000Z
URIs: http://deb.debian.org/debian-security
Suites: bookworm-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Debian 13.1

nissy@server01:~$ docker run --rm debian:13.1 cat /etc/apt/sources.list
cat: /etc/apt/sources.list: No such file or directory
nissy@server01:~$ docker run --rm debian:13.1 cat /etc/apt/sources.list.d/debian.sources
Types: deb
# http://snapshot.debian.org/archive/debian/20250908T000000Z
URIs: http://deb.debian.org/debian
Suites: trixie trixie-updates
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.pgp

Types: deb
# http://snapshot.debian.org/archive/debian-security/20250908T000000Z
URIs: http://deb.debian.org/debian-security
Suites: trixie-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.pgp

※ 13.0や12.12では、Signed-Byの拡張子はgpgなのに、13.1はpgp…間違っているのか、新しく変わったのか…
※ 変わったらしい

12.12ではpgpファイルは無かった

$ docker run --rm debian:12.12 /bin/sh -c "ls -l /usr/share/keyrings/debian-archive-keyring.*"
-rw-r--r-- 1 root root 55918 Apr  9 23:04 /usr/share/keyrings/debian-archive-keyring.gpg

13.0ではgpgファイルはpgpファイルへのシンボリックリンクになった

$ docker run --rm debian:13.0 /bin/sh -c "ls -l /usr/share/keyrings/debian-archive-keyring.*"
lrwxrwxrwx 1 root root    26 Apr  9 22:05 /usr/share/keyrings/debian-archive-keyring.gpg -> debian-archive-keyring.pgp
-rw-r--r-- 1 root root 55918 Apr  9 22:05 /usr/share/keyrings/debian-archive-keyring.pgp

13.1でも同じだけど、debian.sourcesの中で実体を指すようになったようだ

$ docker run --rm debian:13.1 /bin/sh -c "ls -l /usr/share/keyrings/debian-archive-keyring.*"
lrwxrwxrwx 1 root root    26 Apr  9 22:05 /usr/share/keyrings/debian-archive-keyring.gpg -> debian-archive-keyring.pgp
-rw-r--r-- 1 root root 55918 Apr  9 22:05 /usr/share/keyrings/debian-archive-keyring.pgp

Google Cloud

Debian 12.12

nissy@instance-deb12:~$ cat /etc/apt/sources.list
# See /etc/apt/sources.list.d/debian.sources
nissy@instance-deb12:~$ cat /etc/apt/sources.list.d/debian.sources 
Types: deb deb-src
URIs: mirror+file:///etc/apt/mirrors/debian.list
Suites: bookworm bookworm-updates bookworm-backports
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb deb-src
URIs: mirror+file:///etc/apt/mirrors/debian-security.list
Suites: bookworm-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
nissy@instance-deb12:~$ cat /etc/apt/sources.list.d/google-cloud.list 
deb https://packages.cloud.google.com/apt google-compute-engine-bookworm-stable main
deb https://packages.cloud.google.com/apt cloud-sdk-bookworm main

Debian 13.1

nissy@instance-deb13:~$ cat /etc/apt/sources.list
# See /etc/apt/sources.list.d/debian.sources
nissy@instance-deb13:~$ cat /etc/apt/sources.list.d/debian.sources 
Types: deb deb-src
URIs: mirror+file:///etc/apt/mirrors/debian.list
Suites: trixie trixie-updates trixie-backports
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Types: deb deb-src
URIs: mirror+file:///etc/apt/mirrors/debian-security.list
Suites: trixie-security
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
nissy@instance-deb13:~$ cat /etc/apt/sources.list.d/google-cloud.list 
deb [signed-by=/etc/apt/keyrings/google-keyring.gpg] https://packages.cloud.google.com/apt google-compute-engine-trixie-stable main
deb [signed-by=/etc/apt/keyrings/google-keyring.gpg] https://packages.cloud.google.com/apt cloud-sdk-trixie main

APTソースファイルの書式

debian.sources 形式

Types: deb deb-src
URIs: mirror+file:///etc/apt/mirrors/debian.list
Suites: bookworm bookworm-updates bookworm-backports
Components: main
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

sources.list 形式

deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3

それぞれの意味は以下のとおり。

Archive Type

Types: の行

  • deb
    • そのリポジトリにはバイナリパッケージ(.deb)を置いている
  • deb-src
    • そのリポジトリにはソースパッケージ(.dsc)を置いている

Repository URI

URIs: の行

パッケージが置いてあるリポジトリのURL。  httpの他にもfileやcdrom、sshのような他のスキームも使うことができる。  他に何が使えるかはこちら

OSインストール時に指定したミラーサイトが書いてあることが多いと思う。  ミラーサイト一覧から選んでもいいし、netselect-aptをインストールしてrootとして実行するとミラーリストの速度を計測して、sources.listを最適なミラーサイトに書き換えてくれる。

最新パッケージが置かれているミラーの他に、過去のスナップショットアーカイブを保管している snapshot.debian.org を書くこともできる。  詳細は別途。

Suite

Suites: の行

Debianの各バージョンに付けられるコードネーム。  Debian 13ならtrixie、Debian 12ならbookwormだし、Debian 11ならbullseye

一般的な使い方では、stableやstable-updatesのようなスイート名は事故の元だから、bookwormやbookworm-updatesのようにコードネームを書いた方が良い。

bookwormの後ろに続きがあるコードネームについては、こことかここを読む限りこんな感じ。  勘違いしてたらごめんなさい。 

  • bookworm
    • ポイントリリース(12.6とか12.7みたいな、hoge.fugaのリリース)された時点のパッケージ
    • 次のポイントリリースまで更新されることはない
  • bookworm-proposed-updates
    • 次のポイントリリースで更新予定のパッケージ
  • bookworm-updates
    • 次のポイントリリースを待たずに入れてほしい重要な更新、任意
  • bookworm-security
    • セキュリティに関する更新、重要

bookwormとbookworm-securityの2つは書いておいた方が良さそう

bookworm-updatesはお好みで

Components

Components: の行

  • main
  • contrib
    • DFSGに準拠したソフトウェアが含まれているが、DFSG に準拠していないソフトウェア(non-free)に依存している
  • non-free
    • DFSGに準拠していない(文字どおりフリーではない)ソフトウェアが含まれている
    • 「フリー」とは「無料」という意味ではない
    • ソースコードの配布を許可していないとか、配布しているがコードの変更に制限を掛けている場合はここに含まれる
  • non-free-firmware
    • 特定のハードウェアでDebianを動作させるために必要な、フリーではないファームウェアが含まれている

© 2020 nissy-lab.com