/etc/apt/sources.list
の設定内容の意味をよく理解していなかったので調べた。
とある Ubuntu 18.04 のサーバーの設定は以下のようになっており、この設定内容を理解することが目的である。
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://jp.archive.ubuntu.com/ubuntu bionic main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic main restricted
# # Major bug fix updates produced after the final release of the
# # distribution.
deb http://jp.archive.ubuntu.com/ubuntu bionic-updates main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic-updates main restricted
# # N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
# # team. Also, please note that software in universe WILL NOT receive any
# # review or updates from the Ubuntu security team.
deb http://jp.archive.ubuntu.com/ubuntu bionic universe
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic universe
deb http://jp.archive.ubuntu.com/ubuntu bionic-updates universe
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic-updates universe
# # N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
# # team, and may not be under a free licence. Please satisfy yourself as to
# # your rights to use the software. Also, please note that software in
# # multiverse WILL NOT receive any review or updates from the Ubuntu
# # security team.
deb http://jp.archive.ubuntu.com/ubuntu bionic multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic multiverse
deb http://jp.archive.ubuntu.com/ubuntu bionic-updates multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic-updates multiverse
# # N.B. software from this repository may not have been tested as
# # extensively as that contained in the main release, although it includes
# # newer versions of some applications which may provide useful features.
# # Also, please note that software in backports WILL NOT receive any review
# # or updates from the Ubuntu security team.
deb http://jp.archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
# # Uncomment the following two lines to add software from Canonical's
# # 'partner' repository.
# # This software is not part of Ubuntu, but is offered by Canonical and the
# # respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner
deb http://security.ubuntu.com/ubuntu bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse
書式
sources.list
の書式は以下のようになっている。
deb uri distribution [component1] [component2] [...]
たとえば以下の例を考えよう。
deb http://security.ubuntu.com/ubuntu bionic-security main restricted
- uri は
http://security.ubuntu.com/ubuntu
- distribution は
bionic-security
- component は
main
と restricted
APT のリポジトリには distribution と component という2つの軸があるということに注意する。component はパッケージの収録ポリシーを、distribution はパッケージのアップデートのポリシーを表している。
component
Ubuntu 公式リポジトリに収録されているすべてのソフトウェアは「Ubuntu チームによってサポートされているか」と「フリーソフトウェア哲学に合致しているか」の2つの観点によって4つのカテゴリに分けられ、それぞれのパッケージがいずれかの component に登録されている。
component |
Ubuntu チームによるサポート |
「フリー」なソフトウェア |
main |
✅ |
✅ |
restricted |
✅ |
❌ |
universe |
❌ |
✅ |
multiverse |
❌ |
❌ |
Ubuntu チームによるサポートが無いソフトウェアを利用したくないならば universe と multiverse を sources.list
から外すこともできる。同様に、「フリー」でないソフトウェアを利用したくないならば restricted と multiverse を外すこともできる。
distribution
xenial-security
や bionic-updates
といった名前がついている部分のことを distribution と呼ぶ。
release
-security
や -updates
といったサフィックスが付いていない distributionは release と呼ばれる。たとえば xenial
や bionic
は release である。
Ubuntu は基本的に、正式版のリリース後にはパッケージがフリーズされる。フリーズ時のパッケージが収録されているのが release である。apt-cache policy ${PACKAGE}
で表示される一番古いバージョンは release 由来のものになるだろう。
$ apt-cache policy nginx
nginx:
Installed: 1.14.0-0ubuntu1.6
Candidate: 1.14.0-0ubuntu1.6
Version table:
*** 1.14.0-0ubuntu1.6 500
500 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
500 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages
100 /var/lib/dpkg/status
1.14.0-0ubuntu1 500
500 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
500 http://jp.archive.ubuntu.com/ubuntu bionic/main i386 Packages
$
security & updates
前述の通り、Ubuntu のリリース時にパッケージはフリーズされ、release のパッケージはアップデートされない。アップデートは ${CODENAME}-security
と ${CODENAME}-updates
で配信される。security ではセキュリティに関するアップデートが配信され、updates では security のアップデートに加えてセキュリティ以外の問題の修正も含むアップデートが配信される。
デフォルト設定では security と updates の両方が有効になっているが、ソフトウェアのアップデートは単なるバグ修正であってもリグレッションのような問題を伴うことがある。選択肢の一つとして、updates を利用しないように設定することで、セキュリティに関するアップデートでない場合はアップデートを延期するような運用を行うことも可能である。
security に配信された内容は updates にもコピーされるが、ミラーへの配信が遅れることもある。そのようなセキュリティリスクを減らすため ${CODENAME}-security
は security.ubuntu.com を参照することが推奨されている。Ubuntu はデフォルトでこの設定になっている。
とある環境で apt-cache policy systemd
を実行したときの結果は以下のようになった。最新版の 237-3ubuntu10.31
は bionic-updates から配信されているが、それより少し古い 237-3ubuntu10.29
が bionic-security から配信されている。このことから、セキュリティに関する修正を含むアップデートが security から配信された後に、セキュリティ以外の修正を含むアップデートが updates から配信されたことが分かる。
$ apt-cache policy systemd
systemd:
Installed: 237-3ubuntu10.25
Candidate: 237-3ubuntu10.31
Version table:
237-3ubuntu10.31 500
500 http://ftp.iij.ad.jp/pub/linux/ubuntu/archive bionic-updates/main amd64 Packages
237-3ubuntu10.29 500
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
*** 237-3ubuntu10.25 100
100 /var/lib/dpkg/status
237-3ubuntu10 500
500 http://ftp.iij.ad.jp/pub/linux/ubuntu/archive bionic/main amd64 Packages
$
unattended-upgrades
security は保守的なポリシーで運用されているため、security のアップデートは確認無しで自動で適用してしまってもよいのではないか、という考え方もある。手動で cron を設定することもできるが、unattended-upgrades というパッケージが提供されているので、これを使うとよい。ちなみにこのパッケージの component は main である。
注意として、以下のページにも書いてあるが、リブートが必要なアップデートがあった場合に自動で再起動する機能 (Unattended-Upgrade::Automatic-Reboot
) を使う場合は update-notifier-common パッケージのインストールが必要らしい。
backports
前述の通り、Ubuntu の公式リポジトリでは機能変更を伴うアップデートは基本的に行われない。しかしながら、需要があるパッケージについては ${CODENAME}-backports
という distribution で新しいバージョンのパッケージが利用可能になることがある。
昔の Ubuntu(10.10 以前?)では backports distribution の設定を sources.list
に追加すると確認無しで新しいバージョンのパッケージがインストールされていたらしいが、最近の Ubuntu では明示的に ${PACKAGE}/${CODENAME}-backports
をインストールしない限りインストールされなくなったらしい。よって sources.list
で backports distribution が有効になっていても勝手に新しいバージョンがインストールされることはない。