yum upgradeとyum updateの違いについて勘違いしてた

yum updateは、よく使うしよく知っているパッケージを最新にアップデートするコマンドだけど、それとよく似たyum upgradeというコマンドがあります。たぶんどこかで読んだんだと思うけど、yum upgradeはメジャーバージョンを上げるコマンドだと、勘違いしていました。yum upgradeについて、調べなおしたので書いておきます。

結論

  • yum upgradeはメジャーバージョンアップ以外にも使う。
  • そもそもyum upgradeyum update --obsoletesと同じコマンド。
  • CentOSのデフォルトでは、設定ファイルにobsoletes=1が書いてあるので--obsoletesは付けなくても付けた扱いになる。
  • --obsoletesをつけると、というかCentOSのデフォルトでは、廃止対象のパッケージがあり、廃止処理される。
  • 廃止処理は、他の新しいパッケージで置き換えられるという形。
    • fooというパッケージが、単にbarという名前に変わった場合、barパッケージがfooを廃止するという情報を持っているので、barをインストールするタイミングでfooが削除される。

補足

yum upgradeをmanから調べる

まず、改めてmanpageを見てみました。

upgrade
Is the same as the update command with the --obsoletes flag set. See update for more details.

yum upgradeyum update --obsoletesと同じみたいです。

update
[snip]
If the main obsoletes configure option is true (default) or the --obsoletes flag is present yum will include package obsoletes in its calculations - this makes it better for distro-version changes, for example: upgrading from somelinux 8.0 to somelinux 9.

If the main obsoletes configure option is true (default) obsoletes configure optionはデフォルト値がtrueなので、常に--obsoletes付いてる扱いになる。
the --obsoletes flag is present yum will include package in its calculations 直訳すると「yumは廃止されたパッケージを計算に含める」と読めるんだけど、具体的にどうなるのかいまいち分からない。
this makes it better for distro-version changes, for example: upgrading from somelinux 8.0 to somelinux 9. ここは分かりやすく、メジャーバージョンを上げるときに良い的な事が書いてあります。

manpageだと結局--obsoletesが具体的に何をするオプションなのか、いまひとつ分からないけど、yum updateyum upgradeは実質同じ動きをするであろう事は分かりました。

検索して見つけた補強情報

そこで、yum の man を見てみたら、upgrade は update + obsoletes フラグ。

If the --obsoletes flag is present yum will include package obsoletes in its calculations - this makes it better for distro-version changes, for example: upgrading from somelinux 8.0 to somelinux 9.

http://linux.die.net/man/8/yum

で、/etc/yum.conf で obsoletes=1 と指定されているので、この二つは同じ機能になってたというわけでした。

http://pub.ne.jp/tkita/?entry_id=1496257

obsoletes configure optionは、どうやら/etc/yum.confobsoletes=1みたい。自分の環境で/etc/yum.confは全然いじってないし、確かにtrueになっている。

いつ効果を発揮するのか

CentOS 5.2 がリリースされてた。

アナウンスによると

Note that the command required is 'upgrade' and not the usual 'update'. Refer to the yum man page for details on how those two differ in operation.

[CentOS-announce] Release for CentOS-5.2 i386 and x86_64

と、バージョンが変わる場合は yum upgrade らしい。

http://pub.ne.jp/tkita/?entry_id=1496257

さっきと同じエントリーだけど、CentOS 5.2リリースのアナウンスで、CentOS 5.0 5.1から移行する場合は、yum upgradeを使うよう指示があるのを見つけていました。つまり--obsoletesを使えって事になる。
このアナウンスから、yum upgrade, --obsoletesはマイナーバージョンアップの際でも使う場合がある事が分かります。

リリースノートには書いてない

Manuals/ReleaseNotes/CentOS5.2/Japanese - CentOS Wiki

余談だけど、メーリングリストのアナウンスには書いてあったupgradeの件、リリースノートには書いてないみたい。

5.5 より前の CentOS からアップグレードする場合、次の手順が勧められています:

yum clean all
yum update glibc\*
yum update yum\* rpm\* pyth\*
yum clean all
yum update mkinitrd nash
yum update selinux\*
yum update
shutdown -r now
Manuals/ReleaseNotes/CentOS5.6/Japanese - CentOS Wiki

CentOS 5.6のリリースノートには、アップグレード手順が書いてあるので、ちょっとなんでだろうという疑問が残る。

結局--obsoletesは何をするのか

obsoletes
This option only has affect during an update. It enables yum’s obsoletes processing logic. Useful when doing distribution level upgrades. See also the yum upgrade command documentation for more details (yum(8)). Default is ‘true’.
Command-line option: --obsoletes

/etc/yum.confのmanpageを見てみると、obsoletes processing logicを有効化するとある。ただ、詳細は要領を得なかったman yumを見ろって書いてある・・・。

1 — Enable yum's obsoletes processing logic when performing updates. When one package declares in its spec file that it obsoletes another package, the latter package will be replaced by the former package when the former package is installed. Obsoletes are declared, for example, when a package is renamed. obsoletes=1 the default.

8.4. Configuring Yum and Yum Repositories - Red Hat Customer Portal

obsoletes processing logicで検索するとRedHatのドキュメントで、やっとそれっぽい解説を発見。どうやら、パッケージが、他のパッケージを廃止して自分が置き換わるというメタ情報を持っていて、obsoletes処理が有効ならそのメタ情報を元に、実際にその置き換えをするという事らしい。で、ありがちなのが、単にパッケージ名が変わった場合という例が書いてあります。

マイナーバージョン・メジャーバージョンが上がった時のリポジトリ
$ yum check-update centos-release
Loaded plugins: fastestmirror, security
Skipping security plugin, no data

centos-release.x86_64                                  10:5-8.el5.centos                                   base

CentOSがマイナーバージョンアップして5.8がリリースされた時、5.7の環境ではcentos-releaseというパッケージが更新対象になります。

$ yumdownloader centos-release
$ rpm -qlp centos-release-5-8.el5.centos.x86_64.rpm 
/etc/issue
/etc/issue.net
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
/etc/pki/rpm-gpg/RPM-GPG-KEY-beta
/etc/redhat-release
/etc/sysconfig/rhn
/etc/sysconfig/rhn/sources
/etc/yum.repos.d
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repo
/etc/yum.repos.d/CentOS-Vault.repo
/usr/share/doc/centos-release-5
/usr/share/doc/centos-release-5/EULA
/usr/share/doc/centos-release-5/GPL
/usr/share/doc/centos-release-5/autorun-template
/usr/share/eula/eula.en_US
/usr/share/firstboot/modules/eula.py
/usr/share/firstboot/modules/eula.pyc
/usr/share/firstboot/modules/eula.pyo

centos-releaseの内容を見てみると、/etc/yum.repos.d/*、つまりyumリポジトリの設定が更新されます。

  1. centos-releaseが5.8系に更新される。
  2. リポジトリの設定も5.8系になる。
  3. 以後5.8系のパッケージが取得できるようになり、他のパッケージを廃止して置き換わるパッケージが含まれている場合、それをインストールする時にobsoletes処理が走る。

実際に確認してないから多分だけど、こういう流れになるんじゃないかなと思っています。

We need to go ahead and setup the centos-release package as follows:

rpm -Uhv centos-release-*.rpm
http://www.admon.org/update-centos-4-to-centos-5-remotely/

CentOS4からCentOS5への移行を解説するエントリーでは、centos-releaseyumじゃなくrpmを使って手動で更新しています。これによってCentOS5系のリポジトリに切り替わり、yumで更新すると、obsoletes処理も走ってCentOS4時代のパッケージは消え、すべてCentOS5のパッケージになる、ということなのかな。

ただ、このエントリーではかなり色々と下準備をしています。やはりメジャーバージョンアップは、centos-releaseを更新してyumで一発というわけには行かないみたい。多分理想はそうだけど、違いがありすぎてうまくいかないって事なのかな。

廃止されるパッケージを一覧にする
$ yum list obsoletes

実際にobsoletes処理の対象となるパッケージは、これで確認できるっぽい。

環境

サーバー Serversman@VPS Entry
Linux CentOS 5.7

書いた日

2012-08-16
例によって下書きのまま放置してた