CUDAを別カーネルにインストールする

現在、最新版のCUDAは3.2でここからダウンロードできる。


Ubuntuを使っているとカーネルのアップデートが頻繁にある。当然、新しいカーネルでCUDAのカーネルモジュールがインストールされていないので、再び自分でインストールしないといけない。私はrecovery modeで起動してインストールしている。
しかし、いちいち再起動するのは面倒なのでどうにかできないかと思い

sh ./devdriver_3.2_linux_64_*.run -A

で、起動オプションを調べたところ、現在起動しているカーネルとは別のカーネルにインストールするオプションがあるではないか。便利そうなオプションを引用しておく。

  • -s, --silent
    • Run silently; no questions are asked and no output is printed, except for error messages to stderr. This option implies '--ui=none --no-questions --accept-license'.
    • 要するに自動でインストールしてくれる。
  • -f, --force-update
    • Forces an update to proceed, even if the installer thinks the latest driver is already installed; this option implies '--update'.
    • 新しいバージョンのをダウンロードしてインストール。
  • -k, --kernel-name=KERNEL-NAME
    • Build and install the NVIDIA kernel module for the non-running kernel specified by KERNEL-NAME (KERNEL-NAME should be the output of `uname -r` when the target kernel is actually running). This option implies '--no-precompiled-interface'. If the options '--kernel-install-path' and '--kernel-source-path' are not given, then they will be inferred from KERNEL-NAME; eg: '/lib/modules/KERNEL-NAME/kernel/drivers/video/' and '/lib/modules/KERNEL-NAME/build/', respectively.
    • カーネルの名前を指定して、そのカーネルにCUDAをインストール。`uname -r`を実行して出てくる文字列を指定してくれって言っている。
  • -K, --kernel-module-only
    • Install a kernel module only, and do not uninstall the existing driver. This is intended to be used to install kernel modules for additional kernels (in cases where you might boot between several different kernels). To use this ption, you must already have a driver installed, and the version of the installed driver must match the version of this kernel module.
    • カーネルモジュールだけインストール。現在のカーネルですでにCUDAをインストール済みであるなら、別カーネルではカーネルモジュールだけインストールすれば良い。

なので、apt-getで新しいカーネルをインストールしたら、その後にこれを実行すればよいことになる。

sudo sh ./devdriver_3.2_linux_64_*.run -s -f --opengl-headers -K -k $KERNELNAME

*はインストーラのファイル名にあわせて。$KERNELNAMEには`uname -r`で出力される文字列を指定するのだが、もちろん指定したいカーネルが起動中ではないのでわからないので、現在のカーネルでの結果から推測していれてみるのがよいかと。(何かちゃんとした方法があるのかな…?)


あと、dkmsという仕組みがあって、カーネルをインストールするときに自動的に作業をやらせることができるらしいのだけれども、これ使えば全自動でできる!?っておもったけれど、よくわからなさそう。わかる人は教えてください。(UbuntuTips/Others/DkmsHowTo - Ubuntu Japanese Wiki)


ちなみにアンインストール(--uninstall)はカーネル指定したのに現在のカーネルのが削除されちゃった? それともドライバーも削除されちゃったのかな? Linuxの細かい事情よくわからないです。

注) 本記事によって生じたいかなる損害について著作者は責任を負いません。