読者です 読者をやめる 読者になる 読者になる

わすれっぽいきみえ

みらいのじぶんにやさしくしてやる

"yum install kernel-devel"を実行したら"No package kernel-devel available."が返ってきた件

macでchefが扱えるようにしてなかったことを思い出して、のほほんと設定やってたら「kernel-develが見つからない」というエラーにはまったのでメモっておく。
正確にはchefを流し込むためのVMvagrant)の設定でハマッた話。

既にvagrant入れるのはやってたけど、時間が経って忘れてしまっているので、ちょっともろもろ確認

$ vagrant plugin list
No plugins installed.
$ vagrant box list -i
centos6.5 (virtualbox)
  - url: https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
  - downloaded_at: 2014-03-03 14:30:37 UTC
~/Documents/vagrant$ ls -la
total 0
drwxr-xr-x  3 kimikimi714  group  102  3  3 23:33 .
drwx------+ 7 kimikimi714  group  238  3 22 16:25 ..
drwxr-xr-x  4 kimikimi714  group  136  3  3 23:41 centos65

なるほどpluginとかはいっさい手を付けないで、CentOS6.5(64bit)のboxだけを落としてきていたのか。
vagrantプラグイン管理のいい感じのものってないのかな。まぁとりあえず

$ vagrant plugin install sahara
Installing the 'sahara' plugin. This can take a few minutes...
Installed the plugin 'sahara (0.0.16)'!
$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Installed the plugin 'vagrant-vbguest (0.10.0)'!
$ vagrant plugin list
sahara (0.0.16)
vagrant-vbguest (0.10.0)

というわけでsaharavagrant-vbguestを導入。
早速vagrant upする。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
GuestAdditions versions on your host (4.3.8) and guest (4.3.4) do not match.
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: ftp.iij.ad.jp
 * epel: mirror01.idc.hinet.net
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
No package kernel-devel-2.6.32-431.el6.x86_64 available.
Package gcc-4.4.7-4.el6.x86_64 already installed and latest version
Package 1:make-3.81-20.el6.x86_64 already installed and latest version
Package 4:perl-5.10.1-136.el6.x86_64 already installed and latest version
Nothing to do
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 4.3.8 - guest version is 4.3.4
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.8 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.4 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-431.el6.x86_64

Building the main Guest Additions module[FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions[  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 4.3.8. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
Restarting VM to apply changes...
[default] Attempting graceful shutdown of VM...
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
Failed to mount folders in Linux guest. This is usually beacuse
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` /vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` /vagrant /vagrant

おや?vboxsfがおかしい。これじゃあ/vagrant下にホストのファイルが同期されない。

これを修正するにあたって、よく分かっていなかったことがあるんだが、
[default]って書いてある行はホストマシンから見たvagrantの挙動なんだけども、 それ以降の[default]がついていない行はゲストマシン側での出力なので、

(Look at /var/log/vboxadd-install.log to find out what went wrong)

って書いてあるところの/var/log/vboxadd-install.logはゲストマシンに入らないと見れない。

何が原因なのかを探るため、いったんゲストマシンにログインする。

$ vagrant ssh
[vagrant@vagrant-centos65 ~]$ less /var/log/vboxadd-install.log
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

確かにkernel moduleがないことが原因のようだ。vagrant upしたときのログにも

The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-431.el6.x86_64

とあるので、素直に実行しよう。

[vagrant@vagrant-centos65 ~]$ sudo yum install kernel-devel
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: mirror01.idc.hinet.net
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
No package kernel-devel-2.6.32-431.el6.x86_64 available.
Error: Nothing to do

ない!?マジで?ああ、vagrant upしたときのログに

No package kernel-devel-2.6.32-431.el6.x86_64 available.

って書いてあった。

kernel-devel-2.6.32-431.el6.x86_64のページを見に行く限りでは存在はしてそうなのに、なんでリポジトリから見つからないんだよ。

ということで、いろいろググったらやっと出てきた。

Chefでbuild-essential cookbookを使った時にkernel-develが存在しないエラーが発生するときの対処

ここにあるようにゲストマシンの/etc/yum.confを次のように変更

--- /home/kimikimi714/backup/yum.conf    2014-03-30 04:13:44.000000000 +0000
+++ /etc/yum.conf   2014-03-30 04:01:33.500224698 +0000
@@ -23,4 +23,4 @@

 # PUT YOUR REPOS HERE OR IN separate files named file.repo
 # in /etc/yum.repos.d
-exclude=kernel*
+# exclude=kernel*

すると

[vagrant@vagrant-centos65 ~]$ sudo yum list kernel-devel
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.riken.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Available Packages
kernel-devel.x86_64              2.6.32-431.11.2.el6                     updates

kernel-develが見つかるようになる。

ゲストマシンからログアウトしてvagrant reloadする。*1

$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'chef/centos-6.5' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
    default: Error: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
GuestAdditions versions on your host (4.3.10) and guest (4.3.4) do not match.
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
Package gcc-4.4.7-4.el6.x86_64 already installed and latest version
Package 1:make-3.81-20.el6.x86_64 already installed and latest version
Package 4:perl-5.10.1-136.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package kernel-devel.x86_64 0:2.6.32-431.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================
 Package              Arch           Version                 Repository    Size
========================================================
Installing:
 kernel-devel         x86_64         2.6.32-431.el6          base         8.7 M

Transaction Summary
========================================================
Install       1 Package(s)

Total download size: 8.7 M
Installed size: 24 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : kernel-devel-2.6.32-431.el6.x86_64                           1/1
  Verifying  : kernel-devel-2.6.32-431.el6.x86_64                           1/1

Installed:
  kernel-devel.x86_64 0:2.6.32-431.el6

Complete!
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 4.3.10 - guest version is 4.3.4
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.3.10 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module[  OK  ]
Building the shared folder support module[  OK  ]
Building the OpenGL support module[  OK  ]
Doing non-kernel setup of the Guest Additions[  OK  ]
Starting the VirtualBox Guest Additions [  OK  ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 4.3.10. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/kimikimi714/Documents/vagrant/centos65
==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it

いけたっぽい。試しに

$ touch aaa
$ vagrant ssh
[vagrant@vagrant-centos65 ~]$ ls -la /vagrant
drwxr-xr-x   1 vagrant vagrant  204 Mar 30 04:13 .
dr-xr-xr-x. 23 root    root    4096 Mar 30 04:02 ..
drwxr-xr-x   1 vagrant vagrant  102 Mar  3 14:41 .vagrant
-rw-r--r--   1 vagrant vagrant 4622 Mar 29 16:06 Vagrantfile
-rw-r--r--   1 vagrant vagrant    0 Mar 30 04:05 aaa
[vagrant@vagrant-centos65 ~]$ rm /vagrant/aaa
[vagrant@vagrant-centos65 ~]$ exit
logout
Connection to 127.0.0.1 closed.
$ ls -la
drwxr-xr-x  5 kimikimi714  group   170  3 30 13:26 .
drwxr-xr-x  3 kimikimi714  group   102  3  3 23:33 ..
drwxr-xr-x  3 kimikimi714  group   102  3  3 23:41 .vagrant
-rw-r--r--  1 kimikimi714  group  4622  3 30 01:06 Vagrantfile

おk−。shared folder使えないとかvagrantの意味ないわ。

ちなみに

kernel-develが読めないのは古いバージョンのCentOSリポジトリからじゃないから、と初めは勘違いしていて

CentOS 用の古いkernel-devel パッケージの検索 - ナレッジベース - Server Backup Manager: Docs, KB Articles, Technical Papers

みたいなページを調べていたりもした。そもそもyumのことを知らなすぎるな…。

*1:SSH addressなど先ほどのvagrant upで表示されなかったログが表示されるようになっているのは、これがvagrant shareを使ったboxの立ち上げに変わっているから。vagrant shareについてはまた別の記事で。