初めて就職したのがWindowsベース、Macユーザは当時係長現課長のお兄さんだけの世界線だったので、当然Windows前提の開発環境で育った炬燵です。
あれからMacユーザは着々と増え、半分くらいの割合になったところで会社を辞めたので現在のOS事情は知りませんが、人数は変動していないとのことで、休職のメンツを省けばやはり半々なのではないでしょうか。よくわかりません。
一緒にプログラミング教室運営してたお姉さんが知らん間に結婚して娘までできてるなんて信じたくないですね。
話を元に戻すと、元職場みたいなところではVagrantとVirtualboxとCentOSがはびこっていたりします。
さて本題ですが、vagrant up時に/etc/init.d/vboxadd setupで失敗します。そうですね。なんかそんな気はしてました。何せ就職してからずっとVagrant使ってるので……。
vagrant -v #=> Vagrant 2.2.9 virtualbox -h #=> 6.1.12 r139181 (Qt5.6.2)
あくまで自分用のメモですので、助けを求めに来た方には何の参考にもならないかもしれません。よくわからん人はとりあえずログの斜め読みと対処の検討方法を覚えて帰ってくださいね。
いつものエラーメッセージです。
/etc/init.d/vboxadd setup Stdout from the command: VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Kernel headers not found for target kernel 2.6.32-754.35.1.el6.x86_64. Please install them and execute /sbin/rcvboxadd setup Stderr from the command: modprobe vboxguest failed The log file /var/log/vboxadd-setup.log may contain further information.
このログはここに残ってるよってあるんですけどまあsetupに失敗したことさえわかればいいんですよね。
勘の鋭い人はここで上から提示されている順になんか流しても意味ないなってことに気づいていると思うんですけど、まあやっていきましょう。というか、vagrant upのログであらかた必要な情報は出てます。
先ほど省いた部分を全部流しましょう。
長いので折りたたみです。読みたい人と、エラーログ全部検索して引っかかる人向けです。
エラーログ
==> default: Machine booted and ready!
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.16
Going on, assuming VBoxService is correct...
[default] GuestAdditions seems to be installed (6.1.16) correctly, but not running.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.16
Going on, assuming VBoxService is correct...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
2.6.32-754.35.1.el6.x86_64. Please install them and execute
/sbin/rcvboxadd setup
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
vboxadd-service.sh: Starting VirtualBox Guest Addition service.
VirtualBox Additions module not loaded!
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.16
Going on, assuming VBoxService is correct...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
2.6.32-754.35.1.el6.x86_64. Please install them and execute
/sbin/rcvboxadd setup
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
/etc/init.d/vboxadd setup
Stdout from the command:
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
2.6.32-754.35.1.el6.x86_64. Please install them and execute
/sbin/rcvboxadd setup
Stderr from the command:
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
vbguestっていうのがなんかいいことをしてるんですけど、いい働きをしようと地盤を整えようとしてさじを投げましたってログが残ってます。これを必ず理解しろとはいわないんですが、vagrant plugin install vagrant-vbguestした記憶がある人はそれで引っかかってるんだなって思ってください。そうじゃない人はすまんわからん。このログの失敗例たくさん存在するからggりましょう。
要するにカーネルのヘッダーのバージョンがいい感じじゃないので困っているらしいです(超意訳)(おれはRuby以外はよくわからん)(なんならRubyもよくわからん)
昔そういう感じの記事を読みあさってなるほどわからんしながら「なんかそこがいい感じじゃないんだな」ってのを学んでたので対応します。
vbguest的には想定内のカーネルのヘッダーじゃないと困るらしいです。Kernel headers not found for target kernelを読む限りそうじゃない? ヘッダーを合わせてインストールしてやればいい(知見/数年Vagrantと戦った結果の無意識の蓄積)らしいのでそうします。
sudo yum install -y kernel-devel-2.6.32-754.35.1.el6.x86_64
対象のカーネルが見つからんからインストールしてくれっていうログの後にこういうのがあります。
Please install them and execute /sbin/rcvboxadd setup
このログから察すると、こうですね。
sudo /sbin/rcvboxadd setup
sudoつけないとバチくそに怒られたのでsudoつけてください。こういうエラーメッセージってroot前提みたいなログだからだまされることが多い。つらい。
怒られた図
[vagrant@xxxx ~]$ /sbin/rcvboxadd setup rm: cannot remove `/var/lib/VBoxGuestAdditions/skip-2.6.32-754.35.1.el6.x86_64': Permission denied FATAL: Could not open /lib/modules/2.6.32-754.35.1.el6.x86_64/modules.dep.temp for writing: Permission denied rm: cannot remove `/etc/kernel/postinst.d/vboxadd': Permission denied rm: cannot remove `/etc/kernel/prerm.d/vboxadd': Permission denied VirtualBox Guest Additions: Starting. rm: cannot remove `/var/lib/VBoxGuestAdditions/skip-2.6.32-754.35.1.el6.x86_64': Permission denied touch: cannot touch `/var/lib/VBoxGuestAdditions/skip-2.6.32-754.35.1.el6.x86_64': Permission denied VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Building the modules for kernel 2.6.32-754.35.1.el6.x86_64. [vagrant@xxxx ~]$ sudo /sbin/rcvboxadd setup VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Building the modules for kernel 2.6.32-754.35.1.el6.x86_64. This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution. modprobe vboxguest failed The log file /var/log/vboxadd-setup.log may contain further information.
いや~~~うまくいったやったね。と思ったあなた、ログを見ましょう。必要なところだけ抜き出したよ。
VirtualBox Guest Additions: Building the modules for kernel 2.6.32-754.35.1.el6.x86_64. This system is currently not set up to build kernel modules. Please install the gcc make perl packages from your distribution. modprobe vboxguest failed
faildしてんじゃん、やだー。じゃあこうだ。-yに関しては好みで入れてね。
sudo yum install gcc make perl
それが終わったらもう一度。
sudo /sbin/rcvboxadd setup
[vagrant@xxxx ~]$ sudo /sbin/rcvboxadd setup VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Building the modules for kernel 2.6.32-754.35.1.el6.x86_64.
なんかうまくいってますね。じゃあvagrantに戻りましょう。
vagrant reload
vagrantがなんかvbguest周辺で再起動してますね。よく分からんけど……いいから通ってくれ……、と思いながらお祈りします。
長いログ
>vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'bento/centos-6.10' version '202012.28.0' 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: Adapter 2: hostonly
default: Adapter 3: hostonly
default: Adapter 4: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> 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: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Connection aborted. Retrying...
==> default: Machine booted and ready!
[default] GuestAdditions seems to be installed (6.1.16) correctly, but not running.
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
2.6.32-754.35.1.el6.x86_64.
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
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: Warning: Connection aborted. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Exporting NFS shared folders...
==> default: Preparing to edit nfs mounting file.
[NFS] Status: halted
[NFS] Start: started
==> default: Mounting NFS shared folders...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o vers=3,udp,vers=3,udp,nolock 30.10.10.1:/<個人情報だよ> /vagrant
Stdout from the command:
Stderr from the command:
mount.nfs: Connection timed out
mount.nfs: Connection timed out ? しらね~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!
また次回お会いしましょう!!!!!!!!!
結論
sudo yum install -y kernel-devel-2.6.32-754.35.1.el6.x86_64 gcc make perl sudo /sbin/rcvboxadd setup