sseze's blog

インターネットとガジェットが好きな人のブログです

Virtualbox上で MacOSX Mountain Lion <=> CentOS 6.3 間の共有フォルダを作る際に、Guest Additionsのインストールに失敗する

Virtualboxで、MacとCentOS間の共有フォルダを作りたい、と思い、
http://mirutover.blogspot.jp/2012/08/virtualbox-centos-guest-additions.html
などを見てトライアンドエラーしていた。

Virtualboxのメニューから、「Devices」→「Install Guest Additions... (Host + D)」をクリック。
インストールCDが入るので、マウント。

[root@centos63 ~]# mkdir /mnt/cdrom
[root@centos63 ~]# mount -r /dev/cdrom /mnt/cdrom
[root@centos63 ~]# cd /mnt/cdrom
[root@centos63 ~]# ./VBoxLinuxAdditions.run

と、ここで怒られる。

[root@centos63 cdrom]# ./VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.2.4 Guest Additions for Linux..........
VirtualBox Guest Additions installer
Removing installed version 4.2.4 of VirtualBox Guest Additions...
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-279.14.1.el6.i686

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                       [FAILED]
(Could not find the X.Org or XFree86 Window System.)

調べてみたところ、ここに解決方法が載っていた。

CentOSなどの一部のLinuxでは以下のようなエラーメッセージが表示され、インストールに失敗する事があります。
これはGuestAdditionがkernelのソースコードを必要としているのに、システムにソースコードがインストールされていないために発生します。
Building the VirtualBox Guest Additions Kernel modules [失敗]

以下でkernelソースをインストールしてから再びインストールスクリプトを実行します。
# yum install kernel-devel

kernel-develをyumでインストールして再度、VBoxLinuxAdditions.runを実行したところ、X Window以外は正常にインストールできた。

※ 2013年01月18日 追記

インストール直後だと、kernelのインストールだけでは動かないことが判明。
/var/log/vboxadd-install.log を見ると、gcc, make, perl がインストールされていないと、正常に動かないことが分かる。
したがって、

# yum install gcc make perl

してから、次に進む。

[root@centos63 cdrom]# ./VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.2.4 Guest Additions for Linux..........
VirtualBox Guest Additions installer
Removing installed version 4.2.4 of VirtualBox Guest Additions...
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                       [FAILED]
(Could not find the X.Org or XFree86 Window System.)

あとは、「Devices」→「Shared Folders」からGUIで共有したいフォルダを指定するだけ。
設定し終わったら、VM再起動。/media/sf_~(Mac側で付けた共有フォルダ名)に共有ディレクトリが作成される。

が、このままだと、一般ユーザに共有ディレクトリの使用権限がないと言われる。

[sseze@centos63 ~]$ cd /media/sf_centos_share/
-bash: cd: /media/sf_centos_share/: 許可がありません

以下の手順に添って作業ユーザ(今回は、"sseze"というユーザ)を登録する必要がある。

[root@centos63 ~]# gpasswd -a sseze vboxsf
Adding user sseze to group vboxsf

一度、ログインシェルを出て、再度ログインすると、共有フォルダが使えるようになる。

[sseze@centos63 ~]$ cd /media/sf_centos_share/
[sseze@centos63 sf_centos_share]$