SEワンタンの独学備忘録

IT関連の独学した内容や資格試験に対する取り組みの備忘録

【GCP】GCE(CentOS7)にVirtualBoxをインストールする


前提としてはGCPのプロジェクトが作成されていることと、Cloud SDKがインストールされていることになります。

Cloud SDKのインストールは以下の記事にあります。

www.wantanblog.com

カスタムイメージの作成

GCEはそもそも仮想マシン上に存在するマシンなので、そこにVirtualBoxをインストールする場合は仮想マシンのネスト構造となります。
GCE上でネストを実現するためにはデフォルトのイメージではできず、カスタムイメージを作成してVT-x を有効にする必要があります。

以下は特に指定のない場合、カスタムイメージの作成のコマンド実行はCloud SDKから実行します。

イメージの確認

コマンドで取得するため公式のイメージを確認しておきます。

gcloud compute images list

・出力結果の抜粋
今回はCentOS7を使用します。

NAME PROJECT FAMILY DEPRECATED STATUS
centos-7-v20200521 centos-cloud centos-7 READY

カスタムイメージの作成

GCEに適用するためのカスタムイメージをCloud SDKから作成します。
以下のコマンドを実行します。

gcloud compute images create nested-centos7-image --source-image=projects/centos-cloud/global/images/centos-7-v20200521 --licenses "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx

VT-x を有効にしているのは「--licenses」の部分です。
また、source-imageは「イメージの確認」で確認したものを以下の形で指定します。

--source-image=projects/[PROJECT]/global/images/[NAME]

以下の表示がされれば問題なく生成されているようです。

NAME PROJECT FAMILY DEPRECATED STATUS
nested-centos7-image wantanblog-pj READY

管理コンソールのイメージからも以下のように確認できます。

f:id:wantanBlog:20200603003345p:plain

GCEインスタンスの生成

先ほど作成したカスタムイメージを使用してインスタンスを生成します。

インスタンスがわからない場合には以下の記事も参照。

www.wantanblog.com

カスタムイメージを適用するにはブートディスクだけ以下のように今回作成したものを指定するだけです。

f:id:wantanBlog:20200603004807p:plain


インスタンスを生成したら任意のターミナルからログインできる状態にします。
方法は任意です。以下の記事はWindowsホストからteratermで接続する手順です。

www.wantanblog.com

最後にインスタンスにログインして、今回の目的であるVT-x が有効になっていることを確認します。

以下のコマンドを実行して結果が返ってくることを確認します。

grep vmx /proc/cpuinfo

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat md_clear spec_ctrl intel_stibp arch_capabilities

flagsに「vmx」が含まれていることが確認できていればOKです。

GCEインスタンスにVirtualBoxをインストール

インストーラの設置

VirtualBoxのインストーラをインスタンスの任意の場所に配置します。
今回は以下バージョンを取り扱います。
・VirtualBox-5.2-5.2.42_137960_el7-1.x86_64.rpm

インストーラの場所がわからない場合は以下の記事も参照してください。

www.wantanblog.com

インストール

少なくともGCPのCentOS7の場合はすぐにインストールできないと思いますが、まずはrpmファイルが存在する場所でインストールコマンドを実行してみます。

rpm -ihv VirtualBox-5.2-5.2.42_137960_el7-1.x86_64.rpm

・出力結果

warning: VirtualBox-5.2-5.2.42_137960_el7-1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 98ab5139: NOKEY
error: Failed dependencies:
libGL.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libICE.so.6()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libSDL-1.2.so.0()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libSM.so.6()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libX11-xcb.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libX11.so.6()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libXcursor.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libXext.so.6()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libXinerama.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libXmu.so.6()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libXrender.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libXt.so.6()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libfontconfig.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libopus.so.0()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libvpx.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64
libxcb.so.1()(64bit) is needed by VirtualBox-5.2-5.2.42_137960_el7-1.x86_64

想定通り、すぐにはインストールできなかったので解消していきます。

もっとかしこい方法があるかもしれませんが一つ一つ見ていきます。

■yum searchで検索したもの

まずはyumからすぐにインストールできるものをインストールしました。

yum search libSM

・出力結果の抜粋

libSM.x86_64 : X.Org X11 SM runtime library

対象のパッケージが分かったらyumでインストールします。
一つずつ確認したため、以下では対象パッケージ一つに一行のインストールコマンドを実行してますが、対象パッケージがわかっているなら一度にインストールしてしまってもOK。

yum install libSM.x86_64
yum install libX11.x86_64
yum install libglvnd-glx.x86_64
yum install libXcursor.x86_64
yum install libXinerama.x86_64
yum install libXmu.x86_64

■別のパッケージ名でインストール

以前に見たことがあったためパッケージ名でインストールしたもの。

yum install SDL


■rpmファイルをダウンロードしてインストールしたもの

いくつかのパッケージはyumでインストールできなかったため、rpmファイルをダウンロードしてインストールしました。
サーバに配置してrpmでインストールしています。


・fontconfig-2.13.0-4.3.el7.x86_64.rpm

https://centos.pkgs.org/7/centos-x86_64/fontconfig-2.13.0-4.3.el7.x86_64.rpm.html

rpm -ihv fontconfig-2.13.0-4.3.el7.x86_64.rpm

・dejavu-sans-fonts-2.33-6.el7.noarch

yumに存在しますが依存関係がそのままだと解消できなかったので上記のパッケージをインストールしてからインストールしました。

yum install dejavu-sans-fonts-2.33-6.el7.noarch


・opus-1.0.2-6.el7.x86_64.rpm

https://centos.pkgs.org/7/centos-x86_64/opus-1.0.2-6.el7.x86_64.rpm.html

rpm -ihv opus-1.0.2-6.el7.x86_64.rpm

・libvpx-1.3.0-5.el7_0.x86_64.rpm

https://centos.pkgs.org/7/centos-x86_64/libvpx-1.3.0-5.el7_0.x86_64.rpm.html

rpm -ihv libvpx-1.3.0-5.el7_0.x86_64.rpm


再インストール!!
インストールには成功していますが、起動に失敗しています。

root@nestedvm-centos7 wantan]# rpm -ihv VirtualBox-5.2-5.2.42_137960_el7-1.x86_64.rpm
warning: VirtualBox-5.2-5.2.42_137960_el7-1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 98ab5139: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:VirtualBox-5.2-5.2.42_137960_el7-################################# [100%]

Creating group 'vboxusers'. VM users must be member of that group!

This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-1127.8.2.el7.x86_64
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-1127.8.2.el7.x86_64

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.  If your system is using EFI Secure Boot you may need to sign the
kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
 them. Please see your Linux system's documentation for more information.

必要だと言われているパッケージをインストールします。

yum install kernel-devel-3.10.0-1127.8.2.el7.x86_64
yum install gcc

起動コマンドを実行します。

[root@nestedvm-centos7 wantan]# /sbin/vboxconfig
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.

エラーが出ていなければ今度こそいけてるはず!!