LoginSignup
1
1

More than 5 years have passed since last update.

CentOS7上でvagrantをインストールし、ubuntu16.06を動かす。

Posted at

CentOS上でvagrantをインストールし、Ubuntu16.06を動かしてみた。
自分への備忘録として残す。

参考サイト

vagrantインストール(ホストOS: Cent OS7)
- https://qiita.com/it__ssei/items/18d54746be2dac56988f
Install Linux kernel-devel
- https://qiita.com/metheglin/items/60261f474ccdfb467574
=> kernel-develのインストールでハマった際に参考にしたサイト。

必要なソフトウェアのインストール

CetOS外部リポジトリを登録する。

dkmsのインストールのために、外部リポジトリを追加する。

$ sudo yum install epel-release

virtualboxに必要なdkmsを入れる。

dkmsとは何かよくわかっていないので、別機会に調べる。

$ sudo yum install dkms

virtualboxをインストールする。

virtual box用のリポジトリを設定する。

$ cd /etc/yum.repos.d/
$ sudo wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

リポジトリ設定を更新する

$ sudo yum update

virtual boxをインストールする。

$ sudo yum search VirtualBox
$ sudo yum install VirtualBox-6.0.x86_64
$ sudo /usr/lib/virtualbox/vboxdrv.sh setup

下記エラーが発生してしまった。

vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
This system is currently not set up to build kernel modules.
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-862.el7.x86_64
This system is currently not set up to build kernel modules.
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-862.el7.x86_64

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.

kernel-devel-3.10.0-862.el7.x86_64をインストールする必要があるらしい。
バージョンを指定してkernel-develをインストールする。

$ sudo yum install kernel-devel-3.10.0-862.el7.x86_64

「そのようなパッケージはありません」と言われてしまう。
色々と情報を探してみた結果、以下のページにたどり着いた。
- https://qiita.com/metheglin/items/60261f474ccdfb467574
上記、ページを参考にkernel-devel-3.10.0-862.el7.x86_64をインストールする。
(どうやら、yum installだと、最新版のものを取ってきてしまい、必ずしもkernelのバージョンと一致するとは限らないらしい。)

まず、kernelのバージョンを確認する。

$ uname -r
3.10.0-862.el7.x86_64

以下のページで、上記バージョンのrpmを検索し、ダウンロードする。
- http://rpm.pbone.net/
検索した結果、リンク切れがいくつかあったため、下記ページ中の「ftp.pbone.net」を任意の場所にダウンロードする。
- http://rpm.pbone.net/index.php3?stat=26&dist=94&size=16424580&name=kernel-devel-3.10.0-862.el7.x86_64.rpm
ダウンロードしたrmpファイルをもとに、パッケージをインストールする。

### 正しいカーネルのバージョンを変数に格納する。
$ KERNEL_VERSION=`uname -r`
$ KERNEL_DEVEL_EXPECTED_VERSION=kernel-devel-${KERNEL_VERSION}
$ echo ${KERNEL_DEVEL_EXPECTED_VERSION}
### インストールする。
$ sudo rpm -ivh ${KERNEL_DEVEL_EXPECTED_VERSION}.rpm
### インストールを確認する。(バージョンがあっているかを確認する。)
$ rpm -qa | grep kernel-devel

再度、virtualboxのセットアップを実行する。

$ sudo /usr/lib/virtualbox/vboxdrv.sh setup
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.

今度は成功した!

vagrantをインストールする。

任意の作業ディレクトリを作成し、そこにrpmをダウンロードする。(2018/12/23時点で最新の2.2.2をダウンロードした)
※ ホストOSと同じビット数のrpmをダウンロードする。

$ cd /tmp
$ sudo wget https://releases.hashicorp.com/vagrant/2.2.2/vagrant_2.2.2_x86_64.rpm

rpmインストールを実行する。

$ sudo yum install vagrant_2.2.2_x86_64.rpm

インストール確認。
バージョンが出ればOK。

$ vagrant --version
Vagrant 2.2.2

VagrantでOSを起動する。

boxを取得する。

下記ページからboxを取得する。
- http://www.vagrantbox.es/
今回は、Ubuntuを入れたかったので、下記を取得した。(色々あって、判断できなかったのでそれっぽいやつを選択した。)
- Official Ubuntu 16.04 daily Cloud Image amd64 (Long Term Support release, No Guest Additions)

vagrantにboxを追加する。

$ vagrant add ubuntu16.04 https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box

起動設定(Vagrantfile)ファイルを作る

任意の作業ディレクトリを作成する。

$ mkdir ubuntu16.04
$ cd ubuntu16.04
$ vagrant init

Vagrantfileが作成されるので、IPアドレスの設定を追加する。

vagrantfile
config.vm.network "private_network", ip: "192.168.38.10"

起動する。

$ vagrant up

下記エラーが発生した。

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "7900f700-bd47-4ba8-83d1-d7476b20adcf", "--type", "headless"]

Stderr: VBoxManage: error: AMD-V is disabled in the BIOS (or by the host OS) (VERR_SVM_DISABLED)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

Web上で調べてみた結果、BIOSの仮想化機能がdisabledになっているらしい。
自分のPCは、AMD-Vなので、下記ページの該当部分を参考にして仮想化機能を有効に設定する。
- https://www.tekwind.co.jp/ASU/faq/entry_134.php

再度、起動を試す。

$ vagrant up

今度は成功!

接続する。

$ vagrant ssh

途中色々はまったが、とりあえず成功した!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1