ライン

ポイント:*

ライン

 はじめに

仮想化

 FreeBSDには以前より Jailという仮想化がありますが、これとは別にビーハイブと呼ばれる仮想化があります。
FreeBSD11になって、対応されたOSが増えたという話もあることや、LinuxのKVMを試した後で眺めてみたいという気持ちからさわり始めています。

 前回(昨日)、FreeBSD 11.0-RELEASEの物理環境で試そうとしたところ、”it doesn't look like your cpu supports bhyve (missing POPCNT)”と
なってしまい、先に進めなかったので、リベンジ回としてお試しをやります。
 ただし、物理環境を作るのが手間だったので、VMware上の仮想OSのFreeBSDで動くかを試します。
(仮想の中では動きませんって終わったりして…)

 昨日に学んだところまで進もう

 準備した環境は昨日に同じ、FreeBSD 11.0。freebsd-updateで

#freebsd-version
11.0-RELEASE-p10

というところまでは準備済み。

#kldstat -v|grep vmm
 2    1 0xffffffff82219000 2997     vmmemctl.ko (/usr/local/lib/vmware-tools/modules/drivers/vmmemctl.ko)
                486 vmmemctl

あ…。まぁ、VMwareの環境なので、名前的なそうかもな。

#kldload vmm.ko
#kldstat -v | grep vmm
 2    1 0xffffffff82219000 2997     vmmemctl.ko (/usr/local/lib/vmware-tools/modules/drivers/vmmemctl.ko)
                486 vmmemctl
 7    1 0xffffffff82259000 331f00   vmm.ko (/boot/kernel/vmm.ko)
#dmesg|grep Feature
  Features=0x1fa3fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,DTS,MMX,FXSR,SSE,SSE2,SS,HTT>
  Features2=0x80982201<SSE3,SSSE3,CX16,SSE4.1,SSE4.2,POPCNT,HV>
  AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM>
  AMD Features2=0x1<LAHF>

 動くことを確認。
/boot/loader.conf加えておきます。

# 20170506
vmm_load="YES"

 では、続き。

 sysutils/vm-bhyve

 昨日のところまではいかないと。

#pkg install vm-bhyve
...
New packages to be INSTALLED:
        vm-bhyve: 1.1.5

Number of packages to be installed: 1

45 KiB to be downloaded.

Proceed with this action? [y/N]:y
...
essage from vm-bhyve-1.1.5:
To enable vm-bhyve, please add the following lines to /etc/rc.conf,
depending on whether you are using ZFS storage or not. Please note
that the directory or dataset specified should already exist.

    vm_enable="YES"
    vm_dir="zfs:pool/dataset"

OR

    vm_enable="YES"
    vm_dir="/directory/path"

Then run 'vm init'.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

If upgrading from 1.0 or earlier, please note that the 'guest'
configuration option is no longer used.

Guests that are not using UEFI boot will need either loader="grub"
or loader="bhyveload" in their configuration in order to make sure
the correct loader is used.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

/etc/rc.confに以下を入れて、

# vm bhype
vm_enable="YES"
vm_dir="/opt/vm"

では、コマンドを投入。

#vm init
/usr/local/sbin/vm: ERROR: $vm_dir has not been configured or is not a valid directory

良し! (…でいいのか?)少なくとも昨日と違うメッセージ。

 昨日よりも先のメモ

 では、さらに続き。

#mkdir -p /opt/vm
#vm init
/usr/local/sbin/vm: ERROR: unable to load vmm.ko!
#kldstat
Id Refs Address            Size     Name
 1   15 0xffffffff80200000 1fa88f8  kernel
 2    1 0xffffffff82219000 2997     vmmemctl.ko
 3    1 0xffffffff8221c000 22c3     vmxnet.ko
 4    1 0xffffffff8221f000 2e8a     vmblock.ko
 5    1 0xffffffff82222000 2847     pflog.ko
 6    1 0xffffffff82225000 33bec    pf.ko
 7    1 0xffffffff82259000 331f00   vmm.ko

何だろう。vmっていうのは、bashみたいなので見ておく。

#!/bin/sh
#-------------------------------------------------------------------------+
# Copyright (C) 2015 Matt Churchyard (churchers@gmail.com)
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted providing that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

VERSION=1.1-p5
VERSION_INT=101066
VERSION_BSD=$(uname -K)
PATH=${PATH}:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin

. /etc/rc.subr
load_rc_config "vm"

# get libs
if [ -e "./lib/vm-core" ]; then
    LIB="./lib"
elif [ -e "/usr/local/lib/vm-bhyve" ]; then
    LIB="/usr/local/lib/vm-bhyve"
else
    echo "unable to locate vm-bhyve libriaries"
    exit 1
fi

# load libs
. "${LIB}/vm-cmd"
. "${LIB}/vm-config"
. "${LIB}/vm-core"
. "${LIB}/vm-datastore"
. "${LIB}/vm-guest"
. "${LIB}/vm-info"
. "${LIB}/vm-rctl"
. "${LIB}/vm-run"
. "${LIB}/vm-switch"
. "${LIB}/vm-util"
. "${LIB}/vm-zfs"

# check informational commands
cmd::parse_info $@

# we should be enabled in rc.conf
# or call it using forcestart
[ -z "$rc_force" ] && ! checkyesno vm_enable && util::err "\$vm_enable is not enabled in /etc/rc.conf!"

# check we can run bhyve
util::check_bhyve_support

# init for zfs
zfs::init

# create directories as needed
[ ! -d "${vm_dir}" ] && util::err "\$vm_dir has not been configured or is not a valid directory"
[ ! -d "${vm_dir}/.config" ] && mkdir "${vm_dir}/.config"
[ ! -e "${vm_dir}/.config/null.iso" ] && touch "${vm_dir}/.config/null.iso"
[ ! -d "${vm_dir}/.templates" ] && mkdir "${vm_dir}/.templates"
[ ! -d "${vm_dir}/.iso" ] && mkdir "${vm_dir}/.iso"

# load core configuration
config::core_load
datastore::load

# run the requested command
cmd::parse_args $@
cmd::parse ${VM_COMMAND}

なんとなく、既にloadされているのが原因っぽいな。アンロードして実行。
何もエラーにならんかったので、OKってことでいいのかな。

準備されているテンプレートを配置。

#cp -p  /usr/local/share/examples/vm-bhyve/* /opt/vm/.templates/
#cd /opt/vm/.templates/
#ll
total 52
-rw-r--r--  1 root  wheel    419 Aug 19  2016 alpine.conf
-rw-r--r--  1 root  wheel    354 Aug 19  2016 centos6.conf
-rw-r--r--  1 root  wheel    487 Aug 19  2016 centos7.conf
-rw-r--r--  1 root  wheel  11851 Aug 19  2016 config.sample
-rw-r--r--  1 root  wheel    149 Aug 19  2016 debian.conf
-rw-r--r--  1 root  wheel    136 Aug 19  2016 default.conf
-rw-r--r--  1 root  wheel    156 Aug 19  2016 freebsd-zvol.conf
-rw-r--r--  1 root  wheel    213 Aug 19  2016 netbsd.conf
-rw-r--r--  1 root  wheel    225 Aug 19  2016 openbsd.conf
-rw-r--r--  1 root  wheel    131 Aug 19  2016 ubuntu.conf
-rw-r--r--  1 root  wheel    123 Aug 19  2016 windows.conf

先に。

#vm switch create public
#vm switch add public em0
#ifconfig bridge0
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        description: vm-public
        ether -
        nd6 options=1<PERFORMNUD>
        groups: bridge
        id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
        maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
        root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
        member: em0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 1 priority 128 path cost 20000

問題無いように思えたけど。
シスログ見ると

May  6 10:43:32 bhyve kernel: vmx_init: processor does not support VMX operation
May  6 10:43:32 bhyve kernel: module_register_init: MOD_LOAD (vmm, 0xffffffff8265c4e0, 0) error 6

やっぱり、ちゃんとした環境で実装しないとダメなのかもね。

【改訂履歴】作成:2017/05/06 更新:-/-/-

【参考リンク】

bhyve - FreeBSD Wiki
FreeBSD bhyve + vm-bhyveでゲストにFreeBSD環境を入れてみる – My Scrap book

Copyright © 1996,1997-2006,2007- by F.Kimura,