bhyve のセットアップ

[FreeBSD インストール (HP Thin Micro TM200 編)](https://qiita.com/bsd-hacker/items/f2d44063e1342f467a42) で [FreeBSD](https://www.freebsd.org/) で仮想環境を作る準備ができました。
今度は仮想環境をセットアップしていきます。
[FreeBSD](https://www.freebsd.org/) で利用可能な仮想環境としては

- [Xen](https://xenproject.org/)
- [bhyve](https://bhyve.org/)
- [VirtualBox](https://www.virtualbox.org/)

といったものがあります。

[Xen](https://xenproject.org/) はまだうまくうごきませんでした。
[Xen Kernel のロード直後にエラーになってしまいました](https://docs.freebsd.org/cgi/getmsg.cgi?fetch=0+0+archive/2021/freebsd-xen/20210523.freebsd-xen)。
それではと [bhyve](https://bhyve.org/) を試してみたところ、こちらは vmm.ko のロードもできて一応動くようなので、仮想環境として [bhyve](https://bhyve.org/) をセットアップしていきます。

# [vm-bhyve](https://github.com/churchers/vm-bhyve) をインストール

[bhyve](https://bhyve.org/) の操作を簡単にするためのツールはいろいろありますが、私は [vm-bhyve](https://github.com/churchers/vm-bhyve) を使っています。
[vm-bhyve](https://github.com/churchers/vm-bhyve) は ZFS が利用できることが前提のため、[FreeBSD](https://www.freebsd.org/) をインストールする際に ZFS を選択してインストールしておくか、インストール後に ZFS の pool を追加で作成してください。

[vm-bhyve](https://github.com/churchers/vm-bhyve) は pkg binary が用意されているので、`pkg install` でインストールできます。

```shell
pkg install vm-bhyve bhyve-firmware grub2-bhyve
```

# [vm-bhyve](https://github.com/churchers/vm-bhyve) をセットアップ

[vm-bhyve](https://github.com/churchers/vm-bhyve) のセットアップ方法については [Quick-Start](https://github.com/churchers/vm-bhyve#quick-start) を参照しながら行っていきます。

## [vm-bhyve](https://github.com/churchers/vm-bhyve) の初期設定

vm-bhyve をインストールしたら初期設定を行っていきます。

まずは VM を作成する ZFS file system を準備します。

```shell
zfs create -o mountpoint=/vm zroot/vm
```

次に vm-bhyve の設定を行います。

```shell
sysrc vm_enable=YES
sysrc vm_dir=zfs:zroot/vm
```

vm-bhyve の初期化コマンドを実行します。

```shell
vm init
```

## ブリッジインタフェースを作成

作成した VM を接続するためのブリッジインタフェースを作成します。
[HP Thin Micro TM200](https://ascii.jp/elem/000/001/448/1448982/) のネットワークインタフェースを igb0, igb1 として認識しているため、どちらのインタフェースに接続するかを選択できるようにインタフェースごとにブリッジインタフェースを作成しておきます。

```shell
vm switch create vswitch-00
vm switch add vswitch-00 igb0
vm switch create vswitch-01
vm switch add vswitch-01 igb1
```

ブリッジインタフェースの一覧を確認します。

```shell
vm switch list
```

```shell
# vm switch list
NAME        TYPE      IFACE          ADDRESS  PRIVATE  MTU  VLAN  PORTS
vswitch-00  standard  vm-vswitch-00  -        no       -    -     00 igb0
vswitch-01  standard  vm-vswitch-01  -        no       -    -     01 igb1
#
```

## デフォルトのテンプレートファイルを設定

VM で使用する OS などに合わせたテンプレートファイルが `/usr/local/share/examples/vm-bhyve/` にインストールされています。
一番インストールすると思われる OS のテンプレートをベースにしてデフォルトのテンプレートファイルを作成しておきます。

[FreeBSD](https://www.freebsd.org/) を多く入れるため、freebsd-zvol.conf をベースにデフォルトテンプレートを作成しておきます。
ネットワークを接続するスイッチインタフェース名だけ作成したブリッジインタフェース名に変更しておきます。

```shell
cat /usr/local/share/examples/vm-bhyve/freebsd-zvol.conf | sed 's/public/vswitch-00/' > /vm/.templates/default.conf
```

# [FreeBSD](https://www.freebsd.org/) 13-RELEASE VM-IMAGES を使って VM を作成

仮想環境で VM をすぐに作成できるように、[FreeBSD](https://www.freebsd.org/) 13-RELEASE がインストールされたディスクイメージが用意されています。
ファイルシステムが '/' 一つだけの UFS になりますが、インストーラーを使ったインストールを行う必要がないため簡単に VM を作成できます。

## [FreeBSD](https://www.freebsd.org/) 13-RELEASE の VM を作成

VM の構成は、

- ディスクサイズ 32GiB
- メモリ 1024MiB
- CPU 2

で作成します。

```shell
vm create -s 32g -m 1024m -c 2 freebsd13-00
```

利用する [FreeBSD](https://www.freebsd.org/) 13-RELEASE がインストールされたディスクイメージのサイズが 6GiB ほどあるため、仮想ディスクのサイズは 8GiB 以上にしてください。
初めて起動したときに自動的にディスクサイズを最大まで拡張してくれるようになっているため、仮想ディスクを大きく作成しても大丈夫です。

## インストール済みのディスクイメージを VM の仮想ディスクに書き込む

用意されている [FreeBSD](https://www.freebsd.org/) 13-RELEASE がインストールされたディスクイメージを dd で書き込みます。
ZFS 用のイメージは用意されていないため、RAW ディスクイメージを書き込みます。

```shell
fetch -o - https://download.freebsd.org/ftp/releases/VM-IMAGES/13.0-RELEASE/amd64/Latest/FreeBSD-13.0-RELEASE-amd64.raw.xz | xz -d | dd of=/dev/zvol/zroot/vm/freebsd13-00/disk0 bs=8k
```

## VM を起動する

ディスクイメージを書き込んだら VM を起動します。

```shell
vm start freebsd13-00
```

## VM の console につなぐ

VM の console に接続します。

```shell
vm console freebsd13-00
```

起動中に console した場合は起動時に表示されるメッセージが表示されます。
何も表示されない場合はすでに起動済みかもしれないため、`RETURN`/`ENTER` キーを押してみてください。

`login: ` プロンプトが表示されれば成功です。

```shell
[root@tm200 ~]# vm console freebsd13-00
Connected


FreeBSD/amd64 (freebsd) (ttyu0)

login:
```

# [FreeBSD](https://www.freebsd.org/) 13-RELEASE インストーラーを使って VM を作成

ファイルシステムを ZFS にしたり、'/' パーティション以外にパーティションを分けたりと細かい調整を行いたい場合はインストーラーを使って [FreeBSD](https://www.freebsd.org/) 13-RELEASE をインストールします。

## [FreeBSD](https://www.freebsd.org/) 13-RELEASE の VM を作成

- ディスクサイズ 32GiB
- メモリ 1024MiB
- CPU 2

の VM を作成します。

```shell
vm create -s 32g -m 1024m -c 2 freebsd13-00
```

## [FreeBSD](https://www.freebsd.org/) 13-RELEASE の ISO イメージを取得

インストールには ISO イメージを使用しますので、[FreeBSD](https://www.freebsd.org/) 13-RELEASE を取得します。

```shell
vm iso https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.0/FreeBSD-13.0-RELEASE-amd64-disc1.iso
```

```shell
vm iso
```

```shell
# vm iso
DATASTORE           FILENAME
default             FreeBSD-13.0-RELEASE-amd64-disc1.iso
#
```

## [FreeBSD](https://www.freebsd.org/) 13-RELEASE をインストール

[FreeBSD](https://www.freebsd.org/) 13-RELEASE をインストールします。

```shell
vm install freebsd13-00 FreeBSD-13.0-RELEASE-amd64-disc1.iso
```

## VM の console につなぐ

VM の console に接続します。

```shell
vm console freebsd13-00
```

起動中に console した場合は起動時に表示されるメッセージが表示されます。
console タイプの選択が表示されれば成功です。
通常はデフォルトの console タイプを選択すれば大丈夫です。

```shell
Starting local daemons:
Welcome to FreeBSD!

Please choose the appropriate terminal type for your system.
Common console types are:
   ansi     Standard ANSI terminal
   vt100    VT100 or compatible terminal
   xterm    xterm terminal emulator (or compatible)
   cons25w  cons25w terminal

Console type [vt100]:
```

何も表示されない場合はすでにインストーラーが起動済みかもしれないため、`RETURN`/`ENTER` キーを押してみてください。
デフォルトの console タイプを選択することになりますが、インストーラーの画面が表示されれば成功です。

```shell
                     lqqqqqqqqqqqqWelcomeqqqqqqqqqqqqqqk
                      x Welcome to FreeBSD! Would you   x
                      x like to begin an installation   x
                      x or use the live CD?             x
                      tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                      x <Install> < Shell > <Live CD>   x
                      mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

## インストール

インストーラーが起動すれば、あとはいつも通りのインストール操作を行って [FreeBSD](https://www.freebsd.org/) 13-RELEASE をインストールしていきます。
今回は選択はデフォルトのものを選択してインストールしてみます。

```shell
                      lqqqqqqqqqqqqWelcomeqqqqqqqqqqqqqqk
                      x Welcome to FreeBSD! Would you   x
                      x like to begin an installation   x
                      x or use the live CD?             x
                      tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                      x <Install> < Shell > <Live CD>   x
                      mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
      lqqqqqqqqqqqqqqqqqqqqqqqKeymap Selectionqqqqqqqqqqqqqqqqqqqqqqqqqqk
      x The system console driver for FreeBSD defaults to standard "US" x
      x keyboard map. Other keymaps can be chosen below.                x
      x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
      x x>>> Continue with default keymap                             x x
      x x->- Test default keymap                                      x x
      x x( ) Armenian phonetic layout                                 x x
      x x( ) Belarusian                                               x x
      x x( ) Belgian                                                  x x
      x x( ) Belgian (accent keys)                                    x x
      x x( ) Brazilian (accent keys)                                  x x
      x x( ) Brazilian (without accent keys)                          x x
      x x( ) Bulgarian (BDS)                                          x x
      x x( ) Bulgarian (Phonetic)                                     x x
      x x( ) Canadian Bilingual                                       x x
      x mqqqq(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq12%qqqqqj x
      tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
      x                   <Select>          <Cancel>                    x
      mqqqqqqqqqqqqqqqqqq[Press arrows, TAB or ENTER]qqqqqqqqqqqqqqqqqqqj

```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq




            lqqqqqqqqqqqqqqqqqqqSet Hostnameqqqqqqqqqqqqqqqqqqqqqqk
            x Please choose a hostname for this machine.          x
            x                                                     x
            x If you are running on a managed network, please ask x
            x your network administrator for an appropriate name. x
            x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
            x x                                                 x x
            x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
            tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
            x                     <  OK  >                        x
            mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
            lqqqqqqqqqqqqqqqqqqqSet Hostnameqqqqqqqqqqqqqqqqqqqqqqk
            x Please choose a hostname for this machine.          x
            x                                                     x
            x If you are running on a managed network, please ask x
            x your network administrator for an appropriate name. x
            x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
            x xtm200.example.jp                                 x x
            x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
            tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
            x                     <  OK  >                        x
            mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq


       lqqqqqqqqqqqqqqqqqqqqqDistribution Selectqqqqqqqqqqqqqqqqqqqqqqqqk
       x Choose optional system components to install:                  x
       x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
       x x [ ] base-dbg    Base system (Debugging)                    x x
       x x [*] kernel-dbg  Kernel (Debugging)                         x x
       x x [ ] lib32-dbg   32-bit compatibility libraries (Debugging) x x
       x x [*] lib32       32-bit compatibility libraries             x x
       x x [ ] ports       Ports tree                                 x x
       x x [ ] src         System source tree                         x x
       x x [ ] tests       Test suite                                 x x
       x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
       x                                                                x
       x                                                                x
       tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
       x                           <  OK  >                             x
       mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq



           lqqqqqqqqqqqqqqqqqqqqqPartitioningqqqqqqqqqqqqqqqqqqqqqqqk
           x How would you like to partition your disk?             x
           x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
           x x   Auto (ZFS)  Guided Root-on-ZFS                   x x
           x x   Auto (UFS)  Guided UFS Disk Setup                x x
           x x   Manual      Manual Disk Setup (experts)          x x
           x x   Shell       Open a shell and partition by hand   x x
           x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
           x                                                        x
           x                                                        x
           tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
           x               <  OK  >        <Cancel>                 x
           mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq

            lqqqqqqqqqqqqqqqqqZFS Configurationqqqqqqqqqqqqqqqqqqqqk
            x Configure Options:                                   x
            x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
            x x  >>> Install          Proceed with Installation  x x
            x x  T Pool Type/Disks:   stripe: 0 disks            x x
            x x  - Rescan Devices     *                          x x
            x x  - Disk Info          *                          x x
            x x  N Pool Name          zroot                      x x
            x x  4 Force 4K Sectors?  YES                        x x
            x x  E Encrypt Disks?     NO                         x x
            x x  P Partition Scheme   GPT (BIOS)                 x x
            x x  S Swap Size          2g                         x x
            x x  M Mirror Swap?       NO                         x x
            x x  W Encrypt Swap?      NO                         x x
            x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
            tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
            x               <Select>        <Cancel>               x
            mqqq[Use alnum, arrows, punctuation, TAB or ENTER]qqqqqj


 Create ZFS boot pool with displayed options
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq



                lqqqqqqqqqqqqqZFS Configurationqqqqqqqqqqqqqqqk
                x Select Virtual Device type:                 x
                x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
                x x stripe  Stripe - No Redundancy          x x
                x x mirror  Mirror - n-Way Mirroring        x x
                x x raid10  RAID 1+0 - n x 2-Way Mirrors    x x
                x x raidz1  RAID-Z1 - Single Redundant RAID x x
                x x raidz2  RAID-Z2 - Double Redundant RAID x x
                x x raidz3  RAID-Z3 - Triple Redundant RAID x x
                x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
                tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                x           <  OK  >      <Cancel>            x
                mqqqqqqqq[Press arrows, TAB or ENTER]qqqqqqqqqj





 [1+ Disks] Striping provides maximum storage but no redundancy
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                     lqqqqqqqqZFS Configurationqqqqqqqqqqk
                     x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
                     x x[*] vtbd0  VirtIO Block Device x x
                     x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
                     tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                     x       <  OK  >    < Back >        x
                     mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq





               lqqqqqqqqqqqqqqZFS Configurationqqqqqqqqqqqqqqqqqk
               x Last Chance! Are you sure you want to destroy  x
               x the current contents of the following disks:   x
               x                                                x
               x  vtbd0                                         x
               x                                                x
               tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
               x             < YES >       < NO  >              x
               mqqqqqqqqq[Press arrows, TAB or ENTER]qqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq



              lqqqqqqqqqqqqqFetching Distributionqqqqqqqqqqqqqqqk
              x                                                 x
              x MANIFEST                         [   Done     ] x
              x base.txz                         [    76%     ] x
              x kernel.txz                       [  Pending   ] x
              x kernel-dbg.txz                   [  Pending   ] x
              x lib32.txz                        [  Pending   ] x
              x                                                 x
              x Fetching distribution files...                  x
              x                                                 x
              x  lqOverall Progressqqqqqqqqqqqqqqqqqqqqqqqqqqk  x
              x  x                    37%                    x  x
              x  mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  x
              mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq





                  lqqqqqqqqqqArchive Extractionqqqqqqqqqqqqqk
                  x Extracting distribution files...        x
                  x                                         x
                  x                                         x
                  x   Overall Progress:                     x
                  x  lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk  x
                  x  x                21%                x  x
                  x  mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  x
                  mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
FreeBSD Installer
========================

Please select a password for the system management account (root):
Typed characters will not be visible.
Changing local password for root
New Password:
```

```shell
FreeBSD Installer
========================

Please select a password for the system management account (root):
Typed characters will not be visible.
Changing local password for root
New Password:
Retype New Password:
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq




                 lqqqqqqqqqqNetwork Configurationqqqqqqqqqqqqk
                 x Please select a network interface to      x
                 x configure:                                x
                 x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
                 x x   vtnet0  VirtIO Networking Adapter   x x
                 x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
                 x                                           x
                 x                                           x
                 tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                 x         <  OK  >     <Cancel>             x
                 mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                         lqqNetwork Configurationqqqqk
                         x Would you like to         x
                         x configure IPv4 for this   x
                         x interface?                x
                         tqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                         x     < Yes >   < No  >     x
                         mqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                         lqqNetwork Configurationqqqqk
                         x Would you like to use     x
                         x DHCP to configure this    x
                         x interface?                x
                         tqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                         x     < Yes >   < No  >     x
                         mqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                         lqqNetwork Configurationqqqqk
                         x Would you like to         x
                         x configure IPv6 for this   x
                         x interface?                x
                         tqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                         x     < Yes >   < No  >     x
                         mqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                         lqqNetwork Configurationqqqqk
                         x Would you like to try     x
                         x stateless address         x
                         x autoconfiguration         x
                         x (SLAAC)?                  x
                         tqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                         x     < Yes >   < No  >     x
                         mqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq




    lqqqqqqqqqqqqqqqqqqqqqqqNetwork Configurationqqqqqqqqqqqqqqqqqqqqqqqqqqk
    x Resolver Configuration                                               x
    x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
    x xSearch                                                            x x
    x xIPv6 DNS #1                                                       x x
    x xIPv6 DNS #2                                                       x x
    x xIPv4 DNS #1    192.168.1.1                                        x x
    x xIPv4 DNS #2    192.168.1.2                                        x x
    x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
    tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
    x                     <  OK  >           <Cancel>                      x
    mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

```

```shell
                     lqqqqqqqTime Zone Selectorqqqqqqqqqqk
                     x Select a region                   x
                     x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
                     x x 1  Africa                     x x
                     x x 2  America -- North and South x x
                     x x 3  Antarctica                 x x
                     x x 4  Asia                       x x
                     x x 5  Atlantic Ocean             x x
                     x x 6  Australia                  x x
                     x x 7  Europe                     x x
                     x x 8  Indian Ocean               x x
                     x x 9  Pacific Ocean              x x
                     x x 0  UTC                        x x
                     x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
                     tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                     x       <  OK  >    <Cancel>        x
                     mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
              lqqqqqqqqqqqqqqqCountries in Asiaqqqqqqqqqqqqqqqqqk
              x Select a country or region                      x
              x lqqqq(-)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
              x x 9   China                                   x x
              x x 10  Cyprus                                  x x
              x x 11  Georgia                                 x x
              x x 12  Hong Kong                               x x
              x x 13  India                                   x x
              x x 14  Indonesia                               x x
              x x 15  Iran (Islamic Republic of)              x x
              x x 16  Iraq                                    x x
              x x 17  Israel                                  x x
              x x 18  Japan                                   x x
              x x 19  Jordan                                  x x
              x x 20  Kazakhstan                              x x
              x x 21  Korea (Democratic People's Republic of) x x
              x x 22  Korea (Republic of)                     x x
              x x 23  Kuwait                                  x x
              x x 24  Kyrgyzstan                              x x
              x mqqqq(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqq48%qqqqqj x
              tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
              x             <  OK  >       <Cancel>             x
              mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
              lqqqqqqqqqqqqqqqCountries in Asiaqqqqqqqqqqqqqqqqqk
              x Select a country or region                      x
              x lqqqq(-)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
              x x 9   China                                   x x
              x x 10  Cyprus                                  x x
              x x 11  Georgia                                 x x
              x x 12  Hong Kong                               x x
              x x 13  India                                   x x
              x x 14  Indonesia                               x x
    lqqqqqqqqqqqqqqqqqqqqqqqqqqqqConfirmationqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
    x Does the abbreviation `JST' look reasonable?                         x
    tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
    x                     < Yes >           < No  >                        x
    mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
              x x 20  Kazakhstan                              x x
              x x 21  Korea (Democratic People's Republic of) x x
              x x 22  Korea (Republic of)                     x x
              x x 23  Kuwait                                  x x
              x x 24  Kyrgyzstan                              x x
              x mqqqq(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqq48%qqqqqj x
              tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
              x             <  OK  >       <Cancel>             x
              mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq

                    lqqqqqqqqqqqqTime & Dateqqqqqqqqqqqqqqqk
                    x                                      x
                    x  Month            Year               x
                    x  lqqqqqqqqqqqqqqqklqqqqqqqqqqqqqqqk  x
                    x  xJune           xx2021           x  x
                    x  mqqqqqqqqqqqqqqqjmqqqqqqqqqqqqqqqj  x
                    x  lqqqqq(-)qqqqqqqqqqqqqqqqqqqqqqqk  x
                    x  x    Sun Mon Tue Wed Thu Fri Sat x  x
                    x  x 23           1   2   3   4   5 x  x
                    x  x 24   6   7   8   9  10  11  12 x  x
                    x  x 25  13  14  15  16  17  18  19 x  x
                    x  x 26  20  21  22  23  24  25  26 x  x
                    x  x 27  27  28  29  30             x  x
                    x  x                                x  x
                    x  mqqqqq(+)qqqqqqqqqqqqqqqqqqqqqqqj  x
                    tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                    x       <Set Date>    <  Skip  >       x
                    mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq





                    lqqqqqqqqqqqqTime & Dateqqqqqqqqqqqqqqqk
                    x                                      x
                    x           lqqk lqqk lqqk             x
                    x           x07x:x23x:x05x             x
                    x           mqqj mqqj mqqj             x
                    x                                      x
                    tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                    x       <Set Time>    <  Skip  >       x
                    mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq


   lqqqqqqqqqqqqqqqqqqqqqqqqSystem Configurationqqqqqqqqqqqqqqqqqqqqqqqqqqqk
   x Choose the services you would like to be started at boot:             x
   x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
   x x [ ] local_unbound  Local caching validating resolver              x x
   x x [*] sshd           Secure shell daemon                            x x
   x x [ ] moused         PS/2 mouse pointer on console                  x x
   x x [ ] ntpdate        Synchronize system and network time at bootime x x
   x x [ ] ntpd           Synchronize system and network time            x x
   x x [ ] powerd         Adjust CPU frequency dynamically if supported  x x
   x x [*] dumpdev        Enable kernel crash dumps to /var/crash        x x
   x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
   x                                                                       x
   x                                                                       x
   tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
   x                               <  OK  >                                x
   mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqSystem Hardeningqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x Choose system security hardening options:                                    x
x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
x x[ ] 0 hide_uids        Hide processes running as other users              x x
x x[ ] 1 hide_gids        Hide processes running as other groups             x x
x x[ ] 2 hide_jail        Hide processes running in jails                    x x
x x[ ] 3 read_msgbuf      Disable reading kernel message buffer for unprivilex x
x x[ ] 4 proc_debug       Disable process debugging facilities for unprivilegx x
x x[ ] 5 random_pid       Randomize the PID of newly created processes       x x
x x[ ] 6 clear_tmp        Clean the /tmp filesystem on system startup        x x
x x[ ] 7 disable_syslogd  Disable opening Syslogd network socket (disables rex x
x x[ ] 8 disable_sendmail Disable Sendmail service                           x x
x x[ ] 9 secure_console   Enable console password prompt                     x x
x x[ ] 10 disable_ddtrace Disallow DTrace destructive-mode                   x x
x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
x                                                                              x
x                                                                              x
x                                                                              x
tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
x                                   <  OK  >                                   x
mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                         lqqqqAdd User Accountsqqqqqqk
                         x Would you like to add     x
                         x users to the installed    x
                         x system now?               x
                         tqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                         x     < Yes >   < No  >     x
                         mqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
   lqqqqqqqqqqqqqqqqqqqqqqqqqFinal Configurationqqqqqqqqqqqqqqqqqqqqqqqqqqqk
   x Setup of your FreeBSD system is nearly complete. You can now modify   x
   x your configuration choices. After this screen, you will have an       x
   x opportunity to make more complex changes using a shell.               x
   x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x
   x x   Exit              Apply configuration and exit installer        x x
   x x   Add User          Add a user to the system                      x x
   x x   Root Password     Change root password                          x x
   x x   Hostname          Set system hostname                           x x
   x x   Network           Networking configuration                      x x
   x x   Services          Set daemons to run on startup                 x x
   x x   System Hardening  Set security options                          x x
   x x   Time Zone         Set system timezone                           x x
   x x   Handbook          Install FreeBSD Handbook (requires network)   x x
   x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x
   x                                                                       x
   x                                                                       x
   tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
   x                               <  OK  >                                x
   mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq





                    lqqqqqqqManual Configurationqqqqqqqqqqk
                    x The installation is now finished.   x
                    x Before exiting the installer, would x
                    x you like to open a shell in the new x
                    x system to make any final manual     x
                    x modifications?                      x
                    tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                    x         < Yes >     < No  >         x
                    mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
 FreeBSD Installer
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq






                         lqqqqqqqqqCompleteqqqqqqqqqqqk
                         x Installation of FreeBSD    x
                         x complete! Would you like   x
                         x to reboot into the         x
                         x installed system now?      x
                         tqqqqqqqqqqqqqqqqqqqqqqqqqqqqu
                         x   <Reboot >  <Live CD>     x
                         mqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
```

```shell
Starting background file system checks in 60 seconds.

Fri Jun 25 07:26:18 JST 2021

FreeBSD/amd64 (tm200.example.jp) (ttyu0)

login:
```

# インストール済みのディスクイメージを作成

[FreeBSD](https://www.freebsd.org/) 13-RELEASE の VM を複数作成する場合、作成した VM のディスクイメージを作成しておくと VM のコピーを楽に作成できるようになります。
ディスクイメージを作成する場合は、VM と停止してディスクイメージが更新されないようにしておくと安心です。

```shell
vm stop freebsd13-00
```

```shell
root@tm200 ~]# vm stop freebsd13-00
Sending ACPI shutdown to freebsd13-00
[root@tm200 ~]#
```

VM が停止したら VM のイメージを作成します。

```shell
vm image create -d 'FreeBSD 13-RELEASE' -u freebsd13-00
```

```shell
[root@tm200 ~]# vm image create -d 'FreeBSD 13-RELEASE' -u freebsd13-00
Creating guest image, this may take some time...
Image of freebsd13-00 created with UUID dff37c0e-d53c-11eb-9cf7-1402ec4997a4
[root@tm200 ~]#
```

```shell
vm image list
```

```shell
[root@tm200 ~]# vm image list
UUID                                  NAME          CREATED                                 DESCRIPTION
dff37c0e-d53c-11eb-9cf7-1402ec4997a4  freebsd13-00  2021年 6月25日 金曜日 07時38分19秒 JST  FreeBSD 13-RELEASE
[root@tm200 ~]#
```

# 作成したディスクイメージを使って VM を作成

ディスイメージを使って VM を作成してみます。
VM を作成する場合、利用するディスクイメージの UUID を指定する必要があるため UUID を確認します。

```shell
vm image list
```

```shell
[root@tm200 ~]# vm image list
UUID                                  NAME          CREATED                                 DESCRIPTION
dff37c0e-d53c-11eb-9cf7-1402ec4997a4  freebsd13-00  2021年 6月25日 金曜日 07時38分19秒 JST  FreeBSD 13-RELEASE
[root@tm200 ~]#
```

今回は dff37c0e-d53c-11eb-9cf7-1402ec4997a4 を使います。

```shell
vm image provision dff37c0e-d53c-11eb-9cf7-1402ec4997a4 freebsd13-01
```

```shell
[root@tm200 ~]# vm image provision dff37c0e-d53c-11eb-9cf7-1402ec4997a4 freebsd13-01
Unpacking guest image, this may take some time...
[root@tm200 ~]#
```

VM が作成されていることを確認します。

```shell
vm  list
```

```shell
[root@tm200 ~]# vm list
NAME          DATASTORE  LOADER     CPU  MEMORY  VNC  AUTOSTART  STATE
freebsd13-00  default    bhyveload  2    1024m   -    No         Stopped
freebsd13-01  default    bhyveload  2    1024m   -    No         Stopped
[root@tm200 ~]#
```

VM が作成できました。

# 終わりに

[FreeBSD インストール (HP Thin Micro TM200 編)](https://qiita.com/bsd-hacker/items/f2d44063e1342f467a42) で [FreeBSD](https://www.freebsd.org/) で作成した環境に仮想環境を作ることができました。
あとは、いろいろな VM を作成して環境を整えていくことになります。