LoginSignup
1
0

More than 3 years have passed since last update.

MAASでUEFIなKVMゲストを作成する

Posted at

はじめに

前回作ったMAAS環境でKVMゲスト管理も行おうとしたところ、PXEの設定をUEFIオンリーにしていたため、そのままではKVMゲストの作成ができませんでした。

環境

MAASサーバ
・Ubuntu 20.04 arm64
・MAAS 2.9
・MAASのインストールはaptで実施

KVMサーバ(MAASを使ってOSインストール済み)
・Ubuntu 20.04 amd64
・MAASでのデプロイ時に「Register as MAAS KVM host」のオプション付与済み。

KVM側対応

KVM/QEMU用UEFIファームウェアのOVMFをインストールしておきます。

$ sudo apt install ovmf
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
ovmf はすでに最新バージョン (0~20191122.bd85bf54-2ubuntu3.1) です。
ovmf は手動でインストールしたと設定されました。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。

今回は既にインストールされてました。

MAAS側対応

MAASのリポジトリからKVMゲストを作成する処理を探すと、以下に行きつきました。
https://github.com/maas/maas/blob/2.9/src/provisioningserver/drivers/pod/virsh.py

libvirt用のXMLファイルを生成してゲストを作成している様子。

コレに手を入れてOVMFを利用するようにします。

        <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
        <nvram template='/usr/share/OVMF/OVMF_VARS.fd'></nvram>

をXMLテンプレート部分に追記します。
apt packageでMAASをインストールした場合、
「/usr/lib/python3/dist-packages/provisioningserver/drivers/pod/virsh.py」に該当のファイルがありますので、コレに追記。

DOM_TEMPLATE_AMD64 = dedent(
    """\
    <domain type='{type}'>
      <name>{name}</name>
      <uuid>{uuid}</uuid>
      <memory unit='MiB'>{memory}</memory>
      <vcpu>{cores}</vcpu>
      <os>
        <type arch="{arch}">hvm</type>
+        <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
+        <nvram template='/usr/share/OVMF/OVMF_VARS.fd'></nvram>
      </os>
      <features>
        <acpi/>
        <apic/>
      </features>
      <clock offset="utc"/>
      <on_poweroff>destroy</on_poweroff>
      <on_reboot>restart</on_reboot>
      <on_crash>restart</on_crash>
      <pm>
        <suspend-to-mem enabled='no'/>
        <suspend-to-disk enabled='no'/>
      </pm>
      <devices>
        <emulator>{emulator}</emulator>
        <controller type='pci' index='0' model='pci-root'/>
        <controller type='virtio-serial' index='0'>
          <address type='pci' domain='0x0000'
            bus='0x00' slot='0x05' function='0x0'/>
        </controller>
        <serial type='pty'>
          <log file="/var/log/libvirt/qemu/{name}-serial0.log" append="off" />
          <target port='0'/>
        </serial>
        <console type='pty'>
          <target type='serial' port='0'/>
        </console>
        <channel type='spicevmc'>
          <target type='virtio' name='com.redhat.spice.0'/>
          <address type='virtio-serial' controller='0' bus='0' port='1'/>
        </channel>
        <graphics type='spice' autoport='yes'>
          <image compression='off'/>
        </graphics>
        <input type='mouse' bus='ps2'/>
        <input type='keyboard' bus='ps2'/>
      </devices>
    </domain>
    """
)

KVMゲストのデプロイ

ブラウザからMAASにログインし、上部メニューから「KVM」を選択、ゲストを配置するKVMホストを選び「Take Action」ボタンから「Compose」を選択。
スクリーンショット 2021-03-05 20.27.07.png

ゲストの名前やスペックを入力し、「Compose Machine」ボタンをクリック。
スクリーンショット 2021-03-05 20.31.50.png

「Machines」の一覧にKVMゲストが追加されCommissioningが動き出します。
Commissioningが終われば、あとはオンプレの機器と同様にOSをDeploy可能になります。
スクリーンショット 2021-03-05 20.32.32.png

ゲストにUbuntuをデプロイしてログインしてみると、

$ ls /sys/firmware/efi/
config_table  efivars  fw_platform_size  fw_vendor  runtime  runtime-map  systab  vars

とUEFIで起動していることが確認できます。

おわりに

コードを直接書き換えるというゴリ押し方法なので、他にスマートな手があれば知りたいところ。

1
0
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
0