2026/08/30

NetBSD/amd64 11.0でXenを入れてみた話

昔(2011年2008年),NetBSD 4や5の時代にXenを使っていたがdom0のマルチプロセッサー対応が無い事から、すっかり触っていなかった。NetBSD 10からマルチプロセッサー対応が入った(Dom0 kernels now have multiprocessor support enabled.)ので気になっていたが、11.0にバージョンアップしたついでに久しぶりにXenを触ってみた。

今のところ、ubuntu-24.04.4を入れていて、ubuntuの世界からもCPUは2個に見えているみたい。

NetBSD側に入れたパッケージは下記の2個

  • xenkernel420-20260610 Xen 4.20.x Kernel
  • xentools420-20260610 Userland Tools for Xen 4.20.x

基本は本家のXenポートに書かれている「Xen Status and HowTo」を見たやったが下記3点ぐらいがちょっと引っかかった。

1. dom0のメモリ
 HowToにぐちゃぐちゃ書いているのでとありあえず物理16GBのマシンなので半分の8GBを与えて運用中
2. domUの設定ファイルではまる。
設定ファイルのネットワークインターフェイスが「vif = [ 'mac=aa:00:00:d1:00:09,bridge=bridge0' ]」の書き方でHowToに確かに書かれているのだが、Linux方面?だとmacアドレスを記載しない事も多い模様で、その書き方ではNetBSDではダメな模様。その際のエラーがログファイル「/var/log/xen/qemu-XXXXX」に「bn1 is not a bridge」としか出ないので理由が分かりにくかった。
3. domUの自動起動が分かりづらい
HowToには/etc/rc.confに「xendomains="domU-netbsd domU-linux"」と起動したいdomUの名前を書くだけとなっているが、設定ファイルの位置などをどうすればよいか書いていない。これ「man xendomains」としても出るものでもなく、「cat /etc/rc.d/xendomains」とすると冒頭に書かれているぐらいしかヒントが無いのではないだろうか。

    #!/bin/sh
    #
    # PROVIDE: xendomains
    # REQUIRE: xencommons
    # KEYWORD: shutdown
    #
    # xendomains                     This required variable is a whitespace-separated
    #                                                list of domains, e.g., xendomains="dom1 dom2 dom3".
    #
    # xendomains_config       This optional variable is a format string that
    #                                                 represents the path to the configuration file for
    #                                                 each domain.  "%s" is substituted with the name of
    #                                                 the domain.  The default is "/usr/pkg/etc/xen/%s".
    #
    # xendomains_prehook    This optional variable is a format string that
    #                                                   represents the command to run, if it exists, before
    #                                                  starting each domain.  "%s" is substituted with the
    #                                                  name of the domain.  The default is
    #                                                  "/usr/pkg/etc/xen/%s-pre".
    #
    # xendomains_posthook   This optional variable is a format string that
    #                                                   represents the command to run, if it exists, after
    #                                                  stopping each domain.  "%s" is substituted with the
    #                                                   name of the domain.  The default is
    #                                                   "/usr/pkg/etc/xen/%s-post".

HowToの中でdomUの設定ファイル名が「domU-netbsd」とかになっていれば例の記載通りではあるのだが。私は自動起動したいドメインを例えば「domU-01.cfg」であればそれを自動起動用設定ファイルディレクトリ「/usr/pkg/etc/xen/auto/」に格納しているので、rc.confには

  • xendomains="domU-01"
  • xendomains_config="/usr/pkg/etc/xen/auto/%s.cfg"

と書いている。