VMware ESXi から LXD へ乗り換え

VMware が ESXi のフリーライセンスの提供を終了することになったので、LXD に乗り換えることにしました。

サーバー
HPE ProLiant MicroServer Gen10 Plus
CPU
4コア
メモリー
32GB
OS
Ubuntu Server 24.04 LTS 64Bit

LXD をインストール

以下のコマンドで LXD をインストールします。ほとんどの質問には Enter キーだけを押してデフォルトを適用します。

sudo snap install lxd
sudo lxd init

Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]:
Name of the storage backend to use (btrfs, dir, lvm, zfs, ceph) [default=zfs]:
Create a new ZFS pool? (yes/no) [default=yes]:
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]:
Size in GiB of the new loop device (1GiB minimum) [default=30GiB]: 800GiB
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like the LXD server to be available over the network? (yes/no) [default=no]: yes
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]:
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:

ファイアウォールの設定

LXD が持っている自前のファイアウォールが Ubuntu のファイアウォールと干渉するので無効にする。

lxc network set lxdbr0 ipv4.firewall false
lxc network set lxdbr0 ipv6.firewall false

ufw コマンドで LXD のブリッジネットワークのルーティングを許可する。

# allow the guest to get an IP from the LXD host
sudo ufw allow in on lxdbr0 to any port 67 proto udp
sudo ufw allow in on lxdbr0 to any port 547 proto udp

# allow the guest to resolve host names from the LXD host
sudo ufw allow in on lxdbr0 to any port 53

# allow the guest to have access to outbound connections
CIDR4="$(lxc network get lxdbr0 ipv4.address | sed 's|\.[0-9]\+/|.0/|')"
CIDR6="$(lxc network get lxdbr0 ipv6.address | sed 's|:[0-9]\+/|:/|')"
sudo ufw route allow in on lxdbr0 from "${CIDR4}"
sudo ufw route allow in on lxdbr0 from "${CIDR6}"

一通り設定が終わったら再起動をして再起動後も LXD が動作していることを確認します。

Web インターフェースの設定

http://192.168.1.101:8443 にブラウザからアクセスして指示に従ってクライアント用の証明書の作成を行います。インストール時にポートを変更している場合は設定したポートでアクセスします。

証明書の設定が完了して Web インターフェースにアクセスできるようになったら、 Settings タブで “core.trust_password” を設定します。このパスワードはインポート作業が終了したら削除します。

ESXi から Windows 仮想マシンをインポート

必要なファイルを準備

以下のコマンドで virt-2v2 をインストールし、必要なファイルを取得します。

sudo apt install virt-v2v
sudo mkdir /usr/share/virtio-win
cd /usr/share/virtio-win
sudo wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso

以下のコマンドで rhsrvany を取得します。

mkdir ~/tmp
cd ~/tmp
sudo apt install rpm2cpio
wget -nd -O srvany.rpm https://kojipkgs.fedoraproject.org//packages/mingw-srvany/1.1/4.fc38/noarch/mingw32-srvany-1.1-4.fc38.noarch.rpm

rpm2cpio srvany.rpm | cpio -idmv
sudo mkdir /usr/share/virt-tools
sudo mv ./usr/i686-w64-mingw32/sys-root/mingw/bin/*exe /usr/share/virt-tools/

以下のコマンドで Windows 仮想マシンを LXD にインポートできる形式にコンバートします。Linux 仮想マシンも同じコマンドでコンバートできます。

mkdir ./os
sudo virt-v2v --block-driver virtio-scsi -o local -of raw -os ./os -i vmx ./test-vm.vmx

[   0.0] Setting up the source: -i vmx ./test-vm.vmx
[   1.0] Opening the source
[  13.5] Inspecting the source
[  15.1] Checking for sufficient free disk space in the guest
[  15.1] Converting Windows 10 Pro to run on KVM
virt-v2v: This guest has virtio drivers installed.
[  24.7] Mapping filesystem data to avoid copying unused and blank areas
[  25.6] Closing the overlay
[  25.7] Assigning disks to buses
[  25.7] Checking if the guest needs BIOS or UEFI to boot
virt-v2v: This guest requires UEFI on the target to boot.
[  25.7] Setting up the destination: -o disk -os ./os
[  26.8] Copying disk 1/1
  100% [****************************************]
[ 275.0] Creating output metadata
[ 275.0] Finishing off

DLX へインポート

マイグレーションツール bin.linux.lxd-migrate.x86_64 をダウンロードして実行パーミッションを付与します。

cd ~/tmp
wget https://github.com/canonical/lxd/releases/latest/download/bin.linux.lxd-migrate.x86_64
chmod u+x ./bin.linux.lxd-migrate.x86_64

マイグレーションツールを実行して仮想マシンをインポートします。

sudo ./bin.linux.lxd-migrate.x86_64

Please provide LXD server URL: https://192.168.1.101:8443
Certificate fingerprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
ok (y/n)? y
1) Use a certificate token
2) Use an existing TLS authentication certificate
3) Generate a temporary TLS authentication certificate
Please pick an authentication mechanism above: 3
Your temporary certificate is:
-----BEGIN CERTIFICATE-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END CERTIFICATE-----
It is recommended to have this certificate be manually added to LXD through `lxc config trust add` on the target server.
Alternatively you could use a pre-defined trust password to add it remotely (use of a trust password can be a security issue).
Would you like to use a trust password? [default=no]: yes
Trust password: [core.trust_password に設定したパスワード]
Remote LXD server:
  Hostname: lxd-server
  Version: 5.21.1
Would you like to create a container (1) or virtual-machine (2)?: 2
Name of the new instance: test-vm
Please provide the path to a disk, partition, or image file: /path/to/disk/image/test-vm-sda (コンバートしたディスクファイルを指定する)
Does the VM support UEFI Secure Boot? [default=no]:
Instance to be created:
  Name: test-vm
  Project: default
  Type: virtual-machine
  Source: /path/to/disk/image/test-vm-sda
  Config:
    security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 3
Please specify config keys and values (key=value ...): limits.cpu=2
Instance to be created:
  Name: test-vm
  Project: default
  Type: virtual-machine
  Source: /path/to/disk/image/test-vm-sda
  Config:
    limits.cpu: "2"
    security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 3
Please specify config keys and values (key=value ...): limits.memory=4GB
Instance to be created:
  Name: test-vm
  Project: default
  Type: virtual-machine
  Source: /path/to/disk/image/test-vm-sda
  Config:
    limits.cpu: "2"
    limits.memory: 4GB
    security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 4
Please provide the storage pool to use: default
Do you want to change the storage size? [default=no]:
Instance to be created:
  Name: test-vm
  Project: default
  Type: virtual-machine
  Source: /path/to/disk/image/test-vm-sda
  Storage pool: default
  Config:
    limits.cpu: "2"
    limits.memory: 4GB
    security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 5
Please specify the network to use for the instance: lxdbr0
Instance to be created:
  Name: test-vm
  Project: default
  Type: virtual-machine
  Source: /path/to/disk/image/test-vm-sda
  Storage pool: default
  Network name: lxdbr0
  Config:
    limits.cpu: "2"
    limits.memory: 4GB
    security.secureboot: "false"
Additional overrides can be applied at this stage:
1) Begin the migration with the above configuration
2) Override profile list
3) Set additional configuration options
4) Change instance storage pool or volume size
5) Change instance network
Please pick one of the options above [default=1]: 1
Transferring instance: test-vm: 1.03GB (257.25MB/s)
Instance test-vm successfully created

Web インターフェース上からインポートした仮想マシンを起動して動作を確認します。

ネットワーク接続を変更

lxdbr0 を使用してネットワークに接続すると NAT 経由の接続になりますが、以下のコマンドでブリッジ接続に変更できます。

lxc config device remove test-vm eth0  
lxc config device add test-vm eth0 nic nictype=macvlan parent=eno1

仮想マシンをホスト起動時に自動起動

lxc config set test-vm boot.autostart true

トラブルシュート

起動時に failed to load Boot0001 “UEFI QEMU QEMU HARDDISK” エラー

元の仮想マシンが UEFI ではなくレガシー BIOS 設定だった場合に発生しました。以下のコマンドでレガシー BIOS 設定に変更することで起動できました。

lxc config set micro-dyn-onl security.secureboot false
lxc config set micro-dyn-onl security.csm true

Windows 10 の時刻が再起動後にずれる

ホスト側の Ubuntu の時刻が UTC にセットされているのに、ゲスト側の Windows がそれをローカルのタイムゾーンの時刻として認識するのが問題のようです。以下のパスにあるレジストリキー RealTimeIsUniversalQWORD (64-bit) として追加し 1 にセットして再起動します。(DWORD (32-bit) だと動作しませんでした。)

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

参考

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です