ESXiカスタムISOを作成してみた

はじめに

みなさんこんにちは、段々と秋らしい天気になり、朝夕凍えている少女Aです
さて、先日ESXi on VirtualBoxを試したところパープルスクリーンと遭遇してしまいました
※この時の記事はこちら
VMwareNICドライバの関係で失敗することがあるという噂を聞いていたので、ドライバを入れたISOで試すことにしました

目的

カスタムISOを作成してVirtualBoxにESXi7をインストールする

結論

カスタムISOの作成方法は分かったが、残念ながらESXi7のインストールは失敗した

作成方法

下記を参考に実施したが、結構躓いたので、そこ含めて記載する

カスタムISOに必要なもの

  • PowerCLI
    • Python
    • six
    • pyopenssl
    • psutil
    • lxml
  • NICドライバ
  • ESXi7のパッチファイル

NICドライバ

下記から入手できる flings.vmware.com

ESXi7のパッチファイル

下記から対象のパッチファイルを入手 https://customerconnect.vmware.com/patch

PowerCLIインストール

PowerCLIはオフラインでインストールするパターンとオンラインでインストールする2パターンがある
オンラインの方が簡単そうだったので、オンラインを採用
※画像のZIPじゃない方の右側にあるダウンロードをクリックするとインストール手順が開く
VMware PowerCLI - VMware {code}

PowerShellを管理者権限で開いて、下記コマンドを実行
<コマンド>

PS C:\> Install-Module -Name VMware.PowerCLI

<実行例>※信頼されていないリポジトリが表示されたらYで返す

信頼されていないリポジトリ
信頼されていないリポジトリからモジュールをインストールしようとしています。
このリポジトリを信頼する場合は、Set-PSRepository コマンドレットを実行して、
リポジトリの InstallationPolicy の値を変更してください。'PSGallery'
からモジュールをインストールしますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): Y

<確認コマンド>
PowerCLIがあることを確認

PS C:\>Get-InstalledModule

<実行例>

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
12.6.0.... VMware.CloudServices                PSGallery            PowerCLI CloudServices sample module.
8.0.0.2... VMware.DeployAutomation             PSGallery            This PowerShell module contains PowerCLI Auto De...
8.0.0.2... VMware.ImageBuilder                 PSGallery            This PowerShell module contains PowerCLI ImageBu...
13.1.0.... VMware.PowerCLI                     PSGallery            This Windows PowerShell module contains VMware.P...
12.6.0.... VMware.PowerCLI.Sdk                 PSGallery            Product agnostic types definitions for the VMwar...
…

ここまできたところで問題が発生

Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip
Add-EsxSoftwareDepot : 'Add-EsxSoftwareDepot' コマンドはモジュール 'VMware.ImageBuilder' で見つかりましたが、このモジュ
ールを読み込むことができませんでした。詳細については、'Import-Module VMware.ImageBuilder' を実行してください。
発生場所 行:1 文字:1
+ Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-EsxSoftwareDepot:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

イメージビルダーをインポートする必要があるようなので、下記を実行するがまたもや問題発生
<実行例>

PS C:\> Import-Module VMware.ImageBuilder
Import-Module : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Program Files\WindowsPowerShell\Mod
ules\VMware.VimAutomation.Sdk\13.1.0.21605170\VMware.VimAutomation.Sdk.psm1 を読み込むことができません。詳細については
、「about_Execution_Policies」(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ Import-Module VMware.ImageBuilder
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) [Import-Module]、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
PS C:\> Set-Execution-Policy
Set-Execution-Policy : 用語 'Set-Execution-Policy' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプロ
グラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいこと
を確認してから、再試行してください。
発生場所 行:1 文字:1
+ Set-Execution-Policy
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-Execution-Policy:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PowerShell権限周りの設定がよろしくないっぽいので権限を確認
<実行例>

PS C:\> Get-ExecutionPolicy
Restricted

権限を変更する

PS C:\> Set-ExecutionPolicy RemoteSigned

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): Y

また怒られた。。。
Python入れているはずなのに無いといわれている
<実行例>

Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip
警告: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a
better product. You can join using the following command:

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to
improve its products and services, to fix problems, and to advise you on how best to deploy and use our products.  As
part of the CEIP, VMware collects technical information about your organization窶冱 use of VMware products and services
 on a regular basis in association with your organization窶冱 VMware license key(s).  This information does not
personally identify any individual.

For more details: type "help about_ceip" to see the related help article.

To disable this warning and set your preference use the following command and restart PowerShell:
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.
Add-EsxSoftwareDepot : Failed to initialize the VMware.ImageBuilder PowerCLI module because of error: Unknown error.
Make sure that Python 3.7.1 or higher is installed and that you have set the path to the Python executable by using Set
-PowerCLIConfiguration -PythonPath . See the PowerCLI Compatibility Matrixes for information on the Py
thon requirements.
発生場所 行:1 文字:1
+ Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-EsxSoftwareDepot], Exception
    + FullyQualifiedErrorId : System.Exception,VMware.ImageBuilder.Commands.AddDepot

Python準備

PowerCLIをインストールして動かすためにはPythonが必要なのはわかっているのでPythonの導入準備
ここで問題が発生したのは、Pythonインストールしているはずなのにバージョンが正常に反映されない
<実行例>

PS C:\> python --version
Python

PythonPathが指定されていないと記載があるので、エラーメッセージに表示されていたコマンドを実行する
<実行例>

PS C:\> Set-PowerCLIConfiguration -PythonPath  C:\Windows

Perform operation?
Performing operation 'Update VMware.PowerCLI configuration.'?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): Y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Unset                     True                       300
User
AllUsers

設定できたっぽいので、再度実行したが失敗
<実行例>

PS C:\> Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip
Add-EsxSoftwareDepot : Failed to initialize the VMware.ImageBuilder PowerCLI module because of error: Unknown error.
Make sure that Python 3.7.1 or higher is installed and that you have set the path to the Python executable by using Set
-PowerCLIConfiguration -PythonPath . See the PowerCLI Compatibility Matrixes for information on the Py
thon requirements.
発生場所 行:1 文字:1
+ Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-EsxSoftwareDepot], Exception
    + FullyQualifiedErrorId : System.Exception,VMware.ImageBuilder.Commands.AddDepot

暫くこねくりまわした結果、Pythonが二つインストールされていたことが判明
どうやらPythonは一つである必要があったようだ
片方インストールした結果、正常にバージョンが表示されるようになった
※ここまでで、何時間彷徨ったことだろうか・・・
<実行例>

PS C:\> python --version
Python 3.11.5

まだ足りなかった模様
six, lxml, psutil, pyopensslをインストールするよう案内がある
<実行例>

PS C:\> Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3-18644231-depot.zip
Add-EsxSoftwareDepot : Failed to initialize the VMware.ImageBuilder PowerCLI module because of error: Missing Python mo
dules. Make sure the following Python modules are installed: six, lxml, psutil, pyopenssl.
Make sure that Python 3.7.1 or higher is installed and that you have set the path to the Python executable by using Set
-PowerCLIConfiguration -PythonPath . See the PowerCLI Compatibility Matrixes for information on the Py
thon requirements.
発生場所 行:1 文字:1
+ Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3-18644231-depot.zip
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-EsxSoftwareDepot], Exception
    + FullyQualifiedErrorId : System.Exception,VMware.ImageBuilder.Commands.AddDepot

six, lxml, psutil, pyopenssl.をインストールする
<実行例>

PS C:\> pip install six pyopenssl psutil lxml
Collecting six
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting pyopenssl
  Obtaining dependency information for pyopenssl from https://files.pythonhosted.org/packages/f0/e2/f8b4f1c67933a4907e52228241f4bd52169f3196b70af04403b29c63238a/pyOpenSSL-23.2.0-py3-none-any.whl.metadata
  Downloading pyOpenSSL-23.2.0-py3-none-any.whl.metadata (10 kB)
Collecting psutil
  Downloading psutil-5.9.5-cp36-abi3-win_amd64.whl (255 kB)
     ---------------------------------------- 255.1/255.1 kB 3.9 MB/s eta 0:00:00
Collecting lxml
  Obtaining dependency information for lxml from https://files.pythonhosted.org/packages/31/58/e3b3dd6bb2ab7404f1f4992e2d0e6926ed40cef8ce1b3bbefd95877499e1/lxml-4.9.3-cp311-cp311-win_amd64.whl.metadata
  Downloading lxml-4.9.3-cp311-cp311-win_amd64.whl.metadata (3.9 kB)
Collecting cryptography!=40.0.0,!=40.0.1,<42,>=38.0.0 (from pyopenssl)
  Obtaining dependency information for cryptography!=40.0.0,!=40.0.1,<42,>=38.0.0 from https://files.pythonhosted.org/packages/30/56/5f4eee57ccd577c261b516bfcbe17492838e2bc4e2e92ea93bbb57666fbd/cryptography-41.0.3-cp37-abi3-win_amd64.whl.metadata
  Downloading cryptography-41.0.3-cp37-abi3-win_amd64.whl.metadata (5.3 kB)
Collecting cffi>=1.12 (from cryptography!=40.0.0,!=40.0.1,<42,>=38.0.0->pyopenssl)
  Downloading cffi-1.15.1-cp311-cp311-win_amd64.whl (179 kB)
     ---------------------------------------- 179.0/179.0 kB 5.4 MB/s eta 0:00:00
Collecting pycparser (from cffi>=1.12->cryptography!=40.0.0,!=40.0.1,<42,>=38.0.0->pyopenssl)
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ---------------------------------------- 118.7/118.7 kB 6.8 MB/s eta 0:00:00
Downloading pyOpenSSL-23.2.0-py3-none-any.whl (59 kB)
   ---------------------------------------- 59.0/59.0 kB ? eta 0:00:00
Downloading lxml-4.9.3-cp311-cp311-win_amd64.whl (3.8 MB)
   ---------------------------------------- 3.8/3.8 MB 16.0 MB/s eta 0:00:00
Downloading cryptography-41.0.3-cp37-abi3-win_amd64.whl (2.6 MB)
   ---------------------------------------- 2.6/2.6 MB 21.0 MB/s eta 0:00:00
Installing collected packages: six, pycparser, psutil, lxml, cffi, cryptography, pyopenssl
Successfully installed cffi-1.15.1 cryptography-41.0.3 lxml-4.9.3 psutil-5.9.5 pycparser-2.21 pyopenssl-23.2.0 six-1.16.0

こちらのコマンドもエラーメッセージに表示されていたので実施
<実行例>

PS C:\> Set-PowerCLIConfiguration -PythonPath 'C:\Python311\python.exe'
Perform operation?
Performing operation 'Update VMware.PowerCLI configuration.'?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "Y"): y

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Unset                     True                       300
User
AllUsers

うまくいったっぽい
<実行例>

Add-EsxSoftwareDepot .\VMware-ESXi-7.0U3n-21930508-depot.zip

Depot Url
---------
zip:C:\VMware-ESXi-7.0U3n-21930508-depot.zip?index.xml


PS C:\> Add-EsxSoftwareDepot .\Net-Community-Driver_1.2.7.0-1vmw.700.1.0.15843807_19480755.zip

Depot Url
---------

カスタムISO作成

ネットワークドライバの登録

カスタムISOにネットワークドライバを登録
<実行例>

PS C:\> Add-EsxSoftwareDepot .\Net-Community-Driver_1.2.7.0-1vmw.700.1.0.15843807_19480755.zip

Depot Url
---------
zip:C:\Net-Community-Driver_1.2.7.0-1vmw.700.1.0.15843807_19480755.zip?index.xml

一覧を確認し、ネットワークドライバが追加されたことを確認(★の部分)
<実行例>

PS C:\> Get-EsxSoftwarePackage

Name                     Version                        Vendor     Creation Date
----                     -------                        ------     -------------
lsuv2-intelv2-nvme-vm... 2.7.2173-1vmw.703.0.20.1919... VMware     2022/01/11 23...
lpfc                     14.0.169.26-5vmw.703.0.50.2... VMW        2022/06/30 14...
…
esxio-combiner           7.0.3-0.95.21930508            VMware     2023/06/15 11...
★net-community            1.2.7.0-1vmw.700.1.0.15843807  VMW        2022/03/10 21... 
ntg3                     4.1.9.0-5vmw.703.0.90.21686933 VMW        2023/04/28 14...

イメージプロファイルを確認する
<実行例>

PS C:\> Get-EsxImageProfile

Name                           Vendor          Last Modified   Acceptance Level
----                           ------          -------------   ----------------
ESXi-7.0U3n-21930508-no-tools  VMware, Inc.    2023/06/15 1... PartnerSupported
ESXi-7.0U3n-21930508-standard  VMware, Inc.    2023/07/06 0... PartnerSupported

プロファイルを作成する
※Vendorは任意のものを指定
<実行例>

PS C:\> New-EsxImageProfile -CloneProfile ESXi-7.0U3n-21930508-standard -Name ESXi-7.0U3n-21930508-standard-custom -Vendor HOGE

Name                           Vendor          Last Modified   Acceptance Level
----                           ------          -------------   ----------------
ESXi-7.0U3n-21930508-standa... HOGE            2023/07/06 0... PartnerSupported

追加されていることを確認する
<実行例>

PS C:\> Get-ESXImageProfile

Name                           Vendor          Last Modified   Acceptance Level
----                           ------          -------------   ----------------
ESXi-7.0U3n-21930508-no-tools  VMware, Inc.    2023/06/15 1... PartnerSupported
ESXi-7.0U3n-21930508-standard  VMware, Inc.    2023/07/06 0... PartnerSupported
ESXi-7.0U3n-21930508-standa... HOGE            2023/07/06 0... PartnerSupported

ISO作成コマンドを実行
<実行例>

PS C:\> Export-EsxImageProfile -ImageProfile ESXi-7.0U3n-21930508-standard-custom -ExportToISO -FilePath "ESXi-7.0U3n-custom.iso"

なお、作成したISOで起動したが、パープル画面のままでした。

おわりに

VirtualBoxにESXiをインストールすることはできなかったが、カスタムISOの作成方法が分かった 環境によって前提条件が異なると思うが、前提条件を守らないとPowerCLIをまともに動かすことができないことが分かった