之前我们封装ESXi ISO镜像大多使用的是GitHub - VFrontDe/ESXi-Customizer-PS: PowerCLI script that greatly simplifies and automates the process of creating fully patched and customized VMware ESXi installation images这个项目的powershell脚本,把一些社区版驱动(比如网卡驱动,USB网卡驱动等)封装进ESXi ISO,这样安装时就可以直接识别相应的硬件了。
实际上上述脚本就是基于VMware.PowerCLI 来实现的。PowerCLI是VMware的一个非常强大的Powershell命令库,有近700 cmdlets 可以用来管理和自动化VMware很多产品(比如vSphere, vCloud Director, vRealize Operations Manager, vSAN, NSX-T, VMware Cloud Services, VMware Cloud on AWS, VMware HCX, VMware Site Recovery Manager, and VMware Horizon environments)。而PowerCLI 12.0.0版本更新中,关于ISO镜像,有如下描述:
New cmdlets for managing auto-bootstrapping and new-style depots in vSphere 7.0 have been added to theVMware.DeployAutomationandVMware.ImageBuildermodule:
New/Set/Reset-LCMClusterRuleWithTransform
Get-DepotAddons
Get-DepotBaseImages
Get-DepotComponents
Get-DepotInfo
Get-DepotVibs
New-IsoImage
New-PxeImage
我们注意到它提到了加入了New-IsoImage(通过VMware.ImageBuildermodule)。
查询相关文档,New-IsoImage Command | VMware PowerCLI Reference和Create a Custom ESXi ISO Image with PowerCLI Cmdlets (vmware.com)有很详细的使用方法。
接下来我们在Windows 11 (Windows 10同理)环境下配置下环境来学习下用法。
1. “以管理员身份运行” Windows Powershell 或者Windows Terminal。
2. Install-Module -Name VMware.PowerCLI此过程中如果有提示是否安装NuGet以及是否要从"PSGallery"安装模块请选择“是”,“全是”。视网络情况,此安装过程可能需要几分钟。
3. 设置Execution policy, Windows 默认不允许执行此类第三方脚本Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine具体详细用法可以参照Set-ExecutionPolicy (Microsoft.PowerShell.Security) - PowerShell | Microsoft Docs
4. Import-Module VMware.ImageBuilder
5. 我们先使用VMwre的官方online repo来查看有哪些Image profile
Get-DepotBaseImages -Depot https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml
查询需要几十秒:
Version Vendor Release date
------- ------ ------------
7.0.0-1.25.16324942 VMware, Inc. 06/15/2020 23:00:00
7.0.0-1.20.16321839 VMware, Inc. 06/15/2020 23:00:00
7.0.0-1.0.15843807 VMware, Inc. 03/16/2020 08:40:41
7.0.1-0.35.19324898 VMware, Inc. 02/14/2022 23:00:00
7.0.1-0.15.17168206 VMware, Inc. 11/18/2020 23:00:00
7.0.1-0.10.17119627 VMware, Inc. 11/03/2020 23:00:00
7.0.1-0.25.17325551 VMware, Inc. 12/16/2020 23:00:00
7.0.1-0.20.17325020 VMware, Inc. 12/16/2020 23:00:00
7.0.1-0.30.17551050 VMware, Inc. 02/03/2021 23:00:00
7.0.1-0.0.16850804 VMware, Inc. 09/04/2020 16:33:22
7.0.2-0.0.17867351 VMware, Inc. 04/28/2021 23:00:00
7.0.2-0.15.18295176 VMware, Inc. 08/23/2021 23:00:00
7.0.2-0.20.18426014 VMware, Inc. 08/23/2021 23:00:00
7.0.2-0.25.18538813 VMware, Inc. 09/13/2021 23:00:00
7.0.2-0.30.19290878 VMware, Inc. 02/14/2022 23:00:00
7.0.3-0.20.19193900 VMware, Inc. 01/17/2022 23:00:00
7.0.3-0.30.19482531 VMware, Inc. 03/28/2022 23:00:00
7.0.3-0.35.19482537 VMware, Inc. 03/28/2022 23:00:00
其实-Depot这个参数也是可以指向一个本地的离线包(非ISO),比如:
Get-DepotBaseImages -Depot C:\CustomImage\VMware-ESXi-7.0U3c-19193900-depot.zip
Version Vendor Release date
------- ------ ------------
7.0.3-0.20.19193900 VMware, Inc. 01/17/2022 23:00:00
类似的还有Get-DepotAddons 和 Get-DepotComponents
比如可以查询社区版网卡驱动包:
Get-DepotComponents -Depot C:\CustomImage\Net-Community-Driver_1.2.7.0-1vmw.700.1.0.15843807_19480755.zip
6. 接下来创建一个自定义镜像的Spec (json格式):
{
"base_image": {
"version": "7.0.3-0.35.19482537"
},
"components": {
"Net-Community-Driver": "1.2.7.0-1vmw.700.1.0.15843807"
}
}
7. 利用前面查询到的离线包,驱动文件和spec文件来制作自定义镜像:
New-IsoImage -Depots "c:\CustomImage\VMware-ESXi-7.0U3c-19193900-depot.zip" , "c:\CustomImage\Net-Community-Driver_1.2.7.0-1vmw.700.1.0.15843807_19480755.zip" -SoftwareSpec "c:\CustomImage\spec.json" -Destination "c:\CustomImage\ESXi-70U3c-custom.iso"
PS: 此方法尝试封装USB NIC Flings时会报错,是该驱动的一个小bug,估计后续会修复。
New-IsoImage : Error retrieving file for VIB 'VMW_bootbank_vmkusb-nic-fling_1.8-3vmw.703.0.15.51233328':
("
mode='r' compress_type=deflate>", "Error opening file object for VIB
'VMW_bootbank_vmkusb-nic-fling_1.8-3vmw.703.0.15.51233328': Expected value '[]' for attribute 'swplatforms', but found
value '[
]'.").