制作HYPER-V的镜像还是很简单的,基本自动化。
参考资料看Cloudbase网站的blog文章(https://cloudbase.it/create-windows-openstack-images/)基本没用。真正有用的在这里:https://github.com/cloudbase/windows-openstack-imaging-tools。
基本步骤汇总如下(制作镜像的主机是windows server 2012 r2,安装完HYPER-V的,全是在powershell中运行):
git clone https://github.com/cloudbase/windows-openstack-imaging-tools.git
pushd windows-openstack-imaging-tools
Import-Module .\WinImageBuilder.psm1
# The Windows image file path that will be generated
$windowsImagePath = "C:\images\my-windows-image.vhdx"
# The wim file path is the installation image on the Windows ISO
# 这一步需要把windows iso文件展开,把其中sources目录下的install.wim文件拷出来
$wimFilePath = "D:\Sources\install.wim"
# Every Windows ISO can contain multiple Windows flavors like Core, Standard, Datacenter
# Usually, the first image version is the Core one
$image = (Get-WimFileImagesInfo -WimFilePath $wimFilePath)[0]
#这个文件还是从国内下吧,没有VPN很慢
$virtIOISOPath = "C:\images\virtio.iso"
# Note(avladu): Do not use stable 0.1.126 version because of this bug https://github.com/crobinso/virtio-win-pkg-scripts/issues/10$virtIODownloadLink = "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.133-2/virtio-win.iso"
# Download the VirtIO drivers ISO from Fedora
# 如果单独下载完了,这一步可以省略
(New-Object System.Net.WebClient).DownloadFile($virtIODownloadLink, $VirtIOISOPath)
New-WindowsOnlineImage -WimFilePath $wimFilePath -ImageName $image.ImageName `
-WindowsImagePath $windowsImagePath -Type 'HYPER-V' -VirtioISOPath $virtIOISOPath `
-SizeBytes 30GB -CpuCores 4 -Memory 4GB -SwitchName 'external'
执行上一条命令后,制作程序开始,可能比较漫长,等待自动启动的虚拟机自动关闭即可
Powershell基本输出如下:
Windows online image generation started at: 2017/9/20 14:25:21
Image generation started at: 2017/9/20 14:25:31
Copying: C:\Users\Administrator\windows-openstack-imaging-tools\UnattendResources G:\
Downloading Cloudbase-Init...
Applying Windows image "E:\Sources\install.wim" in "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
正在应用映像
#这个阶段比较漫长
[==========================100.0%==========================]
操作成功完成。
已成功创建启动文件。
按规定设备无效。
运行 "bcdedit /?" 获得命令行帮助。
参数错误。
警告: BCDEdit failed: bootmgr device locate
按规定设备无效。
运行 "bcdedit /?" 获得命令行帮助。
参数错误。
警告: BCDEdit failed: default device locate
按规定设备无效。
运行 "bcdedit /?" 获得命令行帮助。
参数错误。
警告: BCDEdit failed: default osdevice locate
Adding drivers from H:
Adding drivers from "H:\balloon\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\balloon\2k8r2\AMD64\balloon.inf: 驱动程序包已成功安装
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\netkvm\2k8r2\AMD64\netkvm.inf: 驱动程序包已成功安装。
操作成功完成。
Adding drivers from "H:\pvpanic\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\pvpanic\2k8r2\AMD64\pvpanic.inf: 驱动程序包已成功安装。
操作成功完成。
Adding drivers from "H:\qxl\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\qxl\2k8r2\AMD64\qxl.inf: 驱动程序包已成功安装。
操作成功完成。
Adding drivers from "H:\vioinput\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\vioinput\2k8r2\AMD64\vioinput.inf: 驱动程序包已成功安装。
操作成功完成。
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\viorng\2k8r2\AMD64\viorng.inf: 驱动程序包已成功安装。
操作成功完成。
Adding drivers from "H:\vioscsi\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\vioscsi\2k8r2\AMD64\vioscsi.inf: 驱动程序包已成功安装。
操作成功完成。
Adding drivers from "H:\vioserial\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\vioserial\2k8r2\AMD64\vioser.inf: 驱动程序包已成功安装。
操作成功完成。
Adding drivers from "H:\viostor\2k8r2\AMD64" to image "G:\"
部署映像服务和管理工具
版本: 6.3.9600.16384
映像版本: 6.1.7600.16385
正在搜索要安装的驱动程序包...
找到 1 个要安装的驱动程序包。
正在安装第 1 个,共有 1 个 - H:\viostor\2k8r2\AMD64\viostor.inf: 驱动程序包已成功安装。
操作成功完成。
Image generation finished at: 2017/9/20 15:12:01 |