在「使用 Cobbler 批量自动化部署 CentOS / Ubuntu」一文中,我们讲解了如何自动化部署 CentOS / Ubuntu。本文就来讲一讲如何通过 CentOS 7.6 Minimal + Cobbler 自动化安装 Windows 10 和 Windows Server 2019。
注意:一般安装 Windows 是用 MDT 或者 WDS 居多,毕竟是巨硬自己家的,而且 WDT 还支持分布式镜像传输(主要是巨硬家的 OS,动辄超过 4G,万兆网卡也会卡啊)。本文不涉及到 WDT 或者 WDS 相关操作,感兴趣的可自行搜索。
准备
Windows ADK (http://t.cn/EXe4cME)
a.) 下载 Download the Windows ADK for Windows 10, version 1809(http://t.cn/EXe4nlb)
b.) 下载Download the Windows PE add-on for the ADK(http://t.cn/EXeG99D)
下载 Windows 10 和 Windows Server 2019 (http://t.cn/hViIm)
a.) Windows 10 (business edition), version 1809 (Updated Feb 2019) (x64) - DVD (Chinese-Simplified)
b.) Windows Server 2019 (x64) - DVD (Chinese-Simplified)
注意,ADK 的两个都要下载,这俩都是引导包,真正的安装程序会由这俩软件进行下载。其中 WinPE 需要用到 5G 左右的磁盘空间,简直不能忍受。。。
MSDN I Tell U 堪称良心站,是 Windows 装机神站啊,不过,没有直达页面挺不爽。为了防止下错,特意截图。
安装 ADK 和 WinPE
我已经装过,且忘记截图了,这是事后补图,只需要勾选必须的就行
安装完后,以管理员身份打开部署和映像工具环境。
定制 Win 10 PE
copype amd64 C:\winpeDism /mount-image /imagefile:C:\winpe\media\sources\boot.wim /index:1 /mountdir:C:\winpe\mountecho net use z: \\192.168.0.253\share >> C:\winpe\mount\Windows\System32\startnet.cmdecho z:\win\setup.exe /unattend:z:\win\win10_x64_bios_auto.xml >> C:\winpe\mount\Windows\System32\startnet.cmdDism /unmount-image /mountdir:C:\winpe\mount /commitMakeWinPEMedia /ISO C:\winpe C:\winpe\winpe_win10_amd64.iso
本地生成 Winpe 文件目录
Dism 挂载 Winpe 的启动文件到 Winpe的 Mount 目录。
将启动命令硬编码写死到 Winpe 的 startnet.cmd 文件里。
无人值守安装。
卸载 Winpe 的挂载(一定要执行,否则直接强制删除文件夹会出一些稀奇古怪的问题)。
制作 Win10 镜像,名为 winpe_win10_amd64.iso。
第三步的硬编码是无奈之举,因为要想挂载共享文件夹,必须要知道 SMB 主机,但是这个参数又很难传递进来。
如果是 U 盘启动,可以写死 U 盘路径,大不了插上U盘后,手动改卷标 (当然因为 U 盘挂载顺序不一致,可以通过 for 循环 A-Z 盘,挨个盘访问某个文件名,如果存在,即认为此盘是自己 U 盘,设置环境变量)。而网上说的,startnet.cmd 调用另外一个bat,多是基于这个原理。
而如果 PXE 要达到跟上述要求,动态设置 SMB 主机,要么写死域名,然后劫持或者配置域名,加上 BAT 文件,在 Winpe 启动时,通过 startnet.cmd 下载并执行。要么找办法,看看能不能在启动时,传入参数(目前我还没找到),当然还可以用 MDT 方案,看着比 PXE+无人应答文件简单很多。
配置 Cobbler Server
导入Cobbler
使用 WinScp 等工具,将 winpe_win10_amd64.iso 上传到 Cobbler 服务器上。
[root@localhost ~]# cobbler distro add --name=windows_10_x64 --kernel=/var/lib/tftpboot/memdisk --initrd=/root/winpe_win10_amd64.iso --kopts="raw iso"[root@localhost ~]# touch /var/lib/cobbler/kickstarts/winpe.xml[root@localhost ~]# cobbler profile add --name=windows_10_x64 --distro=windows_10_x64 --kickstart=/var/lib/cobbler/kickstarts/winpe.xml
创建自动应答文件
直接从 Windows Answer File Generator (http://t.cn/EXgGYFf) 通过简单配置后,下载即可(只支持简单操作,比如,装系统,格式化磁盘,设置密码等)。当然也可以使用 【Windows系统映像管理器】,不过挺难用的,具体用法可以参考 How to create an unattended installation of Windows 10。也可以通过 MDT 简化操作。
但是如果使用直接生成的,有点问题,即使页面设置了安装语言,但是仍旧需要手动选择,经过多方研究发现主要卡在 UILanguage 和 Inputlocale 上,全写 zh-CN 无效。
<?xml version="1.0" encoding="utf-8"?><component 此处忽略> <SetupUILanguage> <UILanguage>en-USUILanguage> SetupUILanguage> <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411f-A5AC-CA038EC515D7}InputLocale> <SystemLocale>zh-CNSystemLocale> <UILanguage>zh-CNUILanguage> <UILanguageFallback>zh-CNUILanguageFallback> <UserLocale>zh-CNUserLocale>component>
另外就是安装密钥,统一替换为 VK7JG-NPHTM-C97JM-9MPGT-3V66T
下面是我的应答文件,仅做参考。
<?xml version="1.0" encoding="utf-8"?><unattend xmlns="urn:schemas-microsoft-com:unattend"> <settings pass="windowsPE"> <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SetupUILanguage> <UILanguage>en-USUILanguage> SetupUILanguage> <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411f-A5AC-CA038EC515D7}InputLocale> <SystemLocale>zh-CNSystemLocale> <UILanguage>zh-CNUILanguage> <UILanguageFallback>zh-CNUILanguageFallback> <UserLocale>zh-CNUserLocale> component> <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SetupUILanguage> <UILanguage>en-USUILanguage> SetupUILanguage> <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411f-A5AC-CA038EC515D7}InputLocale> <SystemLocale>zh-CNSystemLocale> <UILanguage>zh-CNUILanguage> <UILanguageFallback>zh-CNUILanguageFallback> <UserLocale>zh-CNUserLocale> component> <component name="Microsoft-Windows-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <DiskConfiguration> <Disk wcm:action="add"> <CreatePartitions> <CreatePartition wcm:action="add"> <Order>1Order> <Type>PrimaryType> <Size>100Size> CreatePartition> <CreatePartition wcm:action="add"> <Extend>trueExtend> <Order>2Order> <Type>PrimaryType> CreatePartition> CreatePartitions> <ModifyPartitions> <ModifyPartition wcm:action="add"> <Active>trueActive> <Format>NTFSFormat> <Label>System ReservedLabel> <Order>1Order> <PartitionID>1PartitionID> <TypeID>0x27TypeID> ModifyPartition> <ModifyPartition wcm:action="add"> <Active>trueActive> <Format>NTFSFormat> <Label>OSLabel> <Letter>CLetter> <Order>2Order> <PartitionID>2PartitionID> ModifyPartition> ModifyPartitions> <DiskID>0DiskID> <WillWipeDisk>trueWillWipeDisk> Disk> DiskConfiguration> <ImageInstall> <OSImage> <InstallTo> <DiskID>0DiskID> <PartitionID>2PartitionID> InstallTo> <InstallToAvailablePartition>falseInstallToAvailablePartition> OSImage> ImageInstall> <UserData> <AcceptEula>trueAcceptEula> <FullName>AnJiaFullName> <Organization>AnJiaOrganization> <ProductKey> <Key>VK7JG-NPHTM-C97JM-9MPGT-3V66TKey> ProductKey> UserData> component> <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <DiskConfiguration> <Disk wcm:action="add"> <CreatePartitions> <CreatePartition wcm:action="add"> <Order>1Order> <Type>PrimaryType> <Size>100Size> CreatePartition> <CreatePartition wcm:action="add"> <Extend>trueExtend> <Order>2Order> <Type>PrimaryType> CreatePartition> CreatePartitions> <ModifyPartitions> <ModifyPartition wcm:action="add"> <Active>trueActive> <Format>NTFSFormat> <Label>System ReservedLabel> <Order>1Order> <PartitionID>1PartitionID> <TypeID>0x27TypeID> ModifyPartition> <ModifyPartition wcm:action="add"> <Active>trueActive> <Format>NTFSFormat> <Label>OSLabel> <Letter>CLetter> <Order>2Order> <PartitionID>2PartitionID> ModifyPartition> ModifyPartitions> <DiskID>0DiskID> <WillWipeDisk>trueWillWipeDisk> Disk> DiskConfiguration> <ImageInstall> <OSImage> <InstallTo> <DiskID>0DiskID> <PartitionID>2PartitionID> InstallTo> <InstallToAvailablePartition>falseInstallToAvailablePartition> OSImage> ImageInstall> <UserData> <AcceptEula>trueAcceptEula> <FullName>AnJiaFullName> <Organization>AnJiaOrganization> <ProductKey> <Key>VK7JG-NPHTM-C97JM-9MPGT-3V66TKey> ProductKey> UserData> component> settings> <settings pass="offlineServicing"> <component name="Microsoft-Windows-LUA-Settings" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <EnableLUA>falseEnableLUA> component> settings> <settings pass="offlineServicing"> <component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <EnableLUA>falseEnableLUA> component> settings> <settings pass="generalize"> <component name="Microsoft-Windows-Security-SPP" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SkipRearm>1SkipRearm> component> settings> <settings pass="generalize"> <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SkipRearm>1SkipRearm> component> settings> <settings pass="specialize"> <component name="Microsoft-Windows-International-Core" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411f-A5AC-CA038EC515D7}InputLocale> <SystemLocale>zh-CNSystemLocale> <UILanguage>zh-CNUILanguage> <UILanguageFallback>zh-CNUILanguageFallback> <UserLocale>zh-CNUserLocale> component> <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <InputLocale>0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411f-A5AC-CA038EC515D7}InputLocale> <SystemLocale>zh-CNSystemLocale> <UILanguage>zh-CNUILanguage> <UILanguageFallback>zh-CNUILanguageFallback> <UserLocale>zh-CNUserLocale> component> <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SkipAutoActivation>trueSkipAutoActivation> component> <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SkipAutoActivation>trueSkipAutoActivation> component> <component name="Microsoft-Windows-SQMApi" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <CEIPEnabled>0CEIPEnabled> component> <component name="Microsoft-Windows-SQMApi" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <CEIPEnabled>0CEIPEnabled> component> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ComputerName>AnJia-PCComputerName> <ProductKey>VK7JG-NPHTM-C97JM-9MPGT-3V66TProductKey> component> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ComputerName>AnJia-PCComputerName> <ProductKey>VK7JG-NPHTM-C97JM-9MPGT-3V66TProductKey> component> settings> <settings pass="oobeSystem"> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <AutoLogon> <Password> <Value>Value> <PlainText>truePlainText> Password> <Enabled>trueEnabled> <Username>AnJiaUsername> AutoLogon> <OOBE> <HideEULAPage>trueHideEULAPage> <HideOEMRegistrationScreen>trueHideOEMRegistrationScreen> <HideOnlineAccountScreens>trueHideOnlineAccountScreens> <HideWirelessSetupInOOBE>trueHideWirelessSetupInOOBE> <NetworkLocation>WorkNetworkLocation> <SkipUserOOBE>trueSkipUserOOBE> <SkipMachineOOBE>trueSkipMachineOOBE> <ProtectYourPC>1ProtectYourPC> OOBE> <UserAccounts> <LocalAccounts> <LocalAccount wcm:action="add"> <Password> <Value>Value> <PlainText>truePlainText> Password> <Description>AnJiaDescription> <DisplayName>AnJiaDisplayName> <Group>AdministratorsGroup> <Name>AnJiaName> LocalAccount> LocalAccounts> UserAccounts> <RegisteredOrganization>AnJiaRegisteredOrganization> <RegisteredOwner>AnJiaRegisteredOwner> <DisableAutoDaylightTimeSet>falseDisableAutoDaylightTimeSet> <FirstLogonCommands> <SynchronousCommand wcm:action="add"> <Description>Control Panel ViewDescription> <Order>1Order> <CommandLine>reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v StartupPage /t REG_DWORD /d 1 /fCommandLine> <RequiresUserInput>trueRequiresUserInput> SynchronousCommand> <SynchronousCommand wcm:action="add"> <Order>2Order> <Description>Control Panel Icon SizeDescription> <RequiresUserInput>falseRequiresUserInput> <CommandLine>reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v AllItemsIconView /t REG_DWORD /d 0 /fCommandLine> SynchronousCommand> <SynchronousCommand wcm:action="add"> <Order>3Order> <RequiresUserInput>falseRequiresUserInput> <CommandLine>cmd /C wmic useraccount where name="AnJia" set PasswordExpires=falseCommandLine> <Description>Password Never ExpiresDescription> SynchronousCommand> FirstLogonCommands> <TimeZone>China Standard TimeTimeZone> component> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <AutoLogon> <Password> <Value>Value> <PlainText>truePlainText> Password> <Enabled>trueEnabled> <Username>AnJiaUsername> AutoLogon> <OOBE> <HideEULAPage>trueHideEULAPage> <HideOEMRegistrationScreen>trueHideOEMRegistrationScreen> <HideOnlineAccountScreens>trueHideOnlineAccountScreens> <HideWirelessSetupInOOBE>trueHideWirelessSetupInOOBE> <NetworkLocation>WorkNetworkLocation> <SkipUserOOBE>trueSkipUserOOBE> <SkipMachineOOBE>trueSkipMachineOOBE> <ProtectYourPC>1ProtectYourPC> OOBE> <UserAccounts> <LocalAccounts> <LocalAccount wcm:action="add"> <Password> <Value>Value> <PlainText>truePlainText> Password> <Description>AnJiaDescription> <DisplayName>AnJiaDisplayName> <Group>AdministratorsGroup> <Name>AnJiaName> LocalAccount> LocalAccounts> UserAccounts> <RegisteredOrganization>AnJiaRegisteredOrganization> <RegisteredOwner>AnJiaRegisteredOwner> <DisableAutoDaylightTimeSet>falseDisableAutoDaylightTimeSet> <FirstLogonCommands> <SynchronousCommand wcm:action="add"> <Description>Control Panel ViewDescription> <Order>1Order> <CommandLine>reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v StartupPage /t REG_DWORD /d 1 /fCommandLine> <RequiresUserInput>trueRequiresUserInput> SynchronousCommand> <SynchronousCommand wcm:action="add"> <Order>2Order> <Description>Control Panel Icon SizeDescription> <RequiresUserInput>falseRequiresUserInput> <CommandLine>reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel" /v AllItemsIconView /t REG_DWORD /d 0 /fCommandLine> SynchronousCommand> <SynchronousCommand wcm:action="add"> <Order>3Order> <RequiresUserInput>falseRequiresUserInput> <CommandLine>cmd /C wmic useraccount where name="AnJia" set PasswordExpires=falseCommandLine> <Description>Password Never ExpiresDescription> SynchronousCommand> FirstLogonCommands> <TimeZone>China Standard TimeTimeZone> component> settings>unattend>
配置 Samba
在 Cobbler 上执行
安装 Samba
[root@localhost ~]# yum install samba -y
修改 SMB CONFIG
[root@localhost ~]# vi /etc/samba/smb.conf # /etc/samba/smb.conf[global]log file = /var/log/samba/log.%mmax log size = 5000security = userguest account = nobodymap to guest = Bad Userload printers = yescups options = raw [share]comment = share directory目录path = /smb/directory mask = 0755create mask = 0755guest ok=yeswritable=yes
启动 SMB 服务
[root@localhost ~]# service smb start[root@localhost ~]# systemctl enable smb
挂载 Win 10 系统
通过 Winscp 等软件将 Windows 10 安装文件上传到 Cobbler 服务器上,并将创建的应答文件上传到cobbler /smb/win/win10_x64_bios_auto.xml
[root@localhost ~]# mkdir -p /smb/win[root@localhost ~]# mount -o loop,ro /tmp/cn_windows_10_business_edition_version_1809_updated_sept_2018_x64_dvd_84ac403f.iso /mnt/[root@localhost ~]# cp -r /mnt/* /smb/win[root@localhost ~]# umount /mnt/
自动化安装 Windows10
从 Vmware 创建一台内存 4G,Cpu 2核,磁盘 60G 的空盘,Win 10虚拟机,然后开机。记得选 BIOS,别选UEFI。
至于如何激活,参考 vlmcsd 搭建 KMS 服务器 (http://t.cn/EXgySKR),成功激活 Windows Server 2019 数据中心版本。
Windows Server 2019
因为 2019 用的也是 1809 版本的,所以制作步骤一样的,在此不再赘述。
来源:家的博客
原文:http://t.cn/EXgUPVr题图:来自谷歌图片搜索
版权:本文版权归原作者所有投稿:欢迎投稿,投稿邮箱: editor@hi-linux.com
今日思想
你知道什么是天才的诀窍吗?那就是永远只做一件事。
—— 王小波「白银时代」
推荐阅读
lsof 命令使用指南
浅谈 MySQL 优化实施方案
抓包神器 TCPDUMP 使用教程
5 分钟小技巧系列 | 使用 AWK 过滤多余的列
5 分钟小技巧系列 | 巧用 Curl 命令分析请求耗时情况