zl程序教程

您现在的位置是:首页 >  系统

当前栏目

docker cobbler批量部署Linux/windows系统(三)——筑梦之路

2023-09-14 09:09:36 时间

docker容器化cobbler server: https://blog.csdn.net/qq_34777982/article/details/116782745

cobbler 批量部署linux系统(centos7 ubuntu16.04):https://blog.csdn.net/qq_34777982/article/details/116783486

接下来,使用cobbler批量部署windows 系统。

参考文章:

https://www.cnblogs.com/pluse/p/8508538.html

https://blog.51cto.com/u_13689359/2473406

https://www.cnblogs.com/xll970105/p/12409234.html

Windows系统的自动安装需要用到Win PE工具。流程如下:

  • 定制Win PE工具
  • Win PE ISO导入至Cobbler Server端
  • 通过Samba共享Windows ISO
  • 客户机器PXE启动安装

1.定制winPE工具

工具下载:

https://www.microsoft.com/zh-cn/download/details.aspx?id=5753

https://go.microsoft.com/fwlink/p/?LinkId=526740

工具安装完成后打开cmd执行如下的命令:

copype amd64 C:\winpe
 
imagex /mountrw c:\winpe\winpe.wim 1 c:\winpe\mount
 
echo ping -n 7 -l 69 192.168.80.10 >> C:\winpe\mount\Windows\System32\startnet.cmd  
echo net use z: \\192.168.80.10\share >> C:\winpe\mount\Windows\System32\startnet.cmd
echo Z: >> C:\winpe\mount\Windows\System32\startnet.cmd
 
#win是包含windows 7 ISO解压文件的父目录
echo cd win >> C:\winpe\mount\Windows\System32\startnet.cmd
echo setup.exe /unattend:Autounattend.xml >> C:\winpe\mount\Windows\System32\startnet.cmd
 
imagex /unmount c:\winpe\mount /commit
 
copy c:\winpe\winpe.wim c:\winpe\ISO\sources\boot.wim
 
# "-bC"中间没有空格
oscdimg -n -bC:\winpe\etfsboot.com c:\winpe\ISO c:\winpe\winpe_cobbler_amd64.iso

解释一下上面的几行命令:

1:使用copype命令创建C:\winpe目录,并在该目录下生成Win PE预安装所需的文件。

3:使用imagex命令挂载c:\winpe\winpe.wim文件到c:\winpe\mount目录下,以便后续进行修改,因为Windows系统的很多核心文件都被打包压缩在这个文件里面,所以我们需要挂载才能读写修改。除了imagex这个工具可以完成修改之外,另一个工具DIMS也能做到,如果你熟悉该工具,则可以使用DIMS来做。

5-11:修改挂载后的wim文件,向C:\winpe\mount\Windows\System32\startnet.cmd文件中写入一些脚本命令。其中第5行用于测试脚本有无执行,可以删去。剩下的几行是对samba共享文件的加载并执行,具体会在后续第三步samba文件共享那里详细解释。需要注意的是,这里用到的IP地址是我Cobbler Server服务器的地址,具体请根据你自己的服务器地址进行更改。至于为什么是写入到startnet.cmd文件中,是因为Win PE第一次运行时固定使用 Wpeinit 和 Startnet.cmd 运行启动脚本。但是对于Wpeinit我多次测试却没有成功过,因此选择将命令脚本写入到startnet.cmd文件中(startnet.cmd是Win PE ISO镜像自带的脚本文件)。

11行:echo setup.exe /unattend:Autounattend.xml,Autounattend.xml为后续制作的自动化应答文件,若无此文件使用echo setup.exe >> C:\winpe\mount\Windows\System32\startnet.cmd也可执行安装操作,只是由自动应答变为手动应答。  

一个问题:写入到脚本中的命令用到了Cobber Server端的IP地址(安装cobbler服务的ip地址),这个IP地址被硬编码到了Win PE ISO镜像中,一个可行的办法是在这里不直接写入具体命令,而是调用另外一个脚本,这个被掉的脚本可以放在其他地方,以方便后续修改。

13:完成修改后,提交保存修改并去除挂载。

15:拷贝修改后的winpe.wim到指定目录并重命名。

18:生成Win PE ISO镜像工具,路径及名称为C:\winpe\winpe_cobbler_amd64.iso。

2.上传pe ISO到cobbler server端

将 winpe_cobbler_amd64.iso 镜像拷贝至 Cobbler Server 服务器/root/目录下,但无需挂载。

docker cp winpe_cobbler_amd64.iso dockercobbler_cobbler_1:/root

cobbler distro add --name=windows7 --kernel=/var/lib/tftpboot/memdisk --initrd=/root/winpe_cobbler_amd64.iso --kopts="raw iso"

  • 配置ISO镜像自动值守安装文件

这里需要说明的是:事实上,该自动值守安装文件并没有作用,它不像CentOS的ks以及Ubuntu的Preseed文件那样,内含有操作系统的那些设置,它的作用在于每个系统distro必须有一个profile,因此尽管它并不是实际用来设定系统设置的,但也要指定。如下:

1

2

touch /var/lib/cobbler/kickstarts/win7pe.xml

cobbler profile add --name=windows7 --distro=windows7 --kickstart=/var/lib/cobbler/kickstarts/win7pe.xml

  这里的win7pe.xml文件可以为空白,但必须要存在。否则,在通过PXE方式启动客户机器时,客户机器看不到可以通过网络安装的Win PE系统。而实际设定Windows系统安装的配置文件则会在第四步客户机器PXE启动安装那里解释。

3.samba 服务共享iso

这里使用的Windows 7 ISO镜像并不是ghost之类的修改版,而是微软官方发布的原生纯净ISO,必须是纯净版iso!!!!

# /etc/samba/smb.conf
[global]
log file = /var/log/samba/log.%m
max log size = 5000
security = user
guest account = nobody
map to guest = Bad User
load printers = yes
cups options = raw
 
[share]
comment = share directory目录
path = /smb/
directory mask = 0755
create mask = 0755
guest ok=yes
writable=yes

mkdir -p /smb/win
mkdir /mnt/win7
mount -o loop,ro /root/cn_windows_7_ultimate_with_sp1_x64_dvd_u_677408.iso /mnt/win7
cp -r /mnt/win7/* /smb/win


应答文件Autounattend.xml

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<SetupUILanguage>
<UILanguage>zh-CN</UILanguage>
</SetupUILanguage>
<InputLocale>zh-CN</InputLocale>
<SystemLocale>zh-CN</SystemLocale>
<UILanguage>zh-CN</UILanguage>
<UserLocale>zh-CN</UserLocale>
</component>
<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserData>
<ProductKey>
<Key>87VT2-FY2XW-F7K39-W3T8R-XMFGF</Key>
</ProductKey>
<AcceptEula>true</AcceptEula>
</UserData>
<ImageInstall>
<OSImage>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/image/index</Key>
<Value>4</Value>
</MetaData>
</InstallFrom>
<InstallTo>
<DiskID>0</DiskID>
<PartitionID>1</PartitionID>
</InstallTo>
</OSImage>
</ImageInstall>
<DiskConfiguration>
<Disk wcm:action="add">
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Active>true</Active>
<Extend>false</Extend>
<Format>NTFS</Format>
<Label>OS</Label>
<Letter>C</Letter>
<Order>1</Order>
<PartitionID>1</PartitionID>
</ModifyPartition>
</ModifyPartitions>
<CreatePartitions>
<CreatePartition wcm:action="add">
<Order>1</Order>
<Size>30000</Size>
<Type>Primary</Type>
</CreatePartition>
</CreatePartitions>
<DiskID>0</DiskID>
<WillWipeDisk>true</WillWipeDisk>
</Disk>
</DiskConfiguration>
</component>
</settings>
<settings pass="oobeSystem">
<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>UABhAHMAcwB3AG8AcgBkAA==</Value>
<PlainText>false</PlainText>
</Password>
<DisplayName>GoSun.Inc</DisplayName>
<Group>Administrators</Group>
<Name>gosun</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<OOBE>
<ProtectYourPC>3</ProtectYourPC>
<NetworkLocation>Work</NetworkLocation>
</OOBE>
<TimeZone>China Standard Time</TimeZone>
</component>
</settings>
<settings pass="specialize">
<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<ComputerName>*</ComputerName>
</component>
</settings>
<cpi:offlineImage xmlns:cpi="urn:schemas-microsoft-com:cpi" cpi:source="wim:c:/users/observer/desktop/cn_windows_7_ultimate_with_sp1_x64_dvd_u_677408/sources/install.wim#Windows 7 ULTIMATE"/>
</unattend>