按照如下步骤进行安装配置,实现PXE+BIOS安装Centos和Ubuntu,UEFI+iPXE安装Windows2019
若想实现UEFI+iPXE安装Centos和Ubuntu,可以参考附录《更全的ipxe/default.ipxe》配置default.ipxe即可
rocky91安装配置cobbler3.3.3
准备工作
rocky91的IP地址是192.168.1.177
yum -y install vim wget epel-release
systemctl disable --now firewalld
systemctl disable --now dnf-makecache.timer
setenforce 0
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
安装软件包
yum -y install rsync rsync-daemon httpd dnsmasq tftp tftp-server cobbler pykickstart ipxe-bootimgs-x86
yum -y install samba ipxe-roms-qemu.noarch # Windows需要使用
启动服务
systemctl enable --now httpd cobblerd rsyncd tftp
修改cobbler配置
sed -i ‘s/manage_dhcp: false/manage_dhcp: true/’ /etc/cobbler/settings.yaml
sed -i ‘s/manage_dhcp_v4: false/manage_dhcp_v4: true/’ /etc/cobbler/settings.yaml
sed -i ‘s/next_server_v4: 127.0.0.1/next_server_v4: 192.168.1.177/’ /etc/cobbler/settings.yaml
sed -i ‘s/redhat_management_permissive: false/redhat_management_permissive: true/’ /etc/cobbler/settings.yaml
sed -i ‘s/server: 127.0.0.1/server: 192.168.1.177/’ /etc/cobbler/settings.yaml
修复一些配置
cobbler check
yum -y install yum-utils
yum -y install syslinux*
cp /usr/share/syslinux/pxelinux.0 /var/lib/cobbler/loaders/
cp /usr/share/syslinux/menu.c32 /var/lib/cobbler/loaders/
cp /usr/share/syslinux/ldlinux.c32 /var/lib/cobbler/loaders/
cp /usr/share/syslinux/libutil.c32 /var/lib/cobbler/loaders/
systemctl restart cobblerd
cobbler sync
修改一些代码
根据 https://github.com/cobbler/cobbler/issues/3473
[root@localhost modules]# grep -nr wlsd sync_post_wingen_ankele.py -C2
81- b = h.node_add_child(objs, "{65c31250-afa2-11df-8045-000c29f37d88}")
82- d = h.node_add_child(b, "Description")
83: # wlsd mod 2
84- #h.node_set_value(d, {"key": "Type", "t": REG_DWORD, "value": b"\x03\x00\x20\x13"})
85- h.node_set_value(d, {"key": "Type", "t": REG_DWORD, "value": b"\x03\x00\x20\x10"})
86- e = h.node_add_child(b, "Elements")
87: # wlsd add 2
88- e1 = h.node_add_child(e, "12000002")
89- h.node_set_value(e1, {"key": "Element", "t": REG_SZ, "value": "\\windows\\system32\\winload.exe\0".encode(encoding="utf-16le"), }, )
--
178-
179- if is_wimboot:
180: # wlsd del 2
181- #distro_path = os.path.join(settings.webdir, "distro_mirror", distro.name)
182- #kernel_path = os.path.join(distro_path, "boot")
--
303-
304- if is_wimboot:
305: # wlsd mod 2
306- #wim_file_name = '\\Boot\\' + wim_file_name
307- wim_file_name = '\\Boot\\' + "winpe.wim"
为Windows修改ipxe.template
sed -i ‘s/kernel $kernel_path $kernel_options initrd=initrd.magic/kernel $kernel_path $kernel_options/’ /etc/cobbler/boot_loader_conf/ipxe.template
为Windows配置ipxe
dnsmasq里边应该是指定的ipxe-x86_64.efi这个文件,所以
cp /usr/share/ipxe/ipxe-x86_64.efi /var/lib/tftpboot/ipxe-x86_64.efi
安装wim工具
不然cobbler import时会报错 no /usr/bin/wiminfo found, please install wimlib-utils 以及 No signature matched in /var/www/cobbler/distro_mirror/win2019
yum -y install wimlib-utils
开启Windows
sed -i ‘s/windows_enabled: false/windows_enabled: true/’ /etc/cobbler/settings.d/windows.settings
开启dnsmasq
而不使用dhcp-server,原因是Windows得使用dnsmasq方便指定ipxe
sed -i ‘s/module = managers.isc/module = managers.dnsmasq/’ /etc/cobbler/modules.conf
cat /etc/cobbler/dnsmasq.template
# Cobbler generated configuration file for dnsmasq
# $date
## resolve.conf .. ?
#no-poll
#enable-dbus
read-ethers
addn-hosts = /var/lib/cobbler/cobbler_hostsdhcp-range=192.168.66.100,192.168.66.200
dhcp-option=66,$next_server_v4
dhcp-lease-max=1000
dhcp-authoritative
#dhcp-boot=pxelinux.0
#dhcp-boot=net:normalarch,pxelinux.0
dhcp-match=set:efi-x86_64,option:client-arch,7
dhcp-boot=tag:efi-x86_64,ipxe-x86_64.efi
dhcp-match=set:ipxe,175
dhcp-boot=tag:ipxe,/ipxe/default.ipxe
dhcp-match=set:bios,option:client-arch,0
dhcp-boot=tag:bios,pxelinux.0$insert_cobbler_system_definitions
systemctl enable --now dnsmasq
cobbler sync
cobbler3.3.3安装Windows2019
配置samba
cat >> /etc/samba/smb.conf << EOF
[DISTRO]
comment = Windows distributions
path = /var/www/cobbler/distro_mirror
guest ok = yes
browseable = yes
public = yes
writeable = no
printable = no
locking = no
EOF
systemctl enable --now smb
导入ISO镜像
scp cn_windows_server_2019_x64_dvd_4de40f33.iso 到/root下
mkdir -p /iso/win2019
mount -o ro,loop cn_windows_server_2019_x64_dvd_4de40f33.iso /iso/win2019
cobbler import --path=/iso/win2019 --name=win2019
指定应答文件
cobbler profile edit --name=win2019-x86_64 --autoinstall-meta=“kernel=http://@@http_server@@/cobbler/images/@@distro_name@@/wimboot bootmgr=bootmgr.exe bcd=bcd winpe=winpe.wim answerfile=autounattended.xml”
ln -s /var/www/cobbler/distro_mirror/win2019 /var/www/cobbler/distro_mirror/win2019-x86_64
cobbler sync
替换cobbler sync生成的winpe.wim,然后给wimpe.wim注入命令
cp /root/winpe.wim /var/www/cobbler/images/win2019-x86_64/
/usr/bin/wimupdate /var/www/cobbler/images/win2019-x86_64/winpe.wim --command=“add /root/winpe_inject /Windows/System32/startnet.cmd”
[root@localhost win2019-x86_64]# cat /root/winpe_inject
wpeinitping 127.0.0.1 -n 10 >nul
net use z: \\192.168.1.177\DISTRO\win2019-x86_64
set exit_code=%ERRORLEVEL%
IF %exit_code% EQU 0 GOTO INSTALL
echo "Can't mount network drive"
pause
goto EXIT:INSTALLz:\sources\setup.exe /unattend:Z:\autounattended.xml
:EXIT
exit# 解释
# net use z: \\192.168.1.177\DISTRO\win2019-x86_64 表示使用smb协议挂载192.168.1.177的共享目录,可修改此IP
覆盖
cd /var/www/cobbler/images/win2019-x86_64/
cp winpe.wim /var/www/cobbler/distro_mirror/win2019-x86_64/boot/winpe.wim
cp winpe.wim /var/lib/tftpboot/images/win2019-x86_64/
下载wimboot
根据https://github.com/cobbler/cobbler/issues/3473
https://github.com/ipxe/wimboot/releases/latest/download/wimboot,
并copy到几个地方
/var/lib/tftpboot
/var/lib/tftpboot/images/win2019-x86_64
/var/www/cobbler/images/win2019-x86_64/
/var/www/cobbler/images/win2019-x86_64/下边共有这几个文件
autounattended.xml bcd boot.sdi bootmgr.exe pxeboot.n12 wimboot winpe.wim
准备好 autounattended.xml,见附件
/var/lib/tftpboot/images/win2019-x86_64/autounattended.xml
/var/www/cobbler/distro_mirror/win2019/autounattended.xml
/var/www/cobbler/images/win2019-x86_64/autounattended.xml
默认从windows启动
vim /var/lib/tftpboot/ipxe/default.ipxe
...
set menu-timeout 2000
isset ${menu-default} || set menu-default win2019-x86_64
...
systemctl restart cobblerd
安装Ubuntu20.04.6-live-server
mkdir /iso/ubuntu20046
mount -o loop,ro ubuntu-20.04.6-live-server-amd64.iso /iso/ubuntu20046
cobbler import --path=/iso/ubuntu20046 --name=ubuntu20046
之后/var/lib/tftpboot/pxelinux.cfg/default中便有了ubuntu20046
修改default,添加参数
LABEL ubuntu20046-casper-x86_64MENU LABEL ubuntu20046-casper-x86_64kernel /images/ubuntu20046-casper-x86_64/vmlinuzappend initrd=/images/ubuntu20046-casper-x86_64/initrd hostname=ubuntu20046-casper-x8664 domain=local.lan suite=focalipappend 2改为LABEL ubuntu20046-casper-x86_64MENU LABEL ubuntu20046-casper-x86_64kernel /images/ubuntu20046-casper-x86_64/vmlinuzinitrd /images/ubuntu20046-casper-x86_64/initrdappend biosdevname=0 net.ifnames=0 netcfg/choose_interface=auto ip=dhcp autoinstall ds='nocloud-net;s=http://192.168.1.177:3003/' cloud-config-url=http://192.168.1.177:3003/user-data url=http://192.168.1.177/cobbler/isos/ubuntu-20.04.6-live-server-amd64.isoipappend 2
# 其中biosdevname=0 net.ifnames=0 在live阶段起作用。欲修改安装后系统的网卡名称,cloud-init的user-data中使用shell命令来配置内核参数
# netcfg/choose_interface=auto ip=dhcp 表示任意选中一张网卡,通过DHCP获取IP,用以与我们的server通信
# autoinstall 指定自动安装
# ds='nocloud-net;s=http://192.168.1.177:3003/' 指定安装方式是nocloud-net,并给出包含user-data和meta-data的http静态路径
# cloud-config-url=http://192.168.1.177:3003/user-data 给出user-data具体路径,方便获取cloud-init指令
# url=http://192.168.1.177/cobbler/isos/ubuntu-20.04.6-live-server-amd64.iso 指定网络安装时局域网内的ISO文件路径
添加user-data
mkdir /root/http_server
touch /root/http_server/user-data
touch /root/http_server/meta-data
cat /root/http_server/meta-data#cloud-config
autoinstall:version: 1apt:geoip: truepreserve_sources_list: falseprimary:- arches: [amd64, i386]uri: http://us.archive.ubuntu.com/ubuntu- arches: [default]uri: http://ports.ubuntu.com/ubuntu-portsidentity:hostname: ubuntu-serverpassword: $6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0username: ubuntukeyboard: {layout: us, toggle: null, variant: ''}locale: en_USnetwork:version: 2ethernets:eth0:dhcp4: truenameservers:addresses: [8.8.8.8]ssh:allow-pw: trueauthorized-keys: []install-server: true#### POST Install commandslate-commands:- sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /target/etc/ssh/sshd_config- sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /target/etc/ssh/sshd_config# - echo "root:root" | chpasswd# - sed -i '/^GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0 biosdevname=0"@' /target/etc/default/grub && update-grub # there is no grub2-common- sed -i '/^GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0 biosdevname=0"@' /target/etc/default/grub# - apt -y install grub2-common# - grub-mkconfig -o /target/boot/grub/grub.cfg- echo '#!/bin/bash' > /target/etc/rc.local- echo 'echo root:root | chpasswd' >> /target/etc/rc.local- echo 'update-grub' >> /target/etc/rc.local- echo 'touch /root/haha' >> /target/etc/rc.local- echo 'rm -- "$0"' >> /target/etc/rc.local- echo 'reboot' >> /target/etc/rc.local- chmod a+x /target/etc/rc.local
然后进入到/root/http_server
python -m http.server 3003
安装CentOS
CentOS-7-x86_64-Everything-2009.iso
mkdir /iso/centos7
mount -o loop,ro CentOS-7-x86_64-Everything-2009.iso /iso/centos7/
cobbler import --path=/iso/centos7 --name=centos7
准备好centos7.ks,修改里边的IP
cobbler profile edit --name centos7-x86_64 --autoinstall centos7.ks
附录
autounattended.xml
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend"><servicing><package action="configure"><assemblyIdentity name="Microsoft-Windows-Foundation-Package" version="10.0.17763.1" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="" /><selection name="RemoteAccess" state="true" /><selection name="Remote-Desktop-Services" state="true" /></package><package action="configure" permanence="permanent"><assemblyIdentity name="Microsoft-Windows-InternetExplorer-Optional-Package" version="11.0.17763.1" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="" /></package><package action="configure" permanence="permanent"><assemblyIdentity name="OpenSSH-Client-Package" version="10.0.17763.1" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="" /></package></servicing><settings pass="windowsPE"><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-US</UILanguage></SetupUILanguage><InputLocale>0c09:00000409</InputLocale><SystemLocale>zh-CN</SystemLocale><UILanguage>zh-CN</UILanguage><UILanguageFallback>zh-CN</UILanguageFallback><UserLocale>zh-CN</UserLocale></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>1</Order><Size>485</Size><Type>Primary</Type></CreatePartition><CreatePartition wcm:action="add"><Order>2</Order><Size>100</Size><Type>EFI</Type></CreatePartition><CreatePartition wcm:action="add"><Order>3</Order><Size>128</Size><Type>MSR</Type></CreatePartition><CreatePartition wcm:action="add"><Order>4</Order><Type>Primary</Type><Extend>true</Extend></CreatePartition></CreatePartitions><ModifyPartitions><ModifyPartition wcm:action="add"><Format>NTFS</Format><Label>WINRE</Label><Order>1</Order><PartitionID>1</PartitionID></ModifyPartition><ModifyPartition wcm:action="add"><Order>2</Order><Format>FAT32</Format><Label>System</Label><PartitionID>2</PartitionID></ModifyPartition><ModifyPartition wcm:action="add"><Order>3</Order><PartitionID>3</PartitionID></ModifyPartition><ModifyPartition wcm:action="add"><Letter>C</Letter><Order>4</Order><PartitionID>4</PartitionID><Label>Windows</Label><Format>NTFS</Format></ModifyPartition></ModifyPartitions><DiskID>0</DiskID><WillWipeDisk>true</WillWipeDisk></Disk></DiskConfiguration><ImageInstall><OSImage><InstallFrom><MetaData wcm:action="add"><Key>/IMAGE/NAME</Key><Value>Windows Server 2019 SERVERSTANDARD</Value></MetaData></InstallFrom><InstallTo><DiskID>0</DiskID><PartitionID>4</PartitionID></InstallTo></OSImage></ImageInstall><UserData><ProductKey><Key>N69G4-B89J2-4G8F4-WWYCC-J464C</Key></ProductKey><AcceptEula>true</AcceptEula><FullName>ankele</FullName><Organization>ankele</Organization></UserData><DynamicUpdate><Enable>false</Enable></DynamicUpdate></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>false</EnableLUA></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>1</SkipRearm></component></settings><settings pass="specialize"><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>0c09:00000409</InputLocale><SystemLocale>zh-CN</SystemLocale><UILanguage>zh-CN</UILanguage><UILanguageFallback>zh-CN</UILanguageFallback><UserLocale>zh-CN</UserLocale></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>true</SkipAutoActivation></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>0</CEIPEnabled></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>-PC-ankele</ComputerName><ProductKey>N69G4-B89J2-4G8F4-WWYCC-J464C</ProductKey></component><component name="Networking-MPSSVC-Svc" 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"><PrivateProfile_EnableFirewall>false</PrivateProfile_EnableFirewall><PublicProfile_EnableFirewall>false</PublicProfile_EnableFirewall></component></settings><settings pass="oobeSystem"><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>aQBuAHMAdABhAGMAawBQAGEAcwBzAHcAbwByAGQA</Value><PlainText>false</PlainText></Password><Enabled>true</Enabled><Username>ankele</Username></AutoLogon><DesktopOptimization><GoToDesktopOnSignIn>true</GoToDesktopOnSignIn><ShowWindowsStoreAppsOnTaskbar>false</ShowWindowsStoreAppsOnTaskbar></DesktopOptimization><FirstLogonCommands><SynchronousCommand wcm:action="add"><CommandLine>reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f</CommandLine><Order>1</Order><RequiresUserInput>false</RequiresUserInput></SynchronousCommand></FirstLogonCommands><OOBE><VMModeOptimizations><SkipAdministratorProfileRemoval>true</SkipAdministratorProfileRemoval><SkipNotifyUILanguageChange>true</SkipNotifyUILanguageChange><SkipWinREInitialization>true</SkipWinREInitialization></VMModeOptimizations></OOBE><UserAccounts><AdministratorPassword><Value>aQBuAHMAdABhAGMAawBBAGQAbQBpAG4AaQBzAHQAcgBhAHQAbwByAFAAYQBzAHMAdwBvAHIAZAA=</Value><PlainText>false</PlainText></AdministratorPassword><LocalAccounts><LocalAccount wcm:action="add"><Password><Value>aQBuAHMAdABhAGMAawBQAGEAcwBzAHcAbwByAGQA</Value><PlainText>false</PlainText></Password><Description>pc of ankele</Description><DisplayName>ankele</DisplayName><Group>Administrators</Group><Name>ankele</Name></LocalAccount></LocalAccounts></UserAccounts><BluetoothTaskbarIconEnabled>false</BluetoothTaskbarIconEnabled><ConvertibleSlateModePromptPreference>0</ConvertibleSlateModePromptPreference><DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet><DoNotCleanTaskBar>true</DoNotCleanTaskBar><EnableStartMenu>true</EnableStartMenu><RegisteredOrganization>ankele</RegisteredOrganization><RegisteredOwner>ankele</RegisteredOwner><ShowPowerButtonOnStartScreen>true</ShowPowerButtonOnStartScreen><SignInMode>0</SignInMode><TimeZone>Asia/Shanghai</TimeZone></component></settings><cpi:offlineImage cpi:source="wim:c:/users/86153/desktop/install.wim#Windows Server 2019 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi" />
</unattend>
centos7.ks
cat centos7.ks
# Sample kickstart file for current EL, Fedora based distributions.#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
# wlsd mod 2
#url --url=$tree
url --url=http://192.168.1.177/cblr/links/centos7-x86_64/
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.1.177/cobbler/distro_mirror/centos7# Network information
network --bootproto=dhcp --device=eth0 --onboot=on# Reboot after installation
reboot#Root password
rootpw --iscrypted $1$wHSPTJgs$o8vHsC2Krje.9QMb8slNe/
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone America/New_York
# Install OS instead of upgrade
# wlsd, install has been removed
#install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart%preset -x -v
exec 1>/tmp/ks-pre.log 2>&1# Once root's homedir is there, copy over the log.
while : ; dosleep 10if [ -d /mnt/sysimage/root ]; thencp /tmp/ks-pre.log /mnt/sysimage/root/logger "Copied %pre section log to system"breakfi
done &curl "http://192.168.1.177/cblr/svc/op/trig/mode/pre/profile/centos7-x86_64" -o /dev/null# Enable installation monitoring
#ip -o -4 a | awk '!/^[0-9]*: ?lo/ {print $2, $4}' > /tmp/ip
#curl "http://192.168.1.177:5000/c?ip=$IP"
%end%packages
@core
%end%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1%end%post
set -x -v
exec 1>/root/ks-post.log 2>&1# Start yum configuration
# wlsd mod 2
#curl "http://192.168.1.177/cblr/svc/op/yum/profile/centos7-x86_64" --output /etc/yum.repos.d/cobbler-config.repo
curl "http://192.168.1.177/cblr/distro_mirror/config/centos7-x86_64-0.repo" --output /etc/yum.repos.d/cobbler-config.repo# End yum configuration# Start post_install_network_config generated code
# End post_install_network_config generated code# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)# Start koan environment setup
echo "export COBBLER_SERVER=192.168.1.177" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.1.177" > /etc/profile.d/cobbler.csh
# End koan environment setup# begin Red Hat management server registration
# not configured to register to any Red Hat management server (ok)
# end Red Hat management server registration# Begin cobbler registration
# cobbler registration is disabled in /etc/cobbler/settings.yaml
# End cobbler registration# Enable post-install boot notification# Start final stepscurl "http://192.168.1.177/cblr/svc/op/autoinstall/profile/centos7-x86_64" -o /root/cobbler.ks
curl "http://192.168.1.177/cblr/svc/op/trig/mode/post/profile/centos7-x86_64" -o /dev/null
# End final steps
%end
inspect.ks
inspect的作用是在安装操作系统之前获取物理机的MAC地址,这里我在192.168.1.177上搞了一个restful接口,用于接收来自inspect的主机的MAC地址信息,然后便可以实现通过system来固定裸机要安装什么操作系统以及要给裸机什么IP了(指定IP目前仅支持Centos),这里可以跳过不看
# Sample kickstart file for current EL, Fedora based distributions.# platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Use network installation
# wlsd mod 2
# url --url=$tree
url --url=http://192.168.1.177/cblr/links/centos7-x86_64/
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
repo --name=source-1 --baseurl=http://192.168.1.177/cobbler/distro_mirror/centos7# Network information
network --bootproto=dhcp --device=eth0 --onboot=on# wlsd
# Reboot after installation
interactive
# reboot
# poweroff#Root password
rootpw --iscrypted $1$wHSPTJgs$o8vHsC2Krje.9QMb8slNe/
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone America/New_York
# Install OS instead of upgrade
# wlsd, install has been removed
# install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
autopart%pre
# wlsd
# ip -o -4 a | awk 'BEGIN{OFS="-"} !/^[0-9]*: ?lo/ {print $2,$4}'
# ip -o -4 a | awk '!/^[0-9]*: ?lo/ {print $2}' > /tmp/ifname
# ip -o -4 a | awk '!/^[0-9]*: ?lo/ {print $4}' > /tmp/ipaddr# ip -o -4 a | awk '!/^[0-9]*: ?lo/ {if (!done) {print $2; done=1}}' > /tmp/ifname
# ip -o -4 a | awk '!/^[0-9]*: ?lo/ {if (!done) {print $4; done=1}}' > /tmp/ipaddr
# ip -o link show | awk '$2 !~ /lo:/ {print $17; exit}'> /tmp/macaddr
# dmidecode -t baseboard > /tmp/baseboard
# ifname=$(cat /tmp/ifname)
# ipaddr=$(cat /tmp/ipaddr)
# macaddr=$(cat /tmp/macaddr)
# echo $ifname > /etc/ifname
# echo $ipaddr > /etc/ipaddr
# echo $macaddr > /etc/macaddr
# curl "http://192.168.1.177:5000/report_if?ifname=$ifname&ipaddr=$ipaddr&macaddr=$macaddr"ip a > /tmp/ip
dmidecode -t baseboard > /tmp/inspect_info
curl -X POST -F "file=@/tmp/ip" "http://192.168.1.177:5000/inspect_info"
curl -X POST -F "file=@/tmp/inspect_info" "http://192.168.1.177:5000/inspect_info"set -x -v
exec 1>/tmp/ks-pre.log 2>&1# Once root's homedir is there, copy over the log.
while : ; dosleep 10if [ -d /mnt/sysimage/root ]; thencp /tmp/ks-pre.log /mnt/sysimage/root/logger "Copied %pre section log to system"breakfi
done &curl "http://192.168.1.177/cblr/svc/op/trig/mode/pre/profile/centos7-x86_64" -o /dev/null# Enable installation monitoring
# ip -o -4 a | awk '!/^[0-9]*: ?lo/ {print $2, $4}' > /tmp/ip
# curl "http://192.168.1.177:5000/c?ip=$IP"
%end%packages
@core
%end%post --nochroot
set -x -v
exec 1>/mnt/sysimage/root/ks-post-nochroot.log 2>&1%end%post
set -x -v
exec 1>/root/ks-post.log 2>&1# Start yum configuration
# wlsd mod 2
# curl "http://192.168.1.177/cblr/svc/op/yum/profile/centos7-x86_64" --output /etc/yum.repos.d/cobbler-config.repo
curl "http://192.168.1.177/cblr/distro_mirror/config/centos7-x86_64-0.repo" --output /etc/yum.repos.d/cobbler-config.repo# End yum configuration# Start post_install_network_config generated code
# End post_install_network_config generated code# Start download cobbler managed config files (if applicable)
# End download cobbler managed config files (if applicable)# Start koan environment setup
echo "export COBBLER_SERVER=192.168.1.177" > /etc/profile.d/cobbler.sh
echo "setenv COBBLER_SERVER 192.168.1.177" > /etc/profile.d/cobbler.csh
# End koan environment setup# begin Red Hat management server registration
# not configured to register to any Red Hat management server (ok)
# end Red Hat management server registration# Begin cobbler registration
# cobbler registration is disabled in /etc/cobbler/settings.yaml
# End cobbler registration# Enable post-install boot notification# Start final stepscurl "http://192.168.1.177/cblr/svc/op/autoinstall/profile/centos7-x86_64" -o /root/cobbler.ks
curl "http://192.168.1.177/cblr/svc/op/trig/mode/post/profile/centos7-x86_64" -o /dev/null
# End final steps
%end
pxelinux.cfg
从BIOS引导centos7和Ubuntu
[root@localhost tftpboot]# cat pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | https://cobbler.github.io
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT localLABEL localMENU LABEL (local)MENU DEFAULTLOCALBOOT -1LABEL centos7-x86_64MENU LABEL centos7-x86_64kernel /images/centos7-x86_64/vmlinuzappend initrd=/images/centos7-x86_64/initrd.img kssendmac inst.ks=http://192.168.1.177/cblr/svc/op/autoinstall/profile/centos7-x86_64ipappend 2LABEL inspect-x86_64MENU LABEL inspect-x86_64kernel /images/inspect-x86_64/vmlinuzappend initrd=/images/inspect-x86_64/initrd.img kssendmac inst.ks=http://192.168.1.177/cblr/svc/op/autoinstall/profile/inspect-x86_64ipappend 2LABEL ubuntu20046-casper-x86_64MENU LABEL ubuntu20046-casper-x86_64kernel /images/ubuntu20046-casper-x86_64/vmlinuzinitrd /images/ubuntu20046-casper-x86_64/initrdappend biosdevname=0 net.ifnames=0 netcfg/choose_interface=auto ip=dhcp autoinstall ds='nocloud-net;s=http://192.168.1.177:3003/' cloud-config-url=http://192.168.1.177:3003/user-data url=http://192.168.1.177/cobbler/isos/ubuntu-20.04.6-live-server-amd64.isoipappend 2MENU end
ipxe/default.ipxe
从ipxe引导Windows2019
#!ipxeset menu-timeout 20000
set submenu-timeout ${menu-timeout}# Set Menu Default to Exit after timeout
isset ${menu-default} || set menu-default local:Cobbler
menu Cobbler | https://cobbler.github.io
item local (local)
item win2019-x86_64 win2019-x86_64
choose --default ${menu-default} --timeout ${menu-timeout} target && goto ${target}:win2019-x86_64
kernel http://192.168.1.177/cobbler/images/win2019-x86_64/wimboot
initrd --name boot.sdi http://192.168.1.177/cobbler/images/win2019-x86_64/boot.sdi boot.sdi
initrd --name bootmgr.exe http://192.168.1.177/cobbler/images/win2019-x86_64/bootmgr.exe bootmgr.exe
initrd --name bcd http://192.168.1.177/cobbler/images/win2019-x86_64/bcd bcd
initrd --name winpe.wim http://192.168.1.177/cobbler/images/win2019-x86_64/winpe.wim winpe.wim
boot:local
iseq ${smbios/manufacturer} HP && exit ||
sanboot --no-describe --drive 0x80
更全的ipxe/default.ipxe
UEFI+ipxe引导Windows,centos,Ubuntu
cat ipxe/default.ipxe
#!ipxeset menu-timeout 20000
set submenu-timeout ${menu-timeout}# Set Menu Default to Exit after timeout
isset ${menu-default} || set menu-default local:Cobbler
menu Cobbler | https://cobbler.github.io
item local (local)
item centos7-x86_64 centos7-x86_64
item inspect-x86_64 inspect-x86_64
item ubuntu20046-casper-x86_64 ubuntu20046-casper-x86_64
item win2019-x86_64 win2019-x86_64
choose --default ${menu-default} --timeout ${menu-timeout} target && goto ${target}:centos7-x86_64
kernel http://192.168.1.177/cobbler/images/centos7-x86_64/vmlinuz
initrd http://192.168.1.177/cobbler/images/centos7-x86_64/initrd.img
imgargs vmlinuz initrd=initrd.img inst.ks=http://192.168.1.177/cblr/svc/op/autoinstall/profile/centos7-x86_64
boot:inspect-x86_64
kernel http://192.168.1.177/cobbler/images/inspect-x86_64/vmlinuz
initrd http://192.168.1.177/cobbler/images/inspect-x86_64/initrd.img
imgargs vmlinuz initrd=initrd.img inst.ks=http://192.168.1.177/cblr/svc/op/autoinstall/profile/inspect-x86_64
boot:ubuntu20046-casper-x86_64
kernel http://192.168.1.177/cobbler/images/ubuntu20046-casper-x86_64/vmlinuz
initrd http://192.168.1.177/cobbler/images/ubuntu20046-casper-x86_64/initrd
imgargs vmlinuz initrd=initrd biosdevname=0 net.ifnames=0 netcfg/choose_interface=auto ip=dhcp autoinstall ds='nocloud-net;s=http://192.168.1.177:3003/' cloud-config-url=http://192.168.1.177:3003/user-data url=http://192.168.1.177/cobbler/isos/ubuntu-20.04.6-live-server-amd64.iso
boot:win2019-x86_64
kernel http://192.168.1.177/cobbler/images/win2019-x86_64/wimboot
initrd --name boot.sdi http://192.168.1.177/cobbler/images/win2019-x86_64/boot.sdi boot.sdi
initrd --name bootmgr.exe http://192.168.1.177/cobbler/images/win2019-x86_64/bootmgr.exe bootmgr.exe
initrd --name bcd http://192.168.1.177/cobbler/images/win2019-x86_64/bcd bcd
initrd --name winpe.wim http://192.168.1.177/cobbler/images/win2019-x86_64/winpe.wim winpe.wim
boot:local
iseq ${smbios/manufacturer} HP && exit ||
sanboot --no-describe --drive 0x80
注意
错误
局域网中有路由器,路由器开启了dhcp,虽然第一次获取IP地址时,需要tftp,而必须走我们的dnsmasq,但后续dhcp ack时,有可能因为路由器给了一个IP地址,用此IP作为dhcp ack会报错,然后被dnsmasq拒绝掉
dnsmasq报错:DHCPNAK(ens3) 192.168.1.106 f0:1f:af:f0:da:6a wrong server-ID
所以,还是直接关掉路由器dhcp,保证局域网中只有一个dhcp服务器