PXE脚本分成四个模块来写。
一、DHCP内容
subnet 192.168.4.0 netmask 255.255.255.0 {
range 192.168.4.100 192.168.4.200;
option domain-name-servers 192.168.4.7;
option routers 192.168.4.254;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.4.7;
filename “pxelinux.0”;
}
二、ks.cfg无人应答文件配置
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
install
keyboard ‘us’
rootpw --iscrypted 1 1 1zjCK.pRB$k38r54VUUMegOfFgK8KND/
url --url=“http://192.168.4.7/centos”
lang en_US
auth --useshadow --passalgo=sha512
graphical
firstboot --disable
selinux --disabled
firewall --disabled
network --bootproto=dhcp --device=eth0
reboot
timezone Asia/Shanghai
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part / --fstype=“xfs” --grow --size=1
%packages
@base
%end
三、界面代码
default vesamenu.c32
timeout 600
display boot.msg
menu clear
menu background splash.png
menu title WangXinKun1.0
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
menu color border * #00000000 #00000000 none
menu color sel 0 #ffffffff #00000000 none
menu color title 0 #ff7ba3d0 #00000000 none
menu color tabmsg 0 #ff3a6496 #00000000 none
menu color unsel 0 #84b8ffff #00000000 none
menu color hotsel 0 #84b8ffff #00000000 none
menu color hotkey 0 #ffffffff #00000000 none
menu color help 0 #ffffffff #00000000 none
menu color scrollbar 0 #ffffffff #ff355594 none
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install CentOS 7
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.4.7/ks.cfg
四、核心代码
#!/bin/bash
a=!
yum -y install httpd &>/dev/null
rpm -q httpd &>/dev/null &&
mkdir /var/www/html/centos
mount /dev/cdrom /var/www/html/centos &>/dev/null && echo -e “I.Web服务------------------------\033[33m[readyKaTeX parse error: Expected 'EOF', got '\0' at position 3: a]\̲0̲33[0m" #yum -y …a]\033[0m”
yum -y install tftp-server &>/dev/null
rpm -q tftp-server &>/dev/null &&
yum -y install syslinux &>/dev/null
rpm -q syslinux &>/dev/null &&
cd /var/www/html/centos/isolinux
\cp -p /usr/share/syslinux/pxelinux.0 vmlinuz splash.png vesamenu.c32 initrd.img /var/lib/tftpboot/
cd /var/lib/tftpboot/
mkdir pxelinux.cfg
echo “界面内容” > pxelinux.cfg/default && echo -e “III.TFTP服务------------------\033[33m[readyKaTeX parse error: Expected 'EOF', got '\0' at position 3: a]\̲0̲33[0m" yum -y i…a]\033[0m”
if [ KaTeX parse error: Expected 'EOF', got '\0' at position 56: …d || echo -e "\̲0̲33[31mNo\033[0m…a\033[0m"
systemctl enable httpd &>/dev/null
systemctl restart tftp || echo -e “\033[31mNo\033[0m” && echo -e “\033[35mSuccessfullyKaTeX parse error: Expected 'EOF', got '\0' at position 2: a\̲0̲33[0m" …a\033[0m”
systemctl enable dhcpd &>/dev/null
echo -e "\033[37mSuccessfully$a"
else
echo -e “\033[31mError 604:Failed.Service a a aa$a\033[0m” >&2
exit 1
fi