Preboot Excution Environment 预启动执行环境,是Intel公司研发
基于Client/Server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统PXE可以引导和安装Windows,linux等多种操作系统。PXE自动安装系统过程如下所示:
[root@centos7 ~]#getenforce 检查selinux 状态
Disabled
[root@centos7 ~]#iptables -vnL
Chain INPUT (policy ACCEPT 201K packets, 8505K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 201K packets, 2597M bytes)
pkts bytes target prot opt in out source destination
防火墙可以通过 iptables -F 来关闭。
selinux 可以通过 setenforce 0 临时关闭。
yum install httpd tftp-server dhcp syslinux
systemctl enable httpd 设置为开机启动
systemctl start httpd 启动httpd 服务
mkdir /var/www/html/centos/7
mount /dev/sr0 /var/www/html/centos/7 把光盘挂载到目录下,也可以copy 到该目录下。
cp /root/anaconda-ks.cfg /var/www/html/ksdir/ks7-1.cfg
chmod +r /var/www/html/ksdir/ks7-1.cfg
vim /var/www/html/ksdir/ks7-1.cfg
cat ks7-1.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=http://192.168.10.33/centos/7
# Use graphical install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate
network --hostname=centos7.magedu.com
# Root password
rootpw --iscrypted $6$Z7LBEUpwj3iQdYZ3$olYQ.Lj1xV2VAGS1UiNflKF0oMGip3b6tU9QFcp0i2JBjwKlY/Yaexul57NHpIJc.Y2V1hWAOueaqwjuWDGMk0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --password=$6$v.VphW/puRblcrFB$uaSrdEhGAwMXap27WIKTn5lyOOfoFyB/SNxyyL3og6s9/VQoAKoL2KQjKmeYFmoYTuYkSNL7BBxgbJzeryKr9. --iscrypted --gecos="wang"
# X Window System configuration information
xconfig --startxonboot
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
zerombr
clearpart --all
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=2048
part /app --fstype="xfs" --ondisk=sda --size=51200
part / --fstype="xfs" --ondisk=sda --size=51200
part /boot --fstype="xfs" --ondisk=sda --size=1024
reboot
%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
kexec-tools
autofs
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --notempty
%end
%post
systemctl enable autofs
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<eof
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
eof
%end
systemctl enable tftp.socket 设置开机启动
systemctl start tftp.socket 启动tftp服务
netstat -unl 检查状态DHCP服务
vim /etc/dhcp/dhcpd.conf
option domain-name "example.com";
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.50 192.168.10.100;
next-server 192.168.10.33;
filename "pxelinux.0";
}
systemctl enable dhcpd
systemctl start dhcpd
mkdir /var/lib/tftpboot/pxelinux.cfg/ 创建目录
cp/usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
cp /misc/cd/isolinux/{vmlinuz,initrd.img,} /var/lib/tftpboot/ 把光盘里的内核文件和伪根文件拷贝到tftpboot 目录下
cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title CentOS Linux 7 PXE Install
label desktop
menu label Auto Install CentOS Linux 7 ^Desktop
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.10.33/ksdir/ks7-1.cfg #tftp server 地址
label mini
menu label Auto Install CentOS Linux 7 M^ini
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.10.33/ksdir/ks7-2.cfg
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
menu end
文件列表如下:
[root@centos7 ~]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│ └── default
└── vmlinuz