PXE的工作过程:
1. PXE Client 从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP;
2. DHCP 服务器返回分配给客户机的IP 以及PXE文件的放置位置(该文件一般是放在一台TFTP服务器上) ;
3. PXE Client 向本网络中的TFTP服务器索取pxelinux.0 文件;
4. PXE Client 取得pxelinux.0 文件后之执行该文件;
5. 根据pxelinux.0 的执行结果,通过TFTP服务器加载内核和文件系统 ;
6. 进入安装画面, 此时可以通过选择HTTP、FTP、NFS 方式之一进行安装;
系统环境
实验环境:VirtualBox5.0
系统平台:CentOS release 6.7 (最小化安装)
网络模式:Bridege
DHCP / TFTP IP:192.168.55.101
HTTP / FTP / NFS IP:192.168.55.101
防火墙已关闭/iptables: Firewall is not running.
SELINUX=disabled
一、配置HTTP服务器
1.1 安装HTTP。
# yum install httpd –y
# rpm -qa|grep httpd
1.2 开启服务并设置开机启动
# /etc/init.d/httpd start
# chkconfig httpd on
二、配置ISO源
2.1 将iso文件挂载至/media/CentOS
# mkdir /media/CentOS
# mount /dev/cdrom /media/CentOS
2.2 复制光盘全部内容至http 的根目录/var/www/html/ 下
#cp -r /media/CentOS /var/www/html/
确保能通过http://192.168.55.101/CentOS/ 访问ISO源
三、配置TFTP
3.1 安装TFTP
# yum install tftp-server –y
3.2 配置并启用tftp 服务
# vi /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
将disable 设置为no
因为tftp服务是挂载在超级进程xinetd 下的,所以通过启动xinetd 来启动tftp服务。
# /etc/init.d/xinetd restart
3.3 设置开机启动xinetd
# chkconfig xinetd on
四、配置支持PXE的启动程序
4.1 安装syslinux
#yum install syslinux -y
4.2 复制pxelinux.0 文件至/var/lib/tftpboot/ 文件夹中
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
说明:syslinux是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX是一个小型的Linux操作系统,它的目的是简化首次安装Linux的时间,并建立修护或其它特殊用途的启动盘。
4.3 复制iso 镜像中的/image/pxeboot/initrd.img 和vmlinux 至/var/lib/tftpboot/ 文件夹中
# cp /var/www/html/CentOS/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/
4.4 复制iso 镜像中的/isolinux/*.msg 至/var/lib/tftpboot/ 文件夹中
# cp /var/www/html/CentOS/isolinux/*.msg /var/lib/tftpboot/
4.5 在/var/lib/tftpboot/ 中新建一个pxelinux.cfg目录
# mkdir /var/lib/tftpboot/pxelinux.cfg
4.6 将iso 镜像中的/isolinux 目录中的isolinux.cfg复制到pxelinux.cfg目录中,同时更改文件名称为default
# cp /var/www/html/CentOS/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
4.7 修改default文件
# vi /var/lib/tftpboot/pxelinux.cfg/default
#default vesamenu.c32
default linux
#prompt 1
timeout 600
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.7!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.1.107/ks.cfg
label vesa
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img nomodeset
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
五、配置DHCP
5.1 安装DHCP服务
# yum -y install dhcp
5.2 复制配置模板文件到DHCP的配置目录中
# cp -f /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
5.3 修改/etc/dhcp/dhcpd.conf 配置文件,内容如下:
ddns-update-style interim;
ignore client-updates;
filename "pxelinux.0"; #pxelinux 启动文件位置;
next-server 192.168.55.101; #TFTP Server 的IP地址;
subnet 192.168.55.0 netmask 255.255.255.0 {
option routers 192.168.55.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.55.100 192.168.55.200;
default-lease-time 21600;
max-lease-time 43200;
}
5.4 启动DHCP服务
# /etc/init.d/dhcpd start
六、生成ks.cfg 文件
编辑ks.cfg文件保存在/var/www/html/ 文件夹下
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=http://192.168.55.101/CentOS/
# Root password
rootpw password
# System authorization information
auth --useshadow --enablemd5
text
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
key --skip
bootloader --append="rhgb quiet" --location=mbr --driveorder=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="ext4" --size=4096
part swap --fstype="swap" --size=1024
part /home --fstype="ext4" --size=2048
%packages --nobase
@core
%end
reboot 此选项必须存在,也必须文中设定位置,不然kickstart显示一条消息,并等待用户按任意键后才重新引导;
clearpart --all --initlabel 此条命令必须添加,不然系统会让用户手动选择是否清除所有数据,这就需要人为干预了,从而导致自动化过程失败;