Cenos7搭建PXE环境(Legacy/BIOS模式)
由于工作中需要使用PXE环境进行一些网卡PXE功能验证,故自己尝试搭建了一个PXE环境,但不是很完善,不适用于企业级生产环境,只作为一个参考。
PXE=httpd+dhcp+tftp+xinetd
系统安装启动模式有两种,一种是UEFI模式,另外一种是Legacy模式,DELL服务器也叫BIOS模式,本文叫Legacy模式(Bios模式)。
物理OS: CentOS7.6
PXEOS: CentOS7.6
基于YUM安装DHCP、TFTP、HTTPD服务,命令如下:
yum install httpd httpd-devel dhcp* tftp-server xinetd -y
1. 配置 tftp,:
cat>/etc/xinetd.d/tftp<<EOF
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -u nobody -s /var/lib/tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}
EOF
因为是物理机环境搭建PXE,即需要一个iso文件,做为PXE环境的镜像,我们要提取这个镜像文件到我们的PXE环境中,这里用的是CentOS-7.6-x86_64-DVD-1810.iso。
先将这个镜像文件打开,并将里面的文件提取到/mnt/iso/下,然后将提取的文件,放到对应的配置文件下。
[root@localhost ~] mkdir -p /var/lib/tftpboot/pxelinux.cfg/
[root@localhost ~] cp /mnt/iso/isolinux/isolinux.cfg var/lib/tftpboot/pxelinux.cfg/default
[root@localhost ~] cp /mnt/iso/isolinux/vesamenu.c32 /var/lib/tftpboot/
[root@localhost ~] cp /mnt/iso/images/pxeboot/vmlinuz /var/lib/tftpboot/
[root@localhost ~] cp //mnt/iso/images/pxeboot/initrd.img /var/lib/tftpboot/
[root@localhost ~] cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~] chmod 644 /var/lib/tftpboot/pxelinux.cfg/default
2.配置TFTPBOOT引导文件,:
因为我们的PXE环境所用到的httpd+dhcp+tftp+xinetd,都是在一台机器上,所以,有关指向IP地址的都要写我们本机IP地址。
append initrd=initrd.img inst.repo=http://10.0.0.6/centos7 quiet ks=http://10.0.0.6/ks.cfg
#repo=http://10.0.0.6/centos7指的是httpd存放镜像的路径
#ks=http://10.0.0.6/ks.cfg指的是ks的配置文件文件
cat>/var/lib/tftpboot/pxelinux.cfg/default<<EOF
default vesamenu.c32
timeout 10
display boot.msg
menu clear
menu background splash.png
menu title CentOS Linux 7
label linux
menu label ^Install CentOS Linux 7
menu default
kernel vmlinuz
append initrd=initrd.img inst.repo=http://10.0.0.6/centos7 quiet ks=http://10.0.0.6/ks.cfg
label check
menu label Test this ^media & install CentOS Linux 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
EOF
3.HTTP的配置,:
#创建存放镜像文件的目录centos7
[root@localhost ~] mkdir -p /var/www/html/centos7/
#将刚刚提取出来的镜像文件,全部复制到centos7目录下,后面pxe的过程中,会自动到这里寻找安装的镜像文件
[root@localhost ~] cp /mnt/iso/* /var/www/html/centos7/
4.配置ks.cfg配置文件内容如下,:
url --url=http://10.0.0.6/centos7
#指的是我们镜像存放地/var/www/html/centos7/
rootpw 123456
#指的是通过pxe安装的系统,root的密码123456
cat>/var/www/html/ks.cfg<<EOF
install
text
keyboard 'us'
rootpw 123456
timezone Asia/Shanghai
url --url=http://10.0.0.6/centos7
lang zh_CN
firewall --disabled
network --bootproto=dhcp --device=ens33
auth --useshadow --passalgo=sha512
firstboot --disable
selinux --disabled
bootloader --location=mbr
clearpart --all --initlabel
part /boot --fstype="ext4" --size=300
part / --fstype="ext4" --grow
part swap --fstype="swap" --size=512
reboot
%packages
@base
@core
%end
EOF
5.配置DHCP服务,DHCP服务配置文件代码如下,:
cat>/etc/dhcp/dhcpd.conf<<EOF
ddns-update-style interim;
ignore client-updates;
next-server 192.168.10.4;
filename "pxelinux.0";
allow booting;
allow bootp;
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.10.180 192.168.10.200;
}
EOF
6.启动各个服务,
systemctl start httpd
systemctl start tftp
systemctl start xinetd
systemctl start dhcpd
在这里一般会遇到dhcpd启动失败的情况,多数都是配置文件的IP地址写错了
这个时候要检查
/var/lib/tftpboot/pxelinux.cfg/default
/var/www/html/ks.cfg
/etc/dhcp/dhcpd.conf