什么是PXE?
PXE( Preboot Execution Environment
的缩写,即预启动执行环境)是由Intel设计的一种网络协议,可使计算机通过网络启动安装系统,同时也是一种使用网络接口启动计算机的机制,其不依赖本地数据存储设备或本地已安装的系统;协议分为client端和server端,PXE client在网卡的boot ROM中启动,当计算机开机引导时,BIOS把PXE client调入内存执行,并显示出命令菜单,经用户选择需要安装的系统后,PXE client将放置在远端的操作系统通过网络下载到本地运行;
常见安装方式:
PXE server的四种模式
PXE有四种启动模式,分别为 IPV4 legacy
,IPV4 UEFI
,IPV6 legacy
,IPV6 UEFI
,这里主要介绍IPV4 legacy
启动模式需要的文件。
1.pxelinux.0
: 计算机自展引导程序(bootstrap),负责系统引导和启动,作用类似于BIOS,会调用PXE相关配置文件
2.pxelinux.cfg
: 文件夹,存放PXE配置文件vmlinuz
: linux的内核文件,可以被引导程序加载,从而启动Linux系统
3.initrd.img
: boot loader initialized RAM disk的缩写,作为根文件系统加载各种模块、驱动、服务等,网卡驱动就包含在该文件中.
ROM
芯片;dhcp
,tftp
,nfs
服务且为开启状态;bootstrap
文件,tftp.server收到请求向客户端发送bootstrap文件 -->pxelinux.0
;default
文件,等待用户选择安装系统后,客户端向tftp.server发出提供内核文件vmlinuz
和根文件系统initrd.img
请求;关闭Firewalls & SELinuxservice iptables stop
#临时有效,重启后防火墙自动打开chkconfig iptables off
#永久有效,重启后防火墙不自动打开setenforce 0
#临时有效,重启后失效vim /etc/selinux/config
#永久有效,重启后也有效SELINUX=disabled
检查是否安装了dhcp,tftp,nfs服务rpm -qa | grep -i dhcp
rpm -qa | grep -i tftp
rpm -qa | grep -i nfs
配置yum源(如已安装了dhcp,tftp,nfs服务可忽略该步骤)vim /etc/yum.repos.d/server.repo
[development]
name=development
baseurl=file:///mnt/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
安装dhcp,ftp,nfs服务(如已安装了dhcp,tftp,nfs服务可忽略该步骤)yum install -y dhcp
yum install -y tftp
yum install -y nfs
配置任意网口信息,并设定IP地址vim /etc/sysconfig/network-scripts/ifcfg-enp3s0f0
NAME="enp3s0f0"
DEVICE="enp3s0f0"
ONBOOT=yes #开机自启
NETBOOT=yes
UUID="169f6948-307c-42a7-bb35-a773c86fb5d6"
BOOTPROTO=none #IP地址类型
IPADDR=192.168.1.250 #IP地址
TYPE=Ethernet
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_FAILURE_FATAL=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
开启网络服务:service network start/restart
or systemctl start network.service
配置dhcp.conf并启动服务vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
class "pxeclients" {
match if substring(option vendor-class-identifier,0,9)="PXEClient";
next-server 192.168.1.250;
filename "pxelinux.0";
}
subnet 192.168.1.0 netmask 255.255.255.0 {
option broadcast-address 192.168.1.255;
option routers 192.168.1.250;
option subnet-mask 255.255.255.0;
range 192.168.1.205 192.168.1.249;
default-lease-time 8640000;
}
启动dhcp服务:service dhcp start
or chkconfig dhcpd on
配置tftp并启动服务vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer protocol.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
启用tftp服务:service tftp start
or /etc/init.d/xinetd start
or chkconfig tftp on 开机自启
配置nfs并启动服务vim /etc/exports
/tftpboot *(rw,no_root_squash)
启用nfs服务:service nfs start
准备系统镜像文件mount -o loop rhel7.4.iso /mnt
#将镜像挂载在'/mnt'下mkdir /tftpboot/rhel7.4
#创建文件夹cp -rf /mnt/* /tftpboot/rhel7.4
拷贝文件至新建文件夹下chmod -R +x /tftpboot/rhel7.4
#给文件赋予执行权限cp -rf /usr/share/syslinux/pxelinux.0 /tftpboot/
cp -rf boot.msg vesamenu.c32 splash.png /tftpboot/
mkdir /tftpboot/pxelinux.cfg
cp -rf /tftpboot/rhel7.4/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/
mv /tftpboot/pxelinux.cfg/isolinux.cfg /tftpboot/pxelinux.cfg/default
#更改文件名字
配置pxelinux.cfg文件vim default
default vesamenu.c32
prompt 1
timeout 600
display boot.msg
menu background 1.jpg
menu title Welcome!
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 install
menu label ^1)Install rhel7.4 in /dev/sda
menu default
kernel rhel7.4/vmlinuz biosdevname=0
append initrd=rhel7.4/initrd.img ks=nfs:192.168.1.250:/tftpboot/rhel7.4/ks/ks.cfg
配置无人值守kickstart文件
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$BrX4T9WN$OXLjtLaSe7VNnmjlsUyXE0
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
install
graphical
# SELinux configuration
selinux --disabled
# Use NFS installation media
nfs --server=192.168.1.250 --dir=/tftpboot/rhel7.4
# Network information
network --bootproto=dhcp --device=enp3s0f0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Partition clearing information
clearpart --all --drives=sda
# System bootloader configuration
bootloader --append="crashkernel=768M vconsole.font=latarcyrheb-sun16 vconsole.keymap=us biosdevname=0 ipv6.
disable=1 console=tty0 console=ttyS0,115200 scsi_mod.scan=sync intel_idle.max_cstate=0 pci=pcie_bus_perf
nouveau.modeset=0 rd.driver.blacklist=nouveau video=vesa:off rd.driver.pre=ahci" --location=mbr --boot-drive
=sda
# autopart --type=lvm
part /boot --asprimary --fstype="ext4" --ondisk=sda --size=1024
part swap --asprimary --fstype="swap" --ondisk=sda --size=51200
part / --asprimary --fstype="ext4" --ondisk=sda --size=153600
%packages
@additional-devel
@anaconda-tools
@backup-client
@backup-server
@base
@compat-libraries
@console-internet
@core
@debugging
@desktop-debugging
@development
@dial-up
@directory-client
@directory-server
@dns-server
@emacs
@file-server
@fonts
@ftp-server
@gnome-apps
@gnome-desktop
@graphical-admin-tools
@graphics
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@identity-management-server
@infiniband
@input-methods
@internet-browser
@java-platform
@kde-desktop
@large-systems
@legacy-unix
@legacy-x
@load-balancer
@mail-server
@mainframe-access
@mariadb
@mariadb-client
@multimedia
@network-file-system-client
@network-server
@network-tools
@networkmanager-submodules
@perl-runtime
@perl-web
@php
@platform-devel
@platform-kvm
@platform-microsoft
@platform-vmware
@postgresql
@postgresql-client
@print-client
@print-server
@python-web
@remote-desktop-clients
@remote-system-management
@ruby-runtime
@scientific
@security-tools
@smart-card
@system-admin-tools
@system-management
@technical-writing
@virtualization-client
@virtualization-hypervisor
@virtualization-platform
@virtualization-tools
@web-server
@web-servlet
@x11
%end
以上,便完成了整个PXE的部署流程。
作者:Clancy_H
链接:https://www.jianshu.com/p/6a44b0a6b87b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。