table of Contents
- 1. What is PXE
- Two, the three advantages of PXE
- 3. Prerequisites for PXE installation
- Fourth, build a PXE remote installation server
-
- 1. Install and enable TFTP service
- 2. Install and enable DHCP service
- 3. Prepare the Linux kernel and initialize the image file
- 4. Prepare the PXE boot program
- 5. Install FTP service, prepare CentOS 7 installation source
- 6. Configure the boot menu file
- 7. Turn off the firewall
- 8. Verify PXE network installation
- Five, Kickstart unattended installation
-
- 1. Install the system-config-kickstart tool
- 2. Open the "Kickstart Configuration Program" window
- 3. Configure kickstart options
- 4. Save the automatic response file
- 5. Configure the software packages to be installed
- 6. Edit the boot menu file default and add ks boot parameters
- 7. Verify unattended installation
1. What is PXE
PXE (pre-boot execution environment, running before the operating system) is a network boot technology developed by Intel. It works in Client/Server mode, allowing clients to download boot images from remote servers through the network and load installation files or the entire operating system .
Two, the three advantages of PXE
- Scale : install multiple servers at the same time;
- Automation : install systems, configure various services;
- Remote realization : No CD, U disk and other installation media are required.
3. Prerequisites for PXE installation
- Client computer
- The client's network card must support the PXE protocol (integrated BOOTROM chip)
- The motherboard supports network boot. Some need to allow booting from Network or LAN in BIOS settings.
- Server
- To DHCP server : automatically assign addresses to clients and specify the location of the boot file.
- The server needs to enable the TFTP service (Simple File Transfer Protocol): it is used to download the system kernel and boot image files.
- Use FTP service (or http/nfs) in the server : Provide yum installation source
- Install software package syslinux : provide PXE boot program
xinetd service: a new generation of network daemon service program, also called super server, commonly used to manage a variety of lightweight Internet services.
Fourth, build a PXE remote installation server
1. Install and enable TFTP service
yum -y install tftp-server xinetd
#修改TFTP服务的配置文件
vim /etc/xinetd.d/tftp
protocol = udp #TFTP默认使用UDP协议
wait = no #no表示客户机可以多台一起连接,yes表示客户机只能一台一台连接
server_args = -s /var/lib/tftpboot #指定TFTP根目录(引导文件的存储路径)
disable = no #no表示开启TFTP服务
systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd
After wq saves the configuration file, start the service and set it to start automatically
2. Install and enable DHCP service
yum -y install dhcp
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
#修改DHCP服务的配置文件
vim /etc/dhcp/dhcpd.conf
ddns-update-style none; #禁用 DNS 动态更新
next-server 192.168.163.5; #指定 TFTP 服务器的地址
filename "pxelinux.0"; #指定要下载的 PXE 引导程序的文件
subnet 192.168.163.0 netmask 255.255.255.0 { #声明要分配的网段地址
range 192.168.163.100 192.168.163.200; #设置地址池
option routers 192.168.163.5; #默认网关地址指向TFTP服务器的IP地址
}
systemctl start dhcpd
systemctl enable dhcpd
After wq saves the configuration file, start the service and set it to start automatically
3. Prepare the Linux kernel and initialize the image file
mount /dev/sr0 /mnt
cd /mnt/images/pxeboot
cp vmlinuz /var/lib/tftpboot/ #复制 Linux系统的内核文件 到TFTP根目录下
cp initrd.img /var/lib/tftpboot/ #复制 初始化镜像文件(linux引导加载模块)到TFTP根目录下
4. Prepare the PXE boot program
yum -y install syslinux #PXE引导程序由软件包 syslinux 提供
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #复制 PXE引导程序 到TFTP根目录下
5. Install FTP service, prepare CentOS 7 installation source
yum -y install vsftpd
mkdir /var/ftp/centos7
cp -rf /mnt/* /var/ftp/centos7/
systemctl start vsftpd
systemctl enable vsftpd
6. Configure the boot menu file
默认的启动菜单文件在TFTP根目录的 pxelinux.cfg子目录下,文件名为default
mkdir /var/lib/tftpboot/pxelinux.cfg
vim /var/lib/tftpboot/pxelinux.cfg/default
default auto #指定默认入口名称
prompt 0 #设置是否等待用户选择,“1”表示等待用户控制
label auto #图形安装(默认)引导入口,label 用来定义启动项
kernel vmlinuz #kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.163.5/centos7
label linux text #文本安装引导入口
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.163.5/centos7
label linux rescue #救援模式引导入口
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.163.5/centos7
7. Turn off the firewall
systemctl stop firewalld.service
setenforce 0
8. Verify PXE network installation
- Use a virtual machine created by VMware for testing. The virtual machine's memory must be at least 2GB, otherwise an error may be reported when the installation is started.
- Turn on the virtual machine, when configuring the default step of the boot menu default file,
- If you set "prompt 1", it will be stuck in an interface with a line of prompt string "boot:"
- Press Enter directly (or execute the "auto" command), it will automatically download the installation file through the Internet and enter the default graphical installation entry;
- If you execute the "linux text" command, enter the text installation entry;
- If you execute the "linux rescue" command, you will enter the rescue mode.
- If the setting is "prompt 0", no operation is required, and you can directly enter the default graphical installation entry.
- If you set "prompt 1", it will be stuck in an interface with a line of prompt string "boot:"
Reopen a blank virtual machine with no system installed, and click Start to automatically load the configuration file.
At this point, PXE is complete.
Seeing this, you will find that this does not automatically install the machine at boot, but just enters the installation interface. At this time, the Kickstart unattended installation program is needed.
Five, Kickstart unattended installation
1. Install the system-config-kickstart tool
yum install -y system-config-kickstart
2. Open the "Kickstart Configuration Program" window
方法一:
通过桌面菜单“应用程序”-->“系统工具”-->“Kickstart” 打开
方法二:
执行 “system-config-kickstart” 命令打开
Method 1: Open the program in the graphical interface as shown below.
Method 2:
3. Configure kickstart options
基本配置:
默认语言设为“中文(简体)”
时区设为“Asia/Shanghai”
设置root密码
高级配置中勾选“安装后重启”。
安装方法:
选FTP
FTP服务器:ftp://192.168.163.5
FTP目录:centos7
引导装载程序选项:
“安装类型”:安装新引导装载程序
“安装选项”:在主引导记录(MBR)中安装引导装载程序
分区信息:
主引导记录:清除主引导记录
分区:删除所有现存分区
磁盘标签:初始化磁盘标签
布局:添加分区
挂载点:/boot,文件系统类型:xfs,固定大小:500M
文件系统类型:swap,固定大小:4096M
挂载点:/home,文件系统类型:xfs,固定大小:4096M
挂载点:/,文件系统类型:xfs,使用磁盘上全部未使用空间
Below is a screenshot of the four partitions I created, for reference only. (You can create any partition you want, the following are the four commonly used partitions)
网络配置:
添加网络设备“ens33”
网络类型设为“DHCP”
防火墙配置:
禁用 SELinux、禁用防火墙
安装后脚本:
勾选“使用解释程序”:/bin/bash
rm -rf /etc/yum.repos.d/*
echo '[local]
name=local
baseurl=ftp://192.168.163.5/centos7
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
其它选项保持默认设置即可
4. Save the automatic response file
选择“Kickstart 配置程序”窗口的“文件”-->“保存”命令,选择指定保存位置,文件名为ks.cfg
默认保存在/root/ks.cfg
cp /root/ks.cfg /var/ftp/ks.cfg
5. Configure the software packages to be installed
可以根据需要将/root/anaconda-ks.cfg 的软件包安装脚本复制到 /var/ftp/ks.cfg文件中,只需要复制%packages 到%end 部分即可。
如要求最小化安装,可复制下面内容:
vim /var/ftp/ks.cfg
%packages
@^minimal
%end
Edit the ks.cfg file in the ftp directory
6. Edit the boot menu file default and add ks boot parameters
vim /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 0 #设置是否等待用户选择,“0”表示不等待用户控制
label auto
kernel vmlinuz #kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.163.5/centos7 ks=ftp://192.168.163.5/ks.cfg
#添加 ks 引导参数以指定 ks.cfg 应答文件的 URL 路径
7. Verify unattended installation
When the client computer boots in PXE mode each time, it will automatically download the ks.cfg response configuration file, and then install the CentOS 7 system according to the settings in it, without manual intervention.
cat /etc/yum.repos.d/local.repo
Complete installation