PXE automatic installation, huh? The original installation does not need to do it yourself

1, PXE overview

In the PXE / server operating environment, the client can download files from the company's operating system and boot them from the network through the PXE / server

2, Advantages of PXE batch deployment

1. Scale: assemble multiple servers at the same time
2. Automation: install the system and configure various services
3. Remote implementation: no installation media such as optical disk and U SB flash disk are required

3, Requirements for building PXE network system

1. The Network card of the client should support PXE protocol (integrated BOOTROM chip), and the motherboard supports Network boot. Generally, most servers support it. You only need to allow booting from Network or LAN in BIOS settings.

2. There is a DHCP server in the network to automatically assign addresses and specify boot file locations for clients.

3. The server shall provide the download of boot image file through TFTP service (simple file transfer protocol).

4, Set up PXE remote installation server

PXE remote installation server integrates CentOS7 installation source, TFTP service and DHCP service, and can send PXE boot program, Linux kernel, Startup menu and other data to the client bare metal, as well as provide installation files.

1. Install and start TFTP service

TFTP (simple file transfer protocol) is a protocol based on UDP protocol for simple file transfer between client and server. It is suitable for small file transfer applications. TFTP service is managed by xinetd service by default and uses UDP port 69

xinetd is a new generation of network daemon service program, also known as super server, which is often used to manage a variety of lightweight Internet services.

yum -y install tftp-server xinetd            #Install and enable TFTP service
vim /etc/xinetd.d/tftp                       #Modify the configuration file of TFTP service
protocol            = udp		             #TFTP uses UDP protocol by default	
wait                = no		             #no means that multiple clients can be connected together, and yes means that only one client can be connected
server_args         = -s /var/lib/tftpboot	 #Specify TFTP root directory (storage path of boot file)
disable             = no		             #no indicates that the TFTP service is enabled

systemctl start tftp # starts ftp service
systemctl enable tftp # enables the ftp service to start automatically
systemctl start xinetd # start xinetd service
systemctl enable xinetd # enable xinetd service


2. Install and enable DHCP service

DHCP (Dynamic Host Configuration Protocol) is a network protocol of local area network, which works with UDP protocol.

yum -y install dhcp                                 #Install dhcp package
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
                                                    #Copy the dhcp configuration template to the dhcp configuration file
vim /etc/dhcp/dhcpd.conf    						#Modify the configuration file of DHCP service
ddns-update-style none;					         	#Disable DNS dynamic updates
next-server 192.168.184.10; 					    #Specifies the address of the TFTP server
filename "pxelinux.0";						        #Specifies the file of the PXE bootstrapper to download

subnet 192.168.184.0 netmask 255.255.255.0 {# declares the network segment address to be assigned
range 192.168.184.100 192.168.184.200; # Set address pool
option routers 192.168.184.10; # The default gateway address points to the IP address of the TFTP server
}

Systemctl start dhcp PD # starts the dhcp service
systemctl enable dhcpd # enables the dhcp service 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/				#Copy the kernel file of Linux system to the TFTP root directory
cp initrd.img /var/lib/tftpboot/     		#Copy the initialization image file (linux boot load module) to the TFTP root directory

4. Prepare PXE boot program

yum -y install syslinux									#The PXE bootstrap is provided by the software package syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/	#Copy the PXE bootstrap to the TFTP root directory


5. Install FTP service and prepare CentOS 7 installation source

yum -y install vsftpd               #Install vsftpd service
mkdir /var/ftp/centos7              #Create the directory centos7 under the ftp root directory
cp -rf /mnt/* /var/ftp/centos7/     #Forcibly copy the image file to the centos7 directory. You can add & to make it run in the background
systemctl start vsftpd              #Open vsftpd service
systemctl enable vsftpd             #Start the vsftpd service and start it automatically

6. Configure Startup menu file

The default Startup menu file is pxelinux.exe in the TFTP root directory CFG subdirectory, the file name is default

mkdir /var/lib/tftpboot/pxelinux.cfg		  
vim /var/lib/tftpboot/pxelinux.cfg/default	

default auto # specifies the default entry name
prompt 1 # sets whether to wait for user selection. "1" means to wait for user control

label auto # graphic installation (default) boot entry. label is used to define startup items
kernel vmlinuz #kernel and append are used to define boot parameters
append initrd=initrd.img method=ftp://192.168.184.10/centos7

label linux text # text installation boot entry
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.184.10/centos7

label linux rescue # rescue mode boot entry
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.184.10/centos7

systemctl stop firewalld.service # close the system firewall
Setenforce0 # turns off system security


Note: use the virtual machine created by VMware for testing. The memory of the virtual machine needs at least 2GB, otherwise an error may be reported when starting the installation.

Start the virtual machine, press Enter directly after the prompt string "boot:" (or execute the "auto" command), the installation file will be automatically downloaded through the network and Enter the default graphic installation portal;
If the "linux text" command is executed, enter the text installation entry; If you execute the "linux rescue" command, you will enter the rescue mode.

5, Implement Kickstart unattended installation (using desktop environment)

1. Prepare to install answer file

yum install -y system-config-kickstart       #Install the system config kickstart tool

2. Opens the Kickstart configurator window

"Applications" from the Desktop Menu-->""System tools"-->"Kickstart" open
 or
 Execute“ system-config-kickstart" Command open


Or directly execute the "system config kickstart" command to open it

3. Configure kickstart options

● basic configuration

The default language is set to "Chinese (Simplified)"
Set time zone to“ Asia/Shanghai"
set up root password
 Check "restart after installation" in advanced configuration.

● installation method

choose FTP
FTP The server: ftp://192.168.80.10
FTP catalog: centos7

● boot loader options

"Installation type ": install a new boot loader
"Installation options ": in the master boot record( MBR)Install boot loader in

● zoning information

Master boot record: clear master boot record
 Partition: delete all existing partitions
 Disk label: initialize disk label
 Layouts: adding zones
 Mount point:/boot,File system type: xfs,Fixed size: 500 M
 File system type: swap,Fixed size: 4096 M
 Mount point:/home,File system type: xfs,Fixed size: 4096 M
 Mount point:/,File system type: xfs,Use all unused space on disk


Note: the allocation size of each partition depends on its own discretion. The swap partition belongs to the file system type, and others can be found in the mount point

●Network configuration:
Add network device“ ens33"
Set the network type to“ DHCP"

●Firewall configuration:
Disable SELinux,Disable firewall

●Post installation script:
Check "use interpreter":/bin/bash
rm -rf /etc/yum.repos.d/*
echo '[local]
name=local
baseurl=ftp://192.168.80.10/centos7
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo

Other options can be set by default

 
  • 1

4. Save auto answer file

Choose“ Kickstart Profiles in the configurator window-->"Save command, select and specify the save location, and the file name is ks.cfg
 Default saved in/root/ks.cfg

 
  • 1
  • 2


5. Configure the packages that need to be installed

You can change it as needed/root/anaconda-ks.cfg Copy the package installation script to ks.cfg In the file, you only need to copy%packages reach%end Part is enough.

To minimize installation, copy the following:
vim ks.cfg
%packages
@^minimal
%end



cp /root/ks.cfg /var/ftp/ks.cfg

 
  • 1

Set / root / Anaconda KS Copy the package installation script of CFG to / var / ftp / ks CFG for desktop installation


Pay attention to the sequence. Boot boot reads the contents in / var/ftp, not / root, which is only the other party temporarily saved. Therefore, copy it after modification, or directly copy it before modification.

6. Edit the boot menu file default and add ks boot parameters

vim /var/lib/tftpboot/pxelinux.cfg/default	
default auto 							
prompt 0 								#Set whether to wait for user selection. "0" means not to wait for user control

label auto
kernel vmlinuz #kernel and append are used to define boot parameters
append initrd=initrd. img method= ftp://192.168.80.10/centos7 ks= ftp://192.168.80.10/ks.cfg #Add KS boot parameter to specify KS CFG URL path of response file


Each time the client boots in PXE mode, it will automatically download KS CFG answer the configuration file, and then install the CentOS 7 system according to its settings without manual intervention.

7. Create new virtual machine validation
























Added by goltoof on Thu, 17 Feb 2022 19:08:15 +0200