PXE efficient batch network installation and kickstat automatic installation

1, PXE

1. Principle and concept:

The pre boot execution environment (PXE), also known as the pre execution environment, provides a mechanism for starting a computer using a Network Interface. This mechanism allows the computer to start without relying on the local data storage device (hard disk) or the locally installed operating system.

Server: run DHCP service, which is used to allocate address and locate boot program

Run TFTP service and provide bootstrap download

Client: the network card supports PXE protocol

The motherboard supports network boot

advantage:

  • Scale: assemble multiple servers at the same time

  • Automation: install the system and configure various services

  • Remote implementation: No CD, U SB flash disk and other installation media are required

2.PXE service process

Working process of PXE server and client:

1.PXE client sends DHCP request and applies for IP address from DHCP server.  
 
2. The DHCP server responds to the request of the PXE client, automatically assigns an IP address from the IP address pool to the PXE client, and informs the PXE client of the IP address of the TFTP server and the PXE boot program file pxelinux 0. It is under the TFTP shared directory / var/lib/tftpboot / by default
 
3.PXE client initiates to obtain pxelinux from TFTP server Request for 0 bootstrap file.
 
4. The TFTP server responds to the PXE client's request to share pxelinux 0 file transfer to PXE client.
 
5.PXE client starts to the main interface of system installation through the network.
 
6.PXE client sends a request to the file sharing server (ftp, http, nfs, etc.) to obtain centos or windows system installation files.
 
7. The file sharing service responds to the request of the PXE client and transfers the shared system installation files to the PXE client.

8. The PXE client enters the installation prompt wizard interface, and the user needs to complete the system installation manually.

3. Configuration

prerequisite:
● the network card of the client supports PXE protocol (integrated BOOTROM chip), and the motherboard supports network boot.
● there is a DHCP server in the network to automatically assign addresses and specify boot file locations for clients.
● the server provides the download of boot image files through TFTP (simple file transfer protocol).

1)One function of configuring dual network cards is dhcp,One is to use the network source to install the environment package
2)DHCP deploy     
3)tftp-server Server pass TFTP(Trivial File Transfer Protocol,Simple file transfer protocol) provides the download of boot image files.
4)syslinux  //Bootstrapper used to provide pxe
5)xinetd  //Used to host tftp
6)vsftpd   //It is used to place the installation image and access the image installation through ftp
7)kickstart //For unattended installation


Deploy one on the server YUM Software warehouse.

[root@localhost ~]# mkdir -p /var/ftp/centos7
[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7
[root@localhost ~]# yum -y install vsftpd
[root@localhost ~]# systemctl start vsftpd
[root@localhost ~]# systemctl enable vsftpd

Install and enable TFTP service
[root@localhost ~]# yum -y install tftp-server
[root@localhost ~]# vi /etc/xinetd.d/tftp
service tftp
{
####Omit some information
protocol = udp                                            ###TFTP adopts UDP transmission protocol
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot             ###Specify TFTP root directory
disable = no
####Omit some information

[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp
prepare Linux Kernel and initialization image file
[root@localhost ~]#   cd /mnt/images/pxeboot/          ####Switch to the mount directory / mntimages/pxeboot/   

[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/  ###Two files and copy them to the root directory of tftp service

prepare PXE Boot program pxelinux.0 By software package syslinux provide
[root@localhost ~]# yum -y install syslinux
[root@localhost pxeboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
Install and enable DHCP service
 because PXE The client is usually a bare metal machine without a system installed. Therefore, in order to contact the server and download the relevant boot files correctly, it needs to be configured in advance DHCP Service to automatically assign the address and inform the boot file location. as PXE Server IP The address is 20.0.0.254, DHCP The address pool is 20.0.0.100~20.0.0.200

[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf
subnet 20.0.0.0 netmask 255.255.255.0 {
option routers 20.0.0.2;		###This is the gateway
option subnet-mask 255.255.255.0;
option domain-name "bdqn.com";
option domain-name-servers 20.0.0.254,202.106.0.20;
default-lease-time 21600;
max-lease-time 43200;
range 20.0.0.100 20.0.0.200;
next-server 20.0.0.21;                    #####Specifies the address of the TFTP server
filename "pxelinux.0";                     ####Specifies the file name of the PXE bootstrap
}
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd
 Added in configuration file netx-server and filename These two lines of records are used to specify TFTP Address and address of the server PXE The file name of the bootstrap.
Configure Startup menu file
 The Startup menu is used to guide the boot process of the client, including how to call the kernel and how to load the initialization image. The default Startup menu file is default,Should be placed in tftp Of the root directory pxelinux.cfg Subdirectory

[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default auto
prompt 1
label auto
	kernel vmlinuz
	append initrd=initrd.img method=ftp://20.0.0.21/centos7
label linux text
	kernel vmlinuz
	append text initrd=initrd.img method=ftp://20.0.0.21/centos7
label linux rescue
	kernel vmlinuz
	append rescue initrd=initrd.img method=ftp://20.0.0.21/centos7
	

Three boot entries are defined in the above configuration record, namely, graphic installation (default), text installation and rescue mode. Among them, prompt Used to set whether to wait for user selection; label Used to define and separate startup items; kernel and append Used to define boot parameters. The number and content of guide entrances are defined according to needs.

Verify PXE network installation
After setting up the PXE remote installation server, you can use the client for installation and testing. For bare metal PC s, no additional settings are generally required;
If you want to reinstall the system for the host of the existing system, you may need to modify the BIOS setting, set "Boot First" to "NETWORK" or "LAN", and then restart the host; If the virtual machine created by VMware is used for testing, the memory of the virtual machine needs at least 2GB, otherwise an error will be reported when starting the installation.
If the server configuration is correct and there are no problems with network connection and PXE support, the client will automatically configure the IP address after restarting, and then obtain the bootstrap pxelinux from the TFTP server 0, and prompt the user to specify the startup entry according to the boot menu configuration,

Press Enter directly after the prompt string "boot:" (or execute the "auto" command) to Enter the default drawing
Installation entrance; If the "linux text" command is executed, enter the text installation entry; If "linux rescue" command is executed
Order, then enter the rescue mode.
Directly press Enter to confirm, the installation file will be automatically downloaded through the network and Enter the graphical installer interface

2, Kickstart unattended installation

Background: with the method of remote installation of CentOS 7 system through PXE technology, the installation medium is no longer limited to CD, mobile hard disk and other devices, which greatly improves the flexibility of system installation. However, a series of interactive operations such as manually selecting language, keyboard type and specifying installation source are still required during installation, which is very inconvenient when batch installation is required.

Configure the installation response file by using Kickstart tool to automatically complete various settings in the installation process, so as to improve the efficiency of network installation without manual intervention.

The installation answer file can be configured through the graphical Wizard tool. If you are familiar with the configuration of the auto answer file, you can also directly edit the answer file automatically created after CentOS7 installation (/ root / Anaconda KS. CFG)

Minimize installation can use the Kickstart configurator by installing the graphical interface through the command

[root@localhost ~]#  yum -y groupinstall 'GNOME Desktop'		###Install graphical interface tools
[root@localhost ~]# systemctl set-default graphical.target		###Graphical interface startup
Install answer file
[root@localhost ~]# yum -y install  system-config-kickstart		###Install kickstart

Configure installation response parameters
 "Applications" from the Desktop Menu→""System tools"→"Kickstart"Can open“ Kickstart match
 Program window. In“ Kickstart In the "configurator" window, you can specify various installation settings such as basic configuration, installation method, boot loader options, partition information, network configuration, etc

Basic configuration:
	Default language: Chinese (P.R. of China)---Chinese (Simplified)
	Keyboard: U.S English
	Time zone: Asia/Shanghai
	Root Password: 123456
	Default password: 123456
	Check√: to root Password encryption
 Advanced configuration:
	Target architecture: X86,AMD64,live IntelEm64T
	Check√: Restart after installation
	Uncheck: execute installation in text mode (graphical mode by default)
	
Installation method:
	Check√: Perform a fresh installation

Installation method:
	Check√: FTP  
	FTP The server: ftp://20.0.0.21
	FTP catalog: centos7
	
Installation type:
	Check√: Install a new boot loader
	
Partition information:
/boot  	 xfs 	yes   	1024
/home  	xfs 	yes 	4096
swap    	swap 	yes 	2048
/	xfs	yes	1

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

Firewall configuration:
Disable SELinux,Disable firewall

Running of post installation script

mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
echo "[local]
name=local
baseurl=ftp://20.0.0.21/centos7
enabled=1
gpgcheck=0" > /etc/yum.repos.d/local.repo

After configuration, save as ks.cfg File, the saved path is/var/ftp lower

Note: the software package installation is disabled by default. If it needs to be enabled, it must be modified yum Source profile, will[]Change the content in to development,Effective immediately
Package selection
 If you need to install the software package, you can install 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, in%packages reach%end Between, including@The software package list at the beginning will delete the unnecessary software name, and the rest is the software package that will be automatically installed by the system

Minimize installation
####
%packages
@^minimal
%end
####

If you need to configure the software package yourself, you need to edit it ks.cfg file
vim ks.cfg
 Add to last

%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@development
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@hardware-monitoring
@input-methods
@internet-browser
@multimedia
@print-client
@x11
chrony

%end




add to ks Boot parameters to boot menu file
vi /var/lib/tftpboot/pxelinux.cfg/default 
default auto 
prompt 0    ##A value of "0" indicates automatic execution of KS Cfg file (unattended) and "1" indicate manual configuration (attended)
label auto 
kernel vmlinuz 
append initrd=initrd.img method=ftp://20.0.0.21/centos7 ks=ftp://20.0.0.21/ks.cfg

yes ks Optimize
vi /var/lib/tftpboot/pxelinux.cfg/default 
default auto
prompt 1

label auto
        kernel vmlinuz
        append initrd=initrd.img method=ftp://20.0.0.21/centos7  ks=ftp://20.0.0.21/ks.cfg

label linux text
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://20.0.0.21/centos7  ks=ftp://20.0.0.21/ks.cfg

label linux rescue
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://20.0.0.21/centos7  ks=ftp://20.0.0.21/ks.cfg

Keywords: network server

Added by Sarok on Sun, 20 Feb 2022 19:02:45 +0200