Explain the deployment process of PXE server in Linux system

Time:2020-11-21

In large-scale server installation, batch automation method is needed to reduce the daily workload
But the foundation of batch automatic installation server is bootserver
Next, we will introduce the installation and configuration method of network startup server, for your practice!
1. Explanation of terms used in this paper
PXE
PXE (pre boot execution environment) is a protocol designed by Intel. It can make the computer boot through the network rather than from the local hard disk, optical drive and other devices. Modern network card, generally embedded support PXE ROM chip. When the computer is booted, the BIOS calls PXE client into memory for execution, and displays the command menu. After the user selects, PXE client will download the remote operating system to run locally through the network
DHCP
DHCP (Dynamic Host Control Protocol) is used to assign IP address to clients in a centralized and dynamic way
TFTP
TFTP (trivial file transfer protocol), a very small overhead file transfer protocol, has a syntax similar to FTP. Because of its simplicity and efficiency, it is often used in OS and configuration update of network devices
2. PXE principle
2.1. PXE client API (Architecture)
20151120111318615.gif (600×501)

Figure PXE API architecture. (source: PXE specification version 2.1)
The above figure shows that when the BIOS loads PXE client into memory, it has the capabilities of DHCP client and TFTP client.
PXE client has the capability of DHCP client and can obtain IP address through DHCP server.
PXE client has the ability of TFTP client “, and can download kernel image and other files through TFTP.
2.2. PXE boot flow chart (PXE boot)
20151120111347530.png (750×343)

The start-up process in the above figure is described as follows:
PXE client broadcasts dhcpddiscover message to UDP 67 port
After receiving broadcast message, DHCP server or DHCP proxy sends dhcpoffer (including IP address) message to port 68 of PXE client
PXE client sends dhcprequest message to DHCP server to get boot file name
DHCP server sends dhcpack (including network bootstrap program file name) message to PXE client
PXE client obtains NBP (network bootstrap program) file from boot server
PXE client downloads NBP from TFTP server and executes NBP file on client
Note: after NBP initialization, NBP will download other required configuration files from TFTP server by default
At this time, PXE boot process has been completed, the rest of the work is performed by NBP
For example, pxelinux.0 (NBP) will download the default configuration file to display the menu and start different kernel images as required
If it is NBP of RIS (window installation), windows boot loader will be started to perform the task of installing and deploying windows
3. PXE boot server configuration process
The following configuration and test are completed on centos5. Please refer to other systems as appropriate!
3.1. Installation and configuration of DHCP
In the process of PXE booting, PXE client obtains IP address and NBP file name through DHCP server, then downloads NBP file from TFTP server and executes it in client, thus starting the computer.
Please confirm that the DHCP package is installed in the system
Edit / etc/ dhcpd.conf Configuration file, the content of which is as follows

Copy code

The code is as follows:

[[email protected]]# cat /etc/dhcpd.conf
ddns-update-style interim;
Allow booting; ා defines the PXE boot capability
Allow BOOTP; ා defines the support for BOOTP
Next server 192.168.0.1; IP address of TFTP server
File name “pxelinux. 0”; Bootstrap file (NBP)

default-lease-time 1800;
max-lease-time 7200;
ping-check true;
option domain-name-servers 192.168.0.1;

subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.128 192.168.0.220;
option routers 192.168.0.1;
option broadcast-address 192.168.0.255;
}

Note: in / etc/ dhcpd.conf In the configuration file, the file name is “pxelinux. 0”; the file directory is the root directory relative to TFTP (the default is / tftpboot),
Therefore, the absolute path of the file is / tftpboot / pxelinux. 0 “; you can also specify other paths
After configuration, restart the DHCP service and set it to boot

Copy code

The code is as follows:

[[email protected]]# /etc/init.d/dhcpd start
[dhcpd: [OK]
[[email protected]]# chkconfig –level 35 dhcpd on

3.2. Install and configure TFTP server
In the process of PXE boot, PXE client uses TFTP protocol to download bootstrap file from TFTP server and execute
Please confirm that TFTP server package is installed in the system
Configure the TFTP service, which is managed by xinetd service
Edit the / etc / xinetd.d/tftp file and change disable = yes to disable = No. the contents of the configuration file are as follows:

Copy code

The code is as follows:

[[email protected]]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
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
}

Note: the root directory of TFTP server is / tftpboot. Restart xinetd service after configuration to make TFTP server effective

Copy code

The code is as follows:

[[email protected]]# /etc/init.d/xinetd restart

Bootstrap file configuration (NBP), where pxelinux. 0 is used
The bootstrap file is provided by the syslinux package. As long as syslinux is installed, copy the pxelinux.0 file to the / tftpboot directory

Copy code

The code is as follows:

[[email protected]]# rpm -ql syslinux | grep “pxelinux.0”
/usr/lib/syslinux/pxelinux.0
[[email protected]]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/

Configure the configuration file used by pxelinux. 0 (NBP)
Next, create / tftpboot/ pxelinux.cfg/ Directory, which is used to store the configuration files of the client

Copy code

The code is as follows:

[[email protected]]# mkdir /tftpboot/pxelinux.cfg

The default configuration file is default. The contents of the file are as follows

Copy code

The code is as follows:

[[email protected]]# cat /tftpboot/pxelinux.cfg/default

Default Linux ා the boot kernel marked in ‘label Linux’ is started by default
Prompt 1 ා displays the ‘boot:’ prompt
Timeout 60 ා waiting time-out, unit: 1 / 10 second. After timeout, the default specified label will be started automatically
display boot.msg #Display boot.msg The file path is the root directory of the relative TFTP server (default / tftpboot) boot.msg The absolute path of the file is in / tftpboot/ boot.msg .
F1 boot.msg #Documents displayed after pressing the ‘F1’ key
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg

Label 1 #’label ‘specifies the keyword you enter at the’ boot: ‘prompt.
kernel linux/rh44-x86-32/vmlinuz
append initrd=linux/rh44-x86-32/initrd.img ramdisk_size=8192 ks=http://install.test.com/conf/ks_module.cfg ksdevice=link

label 2
kernel linux/rh44-x86-64/vmlinuz
append initrd=linux/rh44-x86-64/initrd.img ramdisk_size=8192 ks=http://install.test.com/conf/ks_module.cfg ksdevice=link

label 3
kernel linux/rh46-x86-64/vmlinuz
append initrd=linux/rh46-x86-64/initrd.img ramdisk_size=8192 ks=http://install.test.com/conf/ks_module.cfg ksdevice=link

label 4
kernel linux/rh46-x86-32/vmlinuz
append initrd=linux/rh46-x86-32/initrd.img ramdisk_size=8192 ks=http://install.test.com/conf/ks_module.cfg ksdevice=link

label 5
kernel image/linux/rh38-x86-32/vmlinuz
append initrd=image/linux/rh38-x86-32/initrd.img ramdisk_size=8192 ks=http://install.test.com/conf/ks_module.cfg ksdevice=link

label 6
kernel linux/rh38-x86-64/vmlinuz
append initrd=linux/rh38-x86-64/initrd.img ramdisk_size=8192 ks=http://install.test.com/conf/ks_module.cfg ksdevice=link

Note: the default pxelinux.0 and pxelinux.cfg It must be in the same directory
3.3. Pxelinx. 0 (NBP) program configuration file search order
Since multiple clients can boot from a single PXE server, the PXE boot image uses a complex profile search method to find the configuration file for the client
Assuming that the MAC address of the network card of the client server is 88:99: AA: BB: CC: DD, and the corresponding IP address is 192.168.1.195, the search order of pxelinux.0 program of the client is as follows:
First, MAC address as the file name matching configuration file, if it does not exist, continue to search
Secondly, the IP address is used to search. According to the configuration file named in hexadecimal of IP address, search is divided from small range to large scale (subnet mask from small to large). If it does not exist, continue to search
Finally, try the default file
In general, the order of files searched by pxelinux.0 is (results can be obtained through tcpdum): –

Copy code

The code is as follows:

/tftpboot/pxelinux.cfg/01-88-99-aa-bb-cc-dd
/tftpboot/pxelinux.cfg/C0A801C3
/tftpboot/pxelinux.cfg/C0A801C
/tftpboot/pxelinux.cfg/C0A801
/tftpboot/pxelinux.cfg/C0A80
/tftpboot/pxelinux.cfg/C0A8
/tftpboot/pxelinux.cfg/C0A
/tftpboot/pxelinux.cfg/C0
/tftpboot/pxelinux.cfg/C
/tftpboot/pxelinux.cfg/default

4. Summary
20151120111412229.png (642×159)