1. What is PXE?
pxe is an acronym for Preboot Excution Environment, is the intel research and development, network-based model client / server, support for remote host download mirror over the network from a remote server, and thus supports Pre-Boot Execution Environment boot through the network operating system.
2, PXE works
Its workflow is this:
1, the client sends a DHCP on the PXE server ip address request message, DHCP detects that the client is legitimate (mainly detecting the client's MAC address) if valid client return side ip address while the startup file pxelinx.0 position information together to the client;
2, the client IP address and get the boot file storage server (tftp server) address, it will send a message acquiring request to the server tftp pxelinux.0 after tftp server receives the message, the client sends again pxelinux. 0 file size, to test whether the client satisfaction, when receiving the consent of the size of the tftp client information sent back after, tftp server pxelinux.0 officially send files to clients;
3, the client receives tftp sent from pxelinux.0 file, the client will again send tftp server configuration information file for the machine (in pxelinux.cfg TFTP server directory), TFTP server configuration file will be sent to after the client, then the client performs a subsequent operation according to the configuration file;
4, the client sends a request message to the Linux kernel TFTP server, tftp kernel file after receiving the message sent to the client, the client receives the file kernel, also the transmission tftp obtain information requested root file, when the server receives tftp after the root file request message, put the root file to the client;
5, after this time the client files with the Linux kernel and root file, the client try to start the Linux kernel;
6, download and install the client source file, read the automated installation script (ks.cfg)
From the above we can know the process, we first need to configure the DHCP server, TFTP server, and then prepare the necessary startup files and configuration files, and automated installation scripts.
Set up a DHCP server, and configure
[root@localhost ~]# yum install dhcp Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:4.1.1-63.P1.el6.centos will be installed --> Processing Dependency: dhcp-common = 12:4.1.1-63.P1.el6.centos for package: 12:dhcp-4.1.1-63.P1.el6.centos.x86_64 --> Running transaction check ---> Package dhcp-common.x86_64 12:4.1.1-53.P1.el6.centos will be updated --> Processing Dependency: dhcp-common = 12:4.1.1-53.P1.el6.centos for package: 12:dhclient-4.1.1-53.P1.el6.centos.x86_64 ---> Package dhcp-common.x86_64 12:4.1.1-63.P1.el6.centos will be an update --> Running transaction check ---> Package dhclient.x86_64 12:4.1.1-53.P1.el6.centos will be updated ---> Package dhclient.x86_64 12:4.1.1-63.P1.el6.centos will be an update --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: dhcp x86_64 12:4.1.1-63.P1.el6.centos updates 824 k Updating for dependencies: dhclient x86_64 12:4.1.1-63.P1.el6.centos updates 323 k dhcp-common x86_64 12:4.1.1-63.P1.el6.centos updates 145 k Transaction Summary ================================================================================ Install 1 Package(s) Upgrade 2 Package(s) Total download size: 1.3 M Is this ok [y/N]: y Downloading Packages: (1/3): dhclient-4.1.1-63.P1.el6.centos.x86_64.rpm | 323 kB 00:00 (2/3): dhcp-4.1.1-63.P1.el6.centos.x86_64.rpm | 824 kB 00:00 (3/3): dhcp-common-4.1.1-63.P1.el6.centos.x86_64.rpm | 145 kB 00:00 -------------------------------------------------------------------------------- Total 2.0 MB/s | 1.3 MB 00:00 warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Importing GPG key 0xC105B9DE: Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <[email protected]> Package: centos-release-6-9.el6.12.3.x86_64 (@anaconda-CentOS-201703281317.x86_64/6.9) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Updating : 12:dhcp-common-4.1.1-63.P1.el6.centos.x86_64 1/5 Installing : 12:dhcp-4.1.1-63.P1.el6.centos.x86_64 2/5 Updating : 12:dhclient-4.1.1-63.P1.el6.centos.x86_64 3/5 Cleanup : 12:dhclient-4.1.1-53.P1.el6.centos.x86_64 4/5 Cleanup : 12:dhcp-common-4.1.1-53.P1.el6.centos.x86_64 5/5 Verifying : 12:dhcp-common-4.1.1-63.P1.el6.centos.x86_64 1/5 Verifying : 12:dhcp-4.1.1-63.P1.el6.centos.x86_64 2/5 Verifying : 12:dhclient-4.1.1-63.P1.el6.centos.x86_64 3/5 Verifying : 12:dhcp-common-4.1.1-53.P1.el6.centos.x86_64 4/5 Verifying : 12:dhclient-4.1.1-53.P1.el6.centos.x86_64 5/5 Installed: dhcp.x86_64 12:4.1.1-63.P1.el6.centos Dependency Updated: dhclient.x86_64 12:4.1.1-63.P1.el6.centos dhcp-common.x86_64 12:4.1.1-63.P1.el6.centos Complete!
Description: dhcp dhcp realization of software and software dnsmasq two, our use of DHCP, DHCP server after installation package yum, let's write a configuration file
[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf cp: overwrite `/etc/dhcp/dhcpd.conf'? y
Description: We are open /etc/dhcp/dhcpd.conf, the contents of which are annotated, it tells us /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample reference file to configure the reason that we just put copy the template files to the / etc / dhcp / down and named dhcpd.conf, can be modified in the next
# DHCP server to understand the network topology. subnet 172.16.56.0 netmask 255.255.255.0 { range 172.16.56.100 172.16.56.200; option routers 172.16.56.5; option domain-name-servers 172.16.56.5; filename "pxelinux.0"; next-server 172.16.56.5; }
Description: We are in the configuration file to configure a good address pool dhcp assigned (this address pool and the host must be on the same network segment), gateway, dns, etc., but also the most important address of the TFTP server configuration, and guidance system file name pxelinux.0, so that clients will be able to know that the files on the server's address and tftp tftp is the boot file. range followed by the address pool range, option routers specifies the gateway, option domain-name-servers designated dns address, filename to specify the name of the boot file start, next-server directive designates the TFTP server address. It should be noted that the end of each line needs to have a semicolon. Of course, we can use the service dhcpd configtest to test whether our configuration file syntax errors.
Then we configure the DHCP server, you can start the DHCP service
[root@localhost ~]# /etc/init.d/dhcpd start Starting dhcpd: [ OK ] [root@localhost ~]# ss -uln State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:67 *:* UNCONN 0 0 *:68 *:* UNCONN 0 0 127.0.0.1:737 *:* UNCONN 0 0 *:55660 *:* UNCONN 0 0 *:111 *:* UNCONN 0 0 *:631 *:* UNCONN 0 0 *:679 *:* UNCONN 0 0 :::111 :::* UNCONN 0 0 :::49813 :::* UNCONN 0 0 :::679 :::* [root@localhost ~]#
Description: We can see 67, 68 udp port has been up to explain our DHCP server is started normally.
DHCP service test is normal, whether the client is able to successfully get the address and the other to take a host on the same LAN, come and collect the addresses above dhclient tool
[root@host_A ~]# dhclient -d Internet Systems Consortium DHCP Client 4.1.1-P1 Copyright 2004-2010 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/eth0/00:0c:29:47:f6:ed Sending on LPF/eth0/00:0c:29:47:f6:ed Sending on Socket/fallback DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x758b581e) DHCPACK from 172.16.56.5 (xid=0x758b581e) bound to 172.16.56.100 -- renewal in 282 seconds.
Description: We can see that the client has got the address, of course, we can also see those addresses are assigned out, who is assigned to the server, the lease is for a long time and other information.
[root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases # The format of this file is documented in the dhcpd.leases(5) manual page. # This lease file was written by isc-dhcp-4.1.1-P1 server-duid "\000\001\000\001%Q\205x\000\014)\350\366{"; lease 172.16.56.100 { starts 0 2019/11/03 12:34:19; ends 0 2019/11/03 12:44:19; cltt 0 2019/11/03 12:34:19; binding state active; next binding state free; hardware ethernet 00:0c:29:47:f6:ed; } [root@localhost ~]#
Note: the recorded address allocation server out, a MAC client information such /var/lib/dhcpd/dhcpd.leases lease to the DHCP server. There we set up a DHCP server is complete.
Then we have to build tftp server.
[root@localhost yum.repos.d]# yum install -y tftp Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package tftp.x86_64 0:0.49-8.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================= Package Arch Version Repository Size ======================================================================================= Installing: tftp x86_64 0.49-8.el6 mybase 32 k Transaction Summary ======================================================================================= Install 1 Package(s) Total download size: 32 k Installed size: 45 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : tftp-0.49-8.el6.x86_64 1/1 Verifying : tftp-0.49-8.el6.x86_64 1/1 Installed: tftp.x86_64 0:0.49-8.el6 Complete! [root@localhost yum.repos.d]# yum install -y tftp-server Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package tftp-server.x86_64 0:0.49-8.el6 will be installed --> Processing Dependency: xinetd for package: tftp-server-0.49-8.el6.x86_64 --> Running transaction check ---> Package xinetd.x86_64 2:2.3.14-40.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================= Package Arch Version Repository Size ======================================================================================= Installing: tftp-server x86_64 0.49-8.el6 mybase 39 k Installing for dependencies: xinetd x86_64 2:2.3.14-40.el6 mybase 122 k Transaction Summary ======================================================================================= Install 2 Package(s) Total download size: 161 k Installed size: 317 k Downloading Packages: --------------------------------------------------------------------------------------- Total 6.0 MB/s | 161 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : 2:xinetd-2.3.14-40.el6.x86_64 1/2 Installing : tftp-server-0.49-8.el6.x86_64 2/2 Verifying : 2:xinetd-2.3.14-40.el6.x86_64 1/2 Verifying : tftp-server-0.49-8.el6.x86_64 2/2 Installed: tftp-server.x86_64 0:0.49-8.el6 Dependency Installed: xinetd.x86_64 2:2.3.14-40.el6 Complete! [root@localhost yum.repos.d]#
Description: TFTP server will only need to install tftp-server package on it, tftp this package is a client tool to facilitate testing. We installed the TFTP can use rpm -ql tftp-server command to view this package in the end what files are installed, installed in any place to go
[root@localhost yum.repos.d]# rpm -ql tftp-server /etc/xinetd.d/tftp /usr/sbin/in.tftpd /usr/share/doc/tftp-server-0.49 /usr/share/doc/tftp-server-0.49/CHANGES /usr/share/doc/tftp-server-0.49/README /usr/share/doc/tftp-server-0.49/README.security /usr/share/doc/tftp-server-0.49/README.security.tftpboot /usr/share/man/man8/in.tftpd.8.gz /usr/share/man/man8/tftpd.8.gz /var/lib/tftpboot [root@localhost yum.repos.d]#
Description: /etc/xined.d/tftp This is tftp configuration file because daemon tftp not independent, it is transient daemon, xinetd super daemon management, so in its configuration file in the directory xinetd.d; /usr/sbin/in.tftpd this file is the main program tftp binary; / var / lib / tftpboot the tftp directory is the working directory of the server, we upload and download files are placed in this directory
Start tftp server
[root@localhost ~]# chkconfig tftp on [root@localhost ~]# chkconfig --list tftp tftp on [root@localhost ~]# /etc/init.d/xinetd restart Stopping xinetd: [FAILED] Starting xinetd: [ OK ] [root@localhost ~]# ss -nul State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:67 *:* UNCONN 0 0 *:69 *:* UNCONN 0 0 127.0.0.1:737 *:* UNCONN 0 0 *:55660 *:* UNCONN 0 0 *:111 *:* UNCONN 0 0 *:631 *:* UNCONN 0 0 *:679 *:* UNCONN 0 0 :::111 :::* UNCONN 0 0 :::49813 :::* UNCONN 0 0 :::679 :::* [root@localhost ~]#
Description: TFTP default port udp work at 69, you can see the port number 69 has been started.
Test: We put some files on the TFTP server, see if I can download it, if you can, this will build our tftp server there is no problem
[root@localhost tmp]# echo "this is test file" >> f1 [root@localhost tmp]# ls f1 [root@localhost tmp]# cp f1 /var/lib/tftpboot/ [root@localhost tmp]# ll /var/lib/tftpboot/ total 8 -rw-------. 1 root root 1591 Nov 3 21:06 anaconda-ks.cfg -rw-r--r--. 1 root root 18 Nov 3 21:09 f1 [root@localhost tmp]# cd [root@localhost ~]# ls anaconda-ks.cfg Documents install.log Music Public Videos Desktop Downloads install.log.syslog Pictures Templates [root@localhost ~]# tftp 172.16.56.5 tftp> get f1 tftp> q [root@localhost ~]# ls anaconda-ks.cfg Documents f1 install.log.syslog Pictures Templates Desktop Downloads install.log Music Public Videos [root@localhost ~]# cat f1 this is test file [root@localhost ~]#
Description: We set up a TFTP server is able to download files, bringing TFTP server set up is completed.
Next we need to build a yum repository HTTP-based network
[root@localhost yum.repos.d]# yum install httpd -y Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Package httpd-2.2.15-59.el6.centos.x86_64 already installed and latest version Nothing to do [root@localhost yum.repos.d]# /etc/init.d/httpd start Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName [ OK ] [root@localhost yum.repos.d]# cd /var/www/html/ [root@localhost html]# ls [root@localhost html]# mkdir centos/6/os/x86_64 -pv mkdir: created directory `centos' mkdir: created directory `centos/6' mkdir: created directory `centos/6/os' mkdir: created directory `centos/6/os/x86_64' [root@localhost html]# mount /dev/sr0 /var/www/html/centos/6/os/x86_64/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost html]# ls centos/6/os/x86_64/ CentOS_BuildTag isolinux RPM-GPG-KEY-CentOS-Debug-6 EFI Packages RPM-GPG-KEY-CentOS-Security-6 EULA RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Testing-6 GPL repodata TRANS.TBL images RPM-GPG-KEY-CentOS-6 [root@localhost html]#
Description: yum build a warehouse refer to https://www.cnblogs.com/qiuhom-1874/p/11487456.html here is not too much to explain
system-config-kickstart graphical tool to create an answer file ks.cfg kickstart
1, install system-config-kickstart
[root@localhost ~]# yum install -y system-config-kickstart
2, a terminal open graphical input system-config-kickstart promoter system-config-kickstart Editor
Note: The figure is set to the language, keyboard layout, time zone, the basic configuration page, which you can specify the system, root password, mounting platform, whether to restart after installation, installed in what mode.
Description: The figure is a configuration of the mounting method, the system may be configured to update or newly installed, the installation source, our position is mirrored storage.
Note: The figure is bootloader configuration options, you can configure the bootloader on this page the type of installation, grub password, boot loader is installed in that position, you can also write kernel parameters.
Note: The figure is the partition configuration information in this page can be configured to remove the original MBR, whether to clear the existing partition information, whether to initialize the disk label, as well as partitioning strategy, and raid configuration
Note: This page is the network configuration page
Note: This page is to configure authentication methods, in general we should not its default configuration, which is the default configuration local authentication, which is used to verify the / etc / passwd file contents, of course, can also be configured according to their actual situation you can support ldap, nis-peer authentication
Note: This page is a firewall and selinux configuration page
Note: This page is a display configuration, you can configure whether to install a graphical environment, whether initialized first start
Description: The package of the above page select the configuration page, we need to pretend to pack it in there like a checkmark
Note: This page is pre-installation script we wrote, we hope that before the system installation needs to do something it can tell by the way the script
Note: This page is a custom installation script contents needs to run, as we wrote a yum repository configuration, you will have this automatic warehouse system configuration after installation
After configuring the above we find the file button, and then click inside the save, and then select a location, you can put before us the option to generate a file kictstart
[root@localhost Desktop]# cat ks.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade install # Use network installation url --url="http://172.16.56.5/centos/6/os/x86_64" # Root password rootpw --plaintext admin # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone Africa/Abidjan # Network information network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration bootloader --location=mbr --password="admin" # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /home --fstype="ext4" --size=10240 part swap --fstype="swap" --size=2048 part / --fstype="ext4" --size=40960 part /data --fstype="ext4" --size=20480 part /boot --fstype="ext4" --size=500 %post mkdir /etc/yum.repo.d/bak_repo mv *.repo /etc/yum.repo.d/bak_repo cat > /etc/yum.repo.d/myrepo.repo<< EOF [mybase] name=mybase baseurl=http://172.16.56.5/centos/6/os/x86_64 gpgcheck=0 EOF %end %packages @base %end
At this point we use system-config-kickstart tools to make good our answer file.
Ready to start the relevant documents
[root@localhost tftpboot]# yum install -y syslinux Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package syslinux.x86_64 0:4.04-3.el6 will be installed --> Processing Dependency: syslinux-nonlinux for package: syslinux-4.04-3.el6.x86_64 --> Running transaction check ---> Package syslinux-nonlinux.noarch 0:4.04-3.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================= Package Arch Version Repository Size ======================================================================================= Installing: syslinux x86_64 4.04-3.el6 mybase 346 k Installing for dependencies: syslinux-nonlinux noarch 4.04-3.el6 mybase 584 k Transaction Summary ======================================================================================= Install 2 Package(s) Total download size: 929 k Installed size: 2.2 M Downloading Packages: --------------------------------------------------------------------------------------- Total 26 MB/s | 929 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : syslinux-nonlinux-4.04-3.el6.noarch 1/2 Installing : syslinux-4.04-3.el6.x86_64 2/2 Verifying : syslinux-4.04-3.el6.x86_64 1/2 Verifying : syslinux-nonlinux-4.04-3.el6.noarch 2/2 Installed: syslinux.x86_64 0:4.04-3.el6 Dependency Installed: syslinux-nonlinux.noarch 0:4.04-3.el6 Complete! [root@localhost tftpboot]# find / -name pxelinux.0 /usr/share/syslinux/pxelinux.0 [root@localhost tftpboot]#
Description: Our aim is to install this package syslinux this package has the file pxelinux.0
[root@localhost tftpboot]# mkdir /var/lib/tftpboot/pxelinux.cfg [root@localhost tftpboot]# pwd /var/lib/tftpboot [root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 . [root@localhost tftpboot]# cp /misc/cd/images/pxeboot/{vmlinuz,initrd.img} . [root@localhost tftpboot]# cp /misc/cd/isolinux/{boot.msg,vesamenu.c32,splash.jpg} . [root@localhost tftpboot]# tree . ├── boot.msg ├── initrd.img ├── pxelinux.0 ├── pxelinux.cfg ├── splash.jpg ├── vesamenu.c32 └── vmlinuz 1 directory, 6 files [root@localhost tftpboot]#
Description: We need vmlinuz (kernel file compression), initrd.img (root file storage system needs to start to mount the drive), pxelinux.0 (boot file system, acts like a bootloader), boot.msg, vesamenu.c32, splash.jpg (this image is to choose how to install the background image behind when we installed the system)
Ready to start the menu file
[root@localhost tftpboot]# cp /misc/cd/isolinux/isolinux.cfg pxelinux.cfg/default [root@localhost tftpboot]# cat pxelinux.cfg/default default vesamenu.c32 #prompt 1 timeout 60 display boot.msg menu background splash.jpg menu title Welcome to CentOS 6.9! 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 auto menu label ^Auto install an system menu default kernel vmlinuz append initrd=initrd.img ks=http://172.16.56.5/centos/6/ks/centos6.cfg label local menu label Boot from ^local drive localboot 0xffff [root@localhost tftpboot]#
Description: Start menu isolinux.cfg there is a document which defines the startup menu in the content directory ioslinux disc, and ks automatic installation location of the script.
test
Create a new virtual machine, and the network pxe server settings in the same local area network, and then turn on the power
Description: When you start a virtual machine, looking for a DHCP server
Description: find a DHCP server, before we display a customized menu
Description: load vmlinuz and initrd.img files
Description: We choose to automatically install the package needs to be filled
Description: The system automatically installed, the automatic restart, log into the system interface. So far pxe automatically install the system environment we set up is completed.