PXE efficient batch network installation

catalogue

preface

1, PXE overview

2, Advantages of PXE batch deployment

3, Building prerequisites:

4, Kickstart overview

5, Steps to build PXE + KickStart:

    1. Set up PXE remote installation server

      2. Implement Kickstart unattended installation

      3. Start the bare metal virtual machine and install it automatically

summary

preface

        In practical work, we often encounter such situations: we want to install Linux, but the computer does not have an optical drive, or a large number of computers need to install Linux at the same time. If we install Linux one by one through an optical drive, it is not only inefficient, but also not conducive to maintenance. This is the time you need the power of PXE.

1, PXE overview

      PXE is a network boot technology developed by Intel. It works in the Client/Server mode, allowing the client to download the boot image from the remote server through the network and load the installation file or the entire operating system.
      PXE is not strictly an installation method, but a boot method. A prerequisite for PXE installation is to install
Your computer contains a PXE supported network card (NIC), that is, there must be a PXE Client in the network card. PXE (pre boot execution environment) protocol enables the computer to boot through the network.
      The protocol is divided into client and server. PXE client is in the ROM of the network card. When the computer boots, the BIOS calls PXEclient into memory for execution, and the PXE client downloads the files placed at the remote end to run locally through the network.
DHCP server and TFTP server need to be set up to run PXE protocol. The DHCP server is used to send data to the PXE client
The host on which the system is to be installed) is assigned an IP address. Since the IP address is assigned to the PXE client, the corresponding PXE settings need to be added when configuring the DHCP server.
      In addition, TFTP client already exists in the ROM of PXE Client. PXE Client downloads required files from TFTP Server through TFTP protocol.

2, Advantages of PXE batch deployment

     Scale: assemble multiple servers at the same time

      Automation: install the system and configure various services

      Remote implementation: no installation media such as optical disk and U SB flash disk are required

3, Building prerequisites:

    The network card of the client supports PXE protocol (integrated BOOTROM chip), and the motherboard supports network boot. There is a DHCP server on 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). Among them, the first condition is actually the hardware requirement. At present, most servers and most PCCS can provide this support. You only need to allow booting from Network or LAN in BIOS settings.

4, Kickstart overview

      KickStart is an unattended installation. The working principle of KickStart is to record various parameters filled in by manual intervention in the typical installation process, and generate a file named ks.cfg; In the subsequent installation process (not limited to the machines that generate KickStart installation files), when parameters are required to be filled in, the installer will first find the files generated by KickStart. When appropriate parameters are found, the found parameters will be used. When appropriate parameters are not found, the installer needs manual intervention.
      In this way, if the KickStart file covers all the parameters that need to be filled in during the installation process, the installer can only tell the installer where to get the ks.cfg file, and then do his own business. After installation, the installer will restart the system according to the restart option set in ks.cfg and end the installation.

5, Steps to build PXE + KickStart:

    DHCP server is used to assign IP to clients;

     TFTP server is used to store PXE related culture, such as system boot file;

     FTP server is used to store system installation files;

    ks.cfg configuration file generated by KickStart;

    Host to be installed with a PXE support network card;

    1. Set up PXE remote installation server

      Required installation package:
          vsftpd       // It is used to place the installation image and access the image installation through ftp

          dhcp.x86_64 -12:4.2.5-7pd-3.0.2-27.el7.x86_64.r9.el7.centos    // Used to assign ip addresses to clients  

          syslinux-4.05-15.el7.x86_64.rpm           // Bootstrapper used to provide pxe

        tftp-server.x86_64 0:5.2-22.el7.rpm   // Used to download boot image files

        xinetd.x86_64 2:2.3.15-14.el7         // Used to host tftp

         system-config-kickstart.noarch 0:2.9.7-1.el7.rpm      // For unattended installation

        1-1. Configure dual network cards, one for dhcp and the other for installing environment packages using network sources

 

        1-2. Create a bare metal

        1-3. Install and enable DHCP service

yum install -y dhcp
cp -rfp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

The following settings are made in the configuration file:
vim /etc/dhcp/dhcpd.conf 
  ddns-update-style none;      //Disable dynamic updates
 
  subnet 192.168.10.0 netmask 255.255.255.0 {     //Configure network segment
    range 192.168.10.40 192.168.100.50;         //Configure address pool
    option routers 192.168.10.10;               //configure gateway
    option domain-name-servers 114.114.114.114;
    next-server 192.168.10.10;                  //Specify the address of the tftp server (*)
    filename "pxelinux.0";                      //Specifies the file name (*) of the pxe bootstrapper
}


systemctl start dhcpd
systemctl status dhcpd    //View status
systemctl enable dhcpd
systemctl is-enabled dhcpd   //Check whether the machine starts automatically

      1-4. Install and enable TFTP service

TFTP: (triple file transfer protocol) is a small and easy to implement file transfer protocol. TFTP is based on UDP datagrams and needs its own error correction measures. TFTP only supports file transfer, does not support interaction, and does not have a large command set. There is no directory list function, and users cannot be authenticated. However, its code occupies less memory and can solidify TFTP code without hard disk. It is very suitable for small computers and special-purpose devices.
A major difference between TFTP and FTP is that it is not interactive and does not authenticate. TFTP is generally used to transfer small files.

yum install -y tftp-server
vim /etc/ xinetd.d/tftp
service tftp
{
     socket_type     =dgram
     protocol        =udp
     wait            = no     //wait
    no Indicates that multiple clients can be connected together, yes Indicates that the client can only connect one by one. Indicates whether to enable multiple threads to work together. No 
    You need to wait
     user            =root
     server          = /usr/sbin/in.tftpd
     server_args     = -s /var/lib/tftpboot  //Specify TFTP root directory (storage path of boot file) -c allowed on 
                                               pass
     disable         = no    //disable no indicates that the TFTP service is enabled
     per_source      =11
     //By limiting the maximum number of connections of a host, a host can be prevented from monopolizing a service. Here, the number of connections per IP address is 11
     cps             =100 2
     //Indicates that the server can start up to 100 connections. If this number is reached, it will stop starting new services for 2 seconds. No requests will be accepted during this period 
     flags           =IPv4
}



#Prepare files that tftp needs to share
mount /dev/cdrom /mnt
cd /mnt/images/pxeboot/
#Kernel initialization image file / var/lib/tftpboot / site
cp initrd.img vmlinuz /var/lib/tftpboot/
ls
cp initrd.img vmlinuz /var/lib/tftpboot/

systemctl start xinetd
systemctl enable xinetd
systemctl start tftp
systemctl enable tftp


      1-5,   pxelinux.0 to prepare PXE bootstrapper

             pxelinux.0 is a binary file, which is mainly used as a guide for system installation steps to guide the client how to install the system.

yum provides */pxelinux.0  //Find out which package this file is installed by, and use it when it is not a path and a package*/
yum install -y syslinux
rpm -ql syslinux | grep pxelinux  #Locate pxe bootstrapper
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #Copy to the root directory of tftp and the system boot file

Note: only installed system-config-kickstart Software package, there will be/usr/share/syslinux/Directory and files in the directory

        1-6. 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 driver. The default Startup menu file is default and should be placed in the pxelinux.cfg subdirectory of the tftp root directory. For typical Startup menu configuration, refer to the following operations to establish it automatically or manually.
              As for why / var/lib/tftpboot/pxelinux.cfg/default file should be used, it is decided by pxelinux.0 file.

mkdir /var/lib/tftpboot/pxelinux.cfg  //The default pxelinux.cfg is not available and needs to be created manually. Note that it is a target 
                                        Record rather than file, although it is based on.cfg ending

vim /var/lib/tftpboot/pxelinux.cfg/default
  default auto     //Specify the default entry name, corresponding to the following label auto
  prompt 1         //Set whether to wait for user selection. 1 means to wait for user control, 0 means not to wait for user control, which will appear during installation 
                     boot:Press enter to select auto pattern
  
  
  label auto       //Default drawing installation
        kernel vmlinuz
        append initrd=initrd.img method=ftp://192.168.10.10/centos7 / / method must specify the network 
                                                                       route
  label linux text    //Text installation mode, enter linux text when boot: appears
        kernel vmlinuz
        append text initrd=initrd.img method=ftp://192.168.10.10/centos7

  label linux rescue   //In the rescue mode, enter linux rescue when boot: appears
        kernel vmlinuz
        append rescue initrd=initrd.img method=ftp://192.168.10.10/centos7

        1-7. Install ftp service and prepare Centos 7 installation source

yum install -y vsftpd
mount /dev/cdrom /mnt
mkdir /var/ftp/centos7
cp -rf /mnt/* /var/ftp/centos7   #Copy the mirror to it
systemctl restart vsftpd
systemctl restart tftp
systemctl restart dhcpd

      2. Implement Kickstart unattended installation

        2-1. Setup and adding ks boot parameters

yum install system-config-kickstart -y

        2-2. Open the Kickstart configurator window

          2-3. To configure the software package, you need to edit the ks.cfg file

[root@localhost~]# cd /var/ftp/
[root@localhost ftp]#ls
centos7 ks.cfg pub
[root@localhost ftp]# cd /root/
[root@localhost~]# ls
anaconda-ks.cfg initial-setup-ks.cfg Public template video picture document download music desktop
[root@localhost~]# vim anaconda-ks.cfg enter, find the following content and copy it

[root@localhost~]# vim /var/ftp/ks.cfg copy the above to the end

      3. Start the bare metal virtual machine and install it automatically

summary

        It should be noted that the network environment is VMnat1. There are many commands here. Please check.

Tags: pxe

Posted on Fri, 03 Sep 2021 13:22:03 -0400 by tblade