PXE batch deployment

Posted by reckdan on Wed, 21 Aug 2019 17:13:38 +0200

Deployment of PXE

brief introduction

What is PXE?

1. PXE is the abbreviation of Preboot Execution Environment, which is called Preboot Execution Environment.
2. A network protocol designed by Intel enables the computer to start the installation system through the network.
3. It is a mechanism to start a computer with network interface, which does not depend on local data storage devices or locally installed systems.
4. The protocol is divided into client and server. PXE client is started in boot ROM of network card. When the computer boots, BIOS calls PXE client into memory for execution.
    The command menu is displayed. After the user chooses the system to install, the PXE client downloads the remote operating system to run locally through the network.

Common installation methods:

1. CD-ROM Installation
    Use server built-in CD-ROM or external USB CD-ROM to record the system image and install it from CD-ROM.
2. U Disk Installation
    The mirror system is written to the U disk by the tool and started from the U disk.
3. Mirror mount installation
    Remote mounting image installation using BMC Web GUI;
4. Network Boot Installation (PXE)
    The client starts through the network and reads the mirror on the remote server for installation.

Four Patterns of PXE server

IPV4 legacy,IPV4 UEFI,IPV6 legacy,IPV6 UEFI

IPV4 legacy PXE Start Required Files

1. pxelinux.0: Bootstrap, which is responsible for booting and booting the system. It acts like BIOS and calls PXE-related configuration files.
2. pxelinux.cfg: Folder, where PXE configuration files are stored
 3. vmlinuz: linux's kernel files, which can be loaded by bootstrappers to start the Linux system
 4. initrd.img: Short for boot loader initialized RAM disk, as the root file system loads various modules, drivers, services, etc., the network card driver is included in the file.

principle

1. Client BIOS supports network card start-up, and network card has PXE ROM chip;
2. The PXE Server has at least dhcp, tftp and nfs services and is open.
3. BIOS is executed in memory through PXE Client, and PXE Sever sends IP allocation request to dhcp.server in local area network.
4. After dhcp.server receives the request, it returns the location of IP and bootstrap file to PXE Server; the client requests bootstrap file to tftp.server
    tftp.server receives the request to send bootstrap file to client - > pxelinux.0;
5. After receiving the pxelinux.0 file, the client executes the file and requests the configuration file of pxelinux.0 - > tftpboot/pxelinux.cfg/default from tftp.server according to the content.
6. The client reads the default file and waits for the user to choose the system to install. After that, the client sends a request to tftp.server to provide the kernel file vmlinuz and the root file system initrd.img.
7. tftp.server receives client requests and provides vmlinuz and initrd.img;
8. The client receives the file and starts the kernel image file. According to the bootstrap configuration file pxelinux.0, the kernel file requests PXE sever to provide the automatic installation script and source file, PXE. 
    Server transmits relevant scripts and source files to the client through one of ftp/http/nfs, and the client automatically installs them after obtaining them.

PXE server erection process

1. Close Firewalls & SELinux
    Firewalls:
    $service iptables stop  <!--Temporary validity. Firewall opens automatically after restart-->
    $chkconfig iptables off <!--Permanent valid. Firewall does not open automatically after restart->
    SELinux:
    $setenforce 0   <!-- Temporary validity, invalidation after restart-->
    $vim /etc/selinux/config    <!--Permanent validity, restart validity-->
        SELINUX=disabled
2. Check if it is installed dhcp,tftp,nfs service
    $rpm -qa | grep {dhcp |  tftp | nfs}
3. To configure yum source
    $vim /etc/yum.repos.d/server.repo
        [development]
        name=development
        baseurl=file:///mnt/
        gpgcheck=0
        enabled=1
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
4. install dhcp,ftp,nfs service
    $yum install -y dhcp tftp nfs
5. Configure any network port information and set it IP address
    $vim /etc/sysconfig/network-scripts/ifcfg-enp3s0f0
        # Generated by dracut initrd
        NAME="enp3s0f0"         
        DEVICE="enp3s0f0"       
        ONBOOT=yes  <!--Start-Up Self-Start-->
        NETBOOT=yes
        UUID="169f6948-307c-42a7-bb35-a773c86fb5d6"
        BOOTPROTO=none  <!--IP Address type-->
        IPADDR=192.168.1.250    <!--IP address-->
        TYPE=Ethernet
        PREFIX=24
        DEFROUTE=yes
        IPV4_FAILURE_FATAL=no
        IPV6INIT=yes
        IPV6_FAILURE_FATAL=no
        IPV6_AUTOCONF=yes
        IPV6_DEFROUTE=yes
        IPV6_PEERDNS=yes
        IPV6_PEERROUTES=yes
    $service network start
6. To configure dhcp.conf And start the service
    $vim /etc/dhcp/dhcpd.conf
        # dhcpd.conf
        # Sample configuration file for ISC dhcpd
        ddns-update-style interim;  <!-- Temporary, intermittent -->
        ignore client-updates;
        allow booting;  <!--Appoint dhcp.server Whether the client is allowed to be in the booting Stage Query host declaration-->
        allow bootp;    <!--Appoint dhcp.server Is it right? bootp query Response -->
        class "pxeclients" {
        match if substring(option vendor-class-identifier,0,9)="PXEClient";
        next-server 192.168.1.250;  <!--Specify the address from which the host startup file is retrieved from the server -->
        filename "pxelinux.0";  <!--Specify the name of the host startup file -->
        }
        subnet 192.168.1.0 netmask 255.255.255.0 {
        option broadcast-address 192.168.1.255;
        option routers 192.168.1.250;
        option subnet-mask 255.255.255.0;
        range 192.168.1.205 192.168.1.249;  <!--dhcp address space -->
        default-lease-time 8640000;
        }
    $service dhcp start or $chkconfig dhcpd on  <!-- Enable dhcp -->
7. To configure tftp And start the service
    $vim /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.
        service tftp
        {
            socket_type     = dgram
            protocol        = udp
            wait            = yes
            user            = root
            server          = /usr/sbin/in.tftpd
            server_args     = -s /tftpboot  <!-- The folder where the operating system image files are stored. The default path is/lib/var/tftpboot -->
            disable         = no    <!-- yes Representatives are closed. no Representatives open -->
            per_source      = 11
            cps         = 100 2
            flags           = IPv4
        }
    $servicre tftp start 
or /etc/init.d/xinetd start or chkconfig tftp on<!-- Enable tftp.server,The last one is boot-up. tftp.server -->
8. To configure nfs And start the service
    $vim /etc/exports
        /tftpboot *(rw,no_root_squash)  <!-- Share all files under this file to any user -->
    $service nfs start
9. Preparing System Mirror Files
    $mount -o loop rhel7.4.iso /mnt
    $mkdir /tftpboot/rhel7.4
    $cp -rf /mnt/* /tftpboot/rhel7.4
    $chmod -R +x /tftpboot/rhel7.4
    $cp -rf /usr/share/syslinux/pxelinux.0 /tftpboot/
    $cp -rf boot.msg vesamenu.c32 splash.png /tftpboot/
    $mkdir /tftpboot/pxelinux.cfg
    $cp -rf /tftpboot/rhel7.4/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/
    $mv /tftpboot/pxelinux.cfg/isolinux.cfg /tftpboot/pxelinux.cfg/default
10. To configure pxelinux.cfg file
    $vim default
        default vesamenu.c32    <!-- vesamenu.c32:Set up the graphical selection interface. Linux Operating system isolinux Under the folder, menu.c32:Setting text
        //Select the interface and get it from the / user/share/syslinux path - >
        prompt 1    <!-- Whether to display"boot"Prompt,"1"Indicates that the prompt can be displayed directly by typing the system you want to install."0"Represents no display, will press directly
        "default"Content startup specified by parameters in-->
        timeout 600     <!-- Time-out before user input, unit 1/10 second -->
        display boot.msg
        menu background 1.jpg   <!-- Background picture -->
        menu title Welcome to CV Team's PXE server!     <!-- Display menu titles -->
        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 install   <!-- "Start the installation process" -->
        menu label ^1)Install rhel7.4 in /dev/sda
        menu default    <!-- If no choice is made within the specified time, the default option will be automatically activated. -->
        kernel rhel7.4/vmlinuz biosdevname=0
        append initrd=rhel7.4/initrd.img ks=nfs:192.168.1.250:/tftpboot/rhel7.4/ks/ks.cfg   <!-- append:Designated additions
        //The path of initrd.img for the kernel parameter; inst.repo: Set the location of the mirror file - >
11. Configuration unattended kickstart file
        #platform=x86, AMD64, or Intel EM64T
        #version=DEVEL
        # Install OS instead of upgrade
        install
        # Keyboard layouts
        keyboard 'us'
        # Root password
        rootpw --iscrypted $1$BrX4T9WN$OXLjtLaSe7VNnmjlsUyXE0
        # System language
        lang zh_CN
        # Firewall configuration
        firewall --disabled
        # System authorization information
        auth  --useshadow  --passalgo=sha512
        # Use graphical install
        install
        graphical
        # SELinux configuration
        selinux --disabled
        # Use NFS installation media
        nfs --server=192.168.1.250 --dir=/tftpboot/rhel7.4
        # Network information
        network  --bootproto=dhcp --device=enp3s0f0
        # Reboot after installation
        reboot
        # System timezone
        timezone Asia/Shanghai
        # Partition clearing information
        clearpart --all --drives=sda
        # System bootloader configuration
        bootloader --append="crashkernel=768M vconsole.font=latarcyrheb-sun16 vconsole.keymap=us biosdevname=0 ipv6.
        disable=1 console=tty0 console=ttyS0,115200 scsi_mod.scan=sync intel_idle.max_cstate=0 pci=pcie_bus_perf
        nouveau.modeset=0 rd.driver.blacklist=nouveau video=vesa:off rd.driver.pre=ahci" --location=mbr --boot-drive
        =sda
        # autopart --type=lvm
        part /boot --asprimary --fstype="ext4" --ondisk=sda --size=1024
        part swap --asprimary --fstype="swap" --ondisk=sda --size=51200
        part / --asprimary --fstype="ext4" --ondisk=sda --size=153600

        %packages
        @additional-devel
        @anaconda-tools
        @backup-client
        @backup-server
        @base
        @compat-libraries
        @console-internet
        @core
        @debugging
        @desktop-debugging
        @development
        @dial-up
        @directory-client
        @directory-server
        @dns-server
        @emacs
        @file-server
        @fonts
        @ftp-server
        @gnome-apps
        @gnome-desktop
        @graphical-admin-tools
        @graphics
        @guest-agents
        @guest-desktop-agents
        @hardware-monitoring
        @identity-management-server
        @infiniband
        @input-methods
        @internet-browser
        @java-platform
        @kde-desktop
        @large-systems
        @legacy-unix
        @legacy-x
        @load-balancer
        @mail-server
        @mainframe-access
        @mariadb
        @mariadb-client
        @multimedia
        @network-file-system-client
        @network-server
        @network-tools
        @networkmanager-submodules
        @perl-runtime
        @perl-web
        @php
        @platform-devel
        @platform-kvm
        @platform-microsoft
        @platform-vmware
        @postgresql
        @postgresql-client
        @print-client
        @print-server
        @python-web
        @remote-desktop-clients
        @remote-system-management
        @ruby-runtime
        @scientific
        @security-tools
        @smart-card
        @system-admin-tools
        @system-management
        @technical-writing
        @virtualization-client
        @virtualization-hypervisor
        @virtualization-platform
        @virtualization-tools
        @web-server
        @web-servlet
        @x11
        %end

Topics: Linux network vim SELinux firewall