KB 101019 - How to make PXE_Boot script

KB 101019 - How to make PXE_Boot script

Introduction of PXE booting

PXE (Pre-Boot Execution Environment) booting is a technology that enables a computer to boot from a network device, rather than a local hard drive or other storage media. PXE booting is commonly used in enterprise environments to automate the deployment of operating systems and software applications on a large scale.

With PXE booting, a client computer first requests an IP address from a DHCP (Dynamic Host Configuration Protocol) server, then requests the location of a boot server from a TFTP (Trivial File Transfer Protocol) server. The boot server provides the client computer with the necessary files to boot, including the operating system, drivers, and other software.

PXE booting provides several benefits, including faster deployment and provisioning of operating systems and applications, and reduced administrative overhead. It also enables centralized management of operating systems and software applications, ensuring that they are consistent and up-to-date across all client computers.

PXE booting is commonly used in combination with other technologies, such as containerization and virtualization, to automate the deployment and management of software applications in large-scale environments.



System Requirements

Hardware requirements:

  1. RAM: 8 GB (Preferred 16)
  2. PROCESSOR: i5 10 gen
  3. SSD: 256GB

Software requirements:

  1. VMware workstation
  2. Centos7 iso
  3. Editor: - vi/vim/nano

Virtual Machine Requirement for Master Node

  1. RAM: 4GB
  2. Cores: 2
  3. Storage: 50GB
  4. OS: Centos 7 (Linux)
  5. Network Adapter: 2
    1. NAT
    2. Custom


Prerequisite For Creating a PXE Cluster

Disable SELinux:

  1.       vim /etc/selinux/config


Stop & Disable Firewall:

  1. systemctl stop firewalld
  2. systemctl disable firewalld
  3. systemctl status firewalld


Code

  1. Crate a file in any editor (vi/vim/nano) and paste all following code
  2. Save to [file_name].sh
  3. For example- pxe_boot_script.sh
  4. Change file permission to rwx(777)
  5. Execute script using command (./[file_name].sh) or ( bash [file_name].sh
  6. For example 1) ./pxe_boot_script.sh           2). bash pxe_boot_script.sh
  7. User inputs after execution: - Provide only necessary IP addresses like
  8. Server IP address (Master Node)
  9. Subnet
  10. Network Mask
  11. Starting IP Range (for DHCP pool ip)
  12. Ending IP Range (for DHCP pool ip)

Install all necessary packages

  1. yum install -y dhcp* syslinux xinetd tftp-server httpd
Description: - yum is a package installer, this code installs necessary packages like: - DHCPD (for IP Address pool and lease), SYSLINUX, XINTED TFTP-SERVER and HTTPD.

Configure dhcpd network

  1. tee /etc/dhcp/dhcpd.conf<<EOF
  2. #host_change=server Host ip, subnet_change=subnet, netmask_change=netmask, range_start=starting ip, range_end=ending ip,
  3. option domain-name "host_change";
  4. subnet subnet_change netmask netmask_change{
  5. range range_start range_end;
  6. option routers host_change;
  7. filename "pxelinux.0";
  8. next-server host_change;
  9. }
  10. EOF
Description: - TEE command is use stdin to stdout, (save inputs to a file), This code configure DHCP network, assigning SERVER IP, SUBNET, NETWORK MASK, POOL RANGE. All this inputs will provide by user after execution of script.

User Input

  1. #read ip address, subnet, netmask, and DHCP network range from user
  2. read -p "enter server ip: " s_ip
  3. read -p "enter subnet mask: " sub_ip
  4. read -p "enter netmask: " net_ip
  5. read -p "enter starting ip range:" start_ip
  6. read -p "enter ending ip range:" end_ip
  7. sed -i -e "s/host_change/${s_ip}/g" /etc/dhcp/dhcpd.conf
  8. sed -i -e "s/subnet_change/${sub_ip}/g" /etc/dhcp/dhcpd.conf
  9. sed -i -e "s/netmask_change/${net_ip}/g" /etc/dhcp/dhcpd.conf
  10. sed -i -e "s/range_start/${start_ip}/g" /etc/dhcp/dhcpd.conf
  11. sed -i -e "s/range_end/${end_ip}/g" /etc/dhcp/dhcpd.conf
  12. #make directory
  13. mkdir /var/lib/tftpboot/pxelinux.cfg
  14. #copy pxelinux.0 file to newly created direcoty
  15. cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
Description: - User provides the all IP Address and pool range, script automatically changes the values to all the configuration files.

Configure xinted file

  1. #configure xinted file
  2. tee /etc/xinetd.d/tftp<<EOF
  3. #default: off
  4. #description: The tftp server serves files using the trivial file transfer \
  5. #protocol.  The tftp protocol is often used to boot diskless \
  6. #workstations, download configuration files to network-aware printers, \
  7. #and to start the installation process for some operating systems.
  8. service tftp
  9.       {
  10.       socket_type          = dgram
  11.       protocol                 = udp
  12.       wait                        = yes
  13.       user                        = root
  14.       server                     = /usr/sbin/in.tftpd
  15.       server_args           = -s /var/lib/tftpboot
  16.       disable                   = no
  17.       per_source            = 11
  18.       cps                          = 100 2
  19.       flags                       = IPv4
  20.       }
  21. EOF
  1. #create a directory and copy all boot related files
  2. mkdir -p /var/pxe/centos7
  3. mkdir -p /var/lib/tftpboot/centos7
  4. mount -t iso9660 -o loop /dev/cdrom /var/pxe/centos7/
  5. cp /var/pxe/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7/
  6. cp /var/pxe/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/centos7/
  7. cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/ 

Configure pxelinux.cfg file

  1. #configure pxelinux.cfg file
  2. tee /var/lib/tftpboot/pxelinux.cfg/default<<EOF
  3. #server_ip
  4. timeout 100
  5. default menu.c32
  6. menu title #######PXE BOOT MENU####
  7. label 1
  8.       menu label ^1) Install centos7
  9.      kernel centos7/vmlinuz
  10.                      append initrd=centos7/initrd.img ks=http://host_change/ks/centos7-ks.cfg method=http://host_change/centos7/ devfs=nomount
  11. label 2
  12.       menu label ^2) Boot from local drive
  13.                     localboot
  14. EOF
  15. sed -i -e "s/host_change/${s_ip}/g" /var/lib/tftpboot/pxelinux.cfg/default

Configure pxeboot.conf file

  1. #configure pxeboot.conf file
  2. tee /etc/httpd/conf.d/pxeboot.conf<<EOF
  3. #subnet_ip
  4. Alias /centos7 /var/pxe/centos7
  5. <Directory /var/pxe/centos7>
  6. options Indexes FollowSymlinks
  7. Require ip 127.0.0.1 subnet_change/24
  8. </Directory>
  9. EOF
  10. sed -i -e "s/subnet_change/${sub_ip}/g" /etc/httpd/conf.d/pxeboot.conf

Kickstart file

  1. #kickstart
  2. #python -c 'import crypt,getpass;print(crypt.crypt(getpass.getpass(),crypt.mksalt(crypt.METHOD_SHA512)))' > pass.txt
  3. mkdir /var/www/html/ks
  4. tee /var/www/html/ks/centos7-ks.cfg<<EOF
  5. #create new
  6. install
  7. # automatically proceed for each steps
  8. autostep
  9. #reboot after installing
  10. reboot
  11. #encrypt algorithm
  12. auth --enableshadow --passalgo=sha512
  13. #installation source
  14. url --url=http://host_change/centos7/
  15. # install disk
  16. ignoredisk --only-use=sda
  17. # keyboard layouts
  18. keyboard --vckeymap=jp106 --xlayouts='jp','us'
  19. # system locale
  20. lang en_US.UTF-8
  21. # network settings
  22. network --bootproto=dhcp --ipv6=auto --activate --hostname=localhost
  23. #root password you generated above
  24. #rootpw --iscrypted < pass.txt
  25. #timezone
  26. timezone Asia/Tokyo --isUtc --nontp
  27. #bootloader's settings
  28. bootloader --location=mbr --boot-drive=sda
  29. #initialize all partition tables
  30. zerombr
  31. clearpart --all --initlabel
  32. #partitioning
  33. autopart --type=lvm
  34. #part /boot --fstype="xfs" --ondisk=sda --size=500
  35. #part pv.10 --fstype="lvmpv" --ondisk=sda --size=51200
  36. #volgroup VolGroup --pesize=4096 pv.10
  37. #logvol / --fstype="xfs" --size=20480 --name=root --vgname=VolGroup
  38. #logvol swap --fstype="swap" --size=4096 --name=swap --vgname=VolGroup
  39. %packages
  40. @core
  41. %end
  42. EOF
  43. sed -i -e "s/host_change/${s_ip}/g" /var/www/html/ks/centos7-ks.cfg

Start all the services

  1. systemctl start xinetd
  2. systemctl enable xinetd
  3. systemctl start httpd
  4. systemctl enable httpd
  5. systemctl start dhcpd
  6. systemctl enable dhcpd
  7. systemctl start tftp
  8. systemctl enable tftp

Screenshots of output

User provides IP Addresses


DHCP file created after execution

pxelinux.cfg

pxeboot.conf file



xinted file

Kickstart File



for full script please click here


    • Related Articles

    • KB 054003 - How to create Virtual Machine in VMWare

      What is Virtualisation Virtualization is technology that lets you create useful IT services using resources that are traditionally bound to hardware. It allows you to use a physical machine’s full capacity by distributing its capabilities among many ...
    • KB 361001 - What is Boot Process in Linux OS.

      Boot Process in Linux OS. Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears? Press the power button on your system, and after few moments you see the Linux login ...
    • KB 461110 - Create VM on Proxmox.

      Steps to create VM. Login to Proxmox account with credentials. In home screen Top Right click on "create VM". Here create: Virtual Machine wizard is appear. Select the server in which you want to create VM. VM ID is auto-generated. Provide any name ...
    • KB 237013 - Configuring BMC in ASUS Server

      To configure the Baseboard Management Controller (BMC) IP address on an ASUS server, initially access the server's BIOS/UEFI settings and then configure the BMC network settings. Here's a step-by-step instructions Server BMC Configuration preparation ...
    • KB 158059 - How to collect diagnostic logs using the NetApp Log Collection Script

      1. Purpose This document describes the procedure to collect diagnostic logs using the NetApp Log Collection Script in environments running: BeeGFS NetApp E-Series backend storage HA cluster using Pacemaker and Corosync This script is typically ...
    • Recent Articles

    • KB-630208 | How to use Find and Locate to search for files in Linux

      Purpose To provide Linux administrators and Field Engineers with guidance on using the find and locate utilities to efficiently search for files and directories within a Linux filesystem based on criteria such as name, type, size, timestamps, ...
    • KB-630164 | How to use rsync to Synchronize Files

      Purpose To provide a clear and practical procedure for using the rsync utility to synchronize files and directories between local systems and remote hosts, including push and pull operations, while preserving file attributes and optimizing data ...
    • KB-630107 | How to create a Linux swap file

      Purpose To provide Field Engineers and Linux administrators with a standardized procedure for creating, configuring, and validating a Linux swap file. This procedure helps ensure sufficient virtual memory is available when physical RAM is exhausted ...
    • MSI All-in-One (AIO) PC – Physical Damage Policy for Warranty Claims

      MSI All-in-One (AIO) PC – Physical Damage Policy for Warranty Claims MSI's standard warranty does not cover physical or accidental damage to an All-in-One (AIO) PC. If the damage is determined to be caused by external factors rather than a ...
    • KB 134833 - Troubleshooting NVSM Alert NV-CPU-XX – Unrecoverable CPU Internal Error

      Purpose This document provides a general troubleshooting procedure for the NVIDIA System Management (NVSM) alert NV-CPU-XX, which indicates that a CPU has reported an internal error. The article outlines how to verify whether the alert represents an ...
    • Popular Articles

    • CP Plus Camera and NVR Configuration

      NVR Configuration The CP Plus Pro Series of NVRs have been meticulously designed for providing you with upgraded performance and higher recording quality in your IP video surveillance solution. The robust processor that has been inculcated in this ...
    • KB 775235 - Kerberos Authentication – Overview

      What is Kerberos? Kerberos is a secure authentication method used in our Active Directory (AD) environment (mbuzztech.com). It allows users to: Access multiple systems without re-entering passwords (Single Sign-On – SSO) Log in once Where We Use It ...
    • How to Remove and Reinstall NVIDIA Drivers on Ubuntu

      This article provides step by step guide to completely remove existing NVIDIA drivers and reinstall specific version of the NVIDIA driver on the Ubuntu system Prerequisites Administrative (sudo) access to the Ubuntu system. Internet access to ...
    • KB 692001 - Personal Computers and Servers - Classification and Point of Contact

      We can classify the computers that MBUZZ handles based on their form-factor as below: Tower Workstations, Desktops, Gaming PCs and SFF (Small form factor) PCs fall under this category. These are computers people would use on a desk and rarely move. ...
    • KB 298031 - M.2 SSD Tier List

      The sequential read and write speeds, which are usually the most advertised number, are not a proper benchmark of real-world performance or the quality of an SSD. This article categorizes and tiers SSDs based on factors like the type of NAND flash, ...