PXE server configuration on Linux

PXE Server (preboot execution environment) helps to install a system in the network without having a physical media. Instead of using manual installation method by using CD/DVD or pen drive, we can configure pxe server in any system in the network and install the operating system by selecting network mode installation. It is must needed to enable a network interface card from BIOS to boot from a network interface card. This method helps to install OS on many systems at a time in the network. In order to deploy successful PXE server the PXE environment needs a DHCP server that distributes the IP addresses to the client systems, and a TFTP server that downloads the installation files to the PXE clients. PXE server also helps to configure several automation tasks like software installation, join to ad server and so on.

Topic

  • How to configure PXE server on Centos Linux?
  • How to configure PXE server on RHEL or Scientific Linux?
  • Linux PXE server configuration
  • Linux advance PXE server configuration


Solution


PXE Server Prerequisites
  • Bare minimum install of Centos


PXE Server details
  • Server IP = 192.168.0.101
  • Host name = server.example.local
  • OS = CentOS 7.x


PXE Server Configuration

We will configure the PXE server on Centos 7 operating system and will use PXE client on both RHEL 6 and RHEL 7 for network boot.

PXE Configuration steps
  • Configuration of central yum repository
  • Installation and configuration of DHCP server
  • Installation and configuration of SYSLINUX bootloader
  • Installation and configuration of TFTP server


Configuration of central yum repository [1]

  • Install HTTPD package to configure Apache web server.
yum install httpd -y

  • mount OS ISO image and copy its content to /www/html directory.
# mkdir /tmp/test
# mount -t iso9660 -o loop CentOS-7-x86_64.iso /tmp/test

# mkdir /var/www/html/centos7
# cp -r /tmp/test/* /var/www/html/centos7

# umount /tmp/test
# mount -t iso9660 -o loop CentOS-6.10-x86_64.iso /tmp/test

# mkdir /var/www/html/centos6
# cp -r /tmp/test/* /var/www/html/centos6

  • Start apache service and allow port 80 in the firewall.
# systemctl start httpd
# systemctl enable httpd
# firewall-cmd --permanent --add-port=80/tcp
# firewall-cmd --reload


Install and Configure DHCP server [2]
  • Install HTTPD Package
# yum install dhcp* -y

  • Add the following configuration in /etc/dhcp/dhcpd.conf file.
# vim /etc/dhcp/dhcpd.conf
authoritative;
allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
next-server 192.168.0.101;
filename "pxelinux.0";

default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.0.0 netmask 255.255.255.0 {

  range 192.168.0.101 192.168.0.254;
  option broadcast-address 192.168.0.255;
  option routers 192.168.0.1;
  option subnet-mask 255.255.255.0;
}

  • Start dhcp service and allow DHCP in the firewall.
# systemctl start dhcpd
# systemctl enable dhcpd

# firewall-cmd --add-service=dhcp --permanent 
# firewall-cmd --reload


Installation and configuration of SYSLINUX bootloader [3]
  • The bootloaders files of PXE is available at /usr/share/syslinux. Copy these files to TFTP Server once TFTP server packages are installed.
# yum install syslinux
# ls /usr/share/syslinux/


Install and configure TFTP server [4]
  • TFTP (Trivial File Transfer Protocol ) transfers the files to its clients without any kind of authentication. Edit configuration file of tftp server /etc/xinetd.d/tftp and make the following changes.
# vim /etc/xinetd.d/tftp
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

  • Copy syslinux files form /usr/share/syslinux to /var/lib/tftpboot directory.
# cp -r /usr/share/syslinux/* /var/lib/tftpboot/
# mkdir /var/lib/tftpboot/pxelinux.cfg
# touch /var/lib/tftpboot/pxelinux.cfg/default
# mkdir /var/lib/tftpboot/networkboot-centos7
# mkdir /var/lib/tftpboot/networkboot-centos6

  • Copy initrd.img and vmlinuz from ISO images to TFTP directory with the following steps..
Centos 7:
# cp /var/www/html/centos7/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/networkboot-centos7/

Centos 7:
# cp /var/www/html/centos6/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/networkboot-centos6/


Create kickStart & PXE menu file [5]
  • Create the encrypted password for root user if you want to set root password through PXE installation and use the encrypted password string in kickstart.cfg file.
# openssl passwd -1 test@123
Password: $1$UOpZjEUC$MVV3kfrcp/nk4WFgpzy5D1

  • The default kickstart file resides at /root with name anaconda-ks.cfg. Copy this file to respective HTTP share directory and make the changes according the requirement. The pxe file can also be generated graphically by using system-config-kickstart command.
# cp /root/anaconda-ks.cfg /var/www/html/centos7/centos7_custom.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos7/centos7_graphical.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos7/centos7_minimal.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos7/centos7_rescue.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos6/centos6_custom.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos6/centos6_graphical.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos6/centos6_minimal.cfg
# cp /root/anaconda-ks.cfg /var/www/html/centos6/centos6_rescue.cfg

  • Edit PXE file and make required changes. Here we have given kickstart file for custom, graphical, minimal and rescue mode installation for both centos 6 and centos 7. Lets review them one by one.

Kickstart file for Centos 7 [Custom Installation]
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Use network installation
url --url="http://192.168.0.101/centos7"

Kickstart file for Centos 7 [Graphical Installation]
# vim /var/www/html/centos7/centos7_graphical.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Install OS instead of upgrade
install

# System authorization information
#auth --enableshadow --passalgo=sha512
auth  --useshadow  --passalgo=sha512

# Keyboard layouts
keyboard --vckeymap=in-eng --xlayouts='in (eng)'

# System language
lang en_IN.UTF-8

# Installation logging level
logging level=info

# Root password
rootpw --iscrypted $1$UOpZjEUC$MVV3kfrcp/nk4WFgpzy5D1

# Use network installation
url --url="http://192.168.0.101/centos7"

# Use graphical install
#graphical

# Use text mode install
text

# System services
services --enabled="chronyd"

# Run the Setup Agent on first boot
firstboot --disable
#ignoredisk --only-use=sda

# SELinux configuration
selinux --disabled

# Firewall configuration
firewall --disabled

# Network information
network  --bootproto=dhcp --device=enp0s3 --onboot=yes --mtu=1500 --noipv6

# Reboot after installation
reboot

# System timezone
timezone Asia/Kolkata --isUtc

#create other user
user --name=test --password=$1$l6M0CsFf$evV/JEdabuQm8Wzkbrof6. --iscrypted --gecos="Test User"

# Clear the Master Boot Record
zerombr

# System bootloader configuration
#bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
bootloader location=mbr

# Partition clearing information
#clearpart --all
clearpart --all --initlabel --drives=sda

# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=500
part pv.01 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup centos pv.01
#volgroup centos --pesize=4096 pv.01
logvol swap  --fstype="swap" --size=1024 --name=swap --vgname=centos
logvol /  --fstype="xfs" --name=root --vgname=centos --size=1 --grow

%packages
#For Graphical Desktop Installation
@^gnome-desktop-environment
@base
@compat-libraries
@core
@desktop-debugging
@development
@dial-up
@directory-client
@fonts
@gnome-apps
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-applications
@internet-browser
@java-platform
@legacy-x
@multimedia
@network-file-system-client
@networkmanager-submodules
@office-suite
@print-client
@security-tools
@x11
kexec-tools
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

Kickstart file for Centos 7 [Minimal installation]
# vim /var/www/html/centos7/centos7_minimal.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Install OS instead of upgrade
install

# System authorization information
#auth --enableshadow --passalgo=sha512
auth  --useshadow  --passalgo=sha512

# Keyboard layouts
keyboard --vckeymap=in-eng --xlayouts='in (eng)'

# System language
lang en_IN.UTF-8

# Installation logging level
logging level=info

# Root password
rootpw --iscrypted $1$rguU5llf$/Z0iQg8HuIqZKNKvruEXY.

# Use network installation
url --url="http://192.168.0.101/centos7"

# Use graphical install
#graphical

# Use text mode install
text

# System services
services --enabled="chronyd"

# Run the Setup Agent on first boot
firstboot --disable
#ignoredisk --only-use=sda

# SELinux configuration
selinux --disabled

# Firewall configuration
firewall --disabled

# Network information
network  --bootproto=dhcp --device=enp0s3 --onboot=yes --mtu=1500 --noipv6

# Reboot after installation
reboot

# System timezone
timezone Asia/Kolkata --isUtc

#create other user
user --name=suresh --password=$1$l6M0CsFf$evV/JEdabuQm8Wzkbrof6. --iscrypted --gecos="Suresh Sahoo"

# Clear the Master Boot Record
zerombr

# System bootloader configuration
#bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
bootloader location=mbr

# Partition clearing information
#clearpart --all
clearpart --all --initlabel --drives=sda

# Disk partitioning information
part /boot --fstype="xfs" --ondisk=sda --size=500
part pv.01 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup centos pv.01
#volgroup centos --pesize=4096 pv.01
logvol swap  --fstype="swap" --size=1024 --name=swap --vgname=centos
logvol /  --fstype="xfs" --name=root --vgname=centos --size=1 --grow

%packages
@^minimal
@core
chrony
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

Kickstart file for Centos 7 [Rescue Mode]
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Keyboard layouts
keyboard --vckeymap=in-eng --xlayouts='in (eng)'

# System language
lang en_IN.UTF-8

# Use network installation
url --url="http://192.168.0.101/centos7"

# Use text mode install
text

# Network information
network  --bootproto=dhcp


Kickstart file for Centos 6 [Custom installation]
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Use network installation
url --url="http://192.168.0.101/centos6"

Kickstart file for Centos 6 [Graphical installation]
# vim /var/www/html/centos6/centos6_graphical.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Install OS instead of upgrade
install

# System authorization information
auth  --useshadow  --passalgo=sha512

# System keyboard
#keyboard us
keyboard --vckeymap=in-eng --xlayouts='in (eng)'

# System language
#lang en_US
lang en_IN.UTF-8

# Installation logging level
logging --level=info

# Root password
rootpw --iscrypted $1$heOaddQy$M6gKoEp1cLHniH0l2dv8j.

# Use network installation
url --url="http://192.168.0.101/centos6"

# Use graphical install
#graphical

# Use text mode install
text

# Run the Setup Agent on first boot
firstboot --disable

# Firewall configuration
firewall --disabled

# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on

# Reboot after installation
reboot

# System timezone
timezone --isUtc Asia/Kolkata

#create other user
user --name=suresh --password=$1$l6M0CsFf$evV/JEdabuQm8Wzkbrof6. --iscrypted --gecos="Suresh Sahoo"

# Clear the Master Boot Record
zerombr

# System bootloader configuration
bootloader --location=mbr

# Partition clearing information
#clearpart --all
clearpart --all --initlabel --drives=sda
#clearpart --all --initlabel 
# Disk partitioning information
#part /boot --asprimary --fstype="ext4" --ondisk=sda --size=1024
#part swap --asprimary --fstype="swap" --ondisk=sda --size=2048
#part / --asprimary --fstype="ext4" --grow --ondisk=sda --size=1
part /boot --fstype="ext4" --ondisk=sda --size=1024
part pv.01 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup centos pv.01
#volgroup centos --pesize=4096 pv.01
logvol swap  --fstype="swap" --size=1024 --name=swap --vgname=centos
logvol /  --fstype="ext4" --name=root --vgname=centos --size=1 --grow

%packages
@additional-devel
@base
@basic-desktop
@compat-libraries
@console-internet
@debugging
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@directory-client
@eclipse
@emacs
@fonts
@general-desktop
@graphical-admin-tools
@graphics
@hardware-monitoring
@input-methods
@internet-applications
@internet-browser
@java-platform
@large-systems
@legacy-unix
@legacy-x
@network-tools
@office-suite
@performance
@perl-runtime
@remote-desktop-clients
@ruby-runtime
@scientific
@security-tools
@server-platform-devel
@system-admin-tools
@technical-writing
@tex
@x11
hmaccalc

%end

Kickstart file for Centos 6 [Minimal installation]
# vim /var/www/html/centos6/centos6_minimal.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# Install OS instead of upgrade
install

# System authorization information
auth  --useshadow  --passalgo=sha512

# System keyboard
keyboard us
#keyboard --vckeymap=in-eng --xlayouts='in (eng)'

# System language
#lang en_US
lang en_IN.UTF-8

# Installation logging level
logging --level=info

# Root password
rootpw --iscrypted $1$heOaddQy$M6gKoEp1cLHniH0l2dv8j.

# Use network installation
url --url="http://192.168.0.101/centos6"

# Use graphical install
#graphical

# Use text mode install
text

# Run the Setup Agent on first boot
firstboot --disable

# Firewall configuration
firewall --disabled

# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on

# Reboot after installation
reboot

# System timezone
timezone --isUtc Asia/Kolkata

#create other user
user --name=suresh --password=$1$l6M0CsFf$evV/JEdabuQm8Wzkbrof6. --iscrypted --gecos="Suresh Sahoo"

# Clear the Master Boot Record
zerombr

# System bootloader configuration
bootloader --location=mbr

# Partition clearing information
#clearpart --all
clearpart --all --initlabel --drives=sda
part /boot --fstype="ext4" --ondisk=sda --size=1024
part pv.01 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup centos pv.01
#volgroup centos --pesize=4096 pv.01
logvol swap  --fstype="swap" --size=1024 --name=swap --vgname=centos
logvol /  --fstype="ext4" --name=root --vgname=centos --size=1 --grow

%packages --ignoremissing --excludedocs
@core
@base
ssh
%end

Kickstart file for Centos 6 [Rescue Mode]
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL

# System keyboard
keyboard us
#keyboard --vckeymap=in-eng --xlayouts='in (eng)'

# System language
#lang en_US
lang en_IN.UTF-8

# Use network installation
url --url="http://192.168.0.101/centos6"

# Use text mode install
text

# Network information
network  --bootproto=dhcp 


Create PXE menu file and start service [6]
  • Edit PXE menu file /var/lib/tftpboot/pxelinux.cfg/default and make the following changes.
# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 300
MENU TITLE pxe.example.local PXE Menu

LABEL centos7_x64_Custom_Installation
MENU LABEL ^Install CentOS 7 X64 Custom Installation
KERNEL /networkboot-centos7/vmlinuz
APPEND  initrd=/networkboot-centos7/initrd.img  inst.repo=http://192.168.0.101/centos7 ks=http://192.168.0.101/centos7/centos7_custom.cfg

LABEL centos7_x64_Graphical
MENU LABEL ^Install CentOS 7 X64 Graphical
KERNEL /networkboot-centos7/vmlinuz
APPEND  initrd=/networkboot-centos7/initrd.img  inst.repo=http://192.168.0.101/centos7 ks=http://192.168.0.101/centos7/centos7_graphical.cfg

LABEL centos7_x64_Minimal
MENU LABEL ^Install CentOS 7 X64 Minimal
KERNEL /networkboot-centos7/vmlinuz
APPEND  initrd=/networkboot-centos7/initrd.img  inst.repo=http://192.168.0.101/centos7 ks=http://192.168.0.101/centos7/centos7_minimal.cfg

LABEL CentOS7 RESCUE
  MENU LABEL ^Boot CentOS7 on Rescue Mode
  KERNEL /networkboot-centos7/vmlinuz
  APPEND  initrd=/networkboot-centos7/initrd.img inst.repo=http://192.168.0.101/centos7 rescue ks=http://192.168.0.101/centos7/centos7_rescue.cfg

LABEL Centos6_x64_Custom_Installation
MENU LABEL ^Install CentOS 6 X64 Custom Installation
KERNEL /networkboot-centos6/vmlinuz
APPEND  initrd=/networkboot-centos6/initrd.img  inst.repo=http://192.168.0.101/centos6 ks=http://192.168.0.101/centos6/centos6_custom.cfg

LABEL Centos6_x64_Graphical
MENU LABEL ^Install CentOS 6 X64 Graphical
KERNEL /networkboot-centos6/vmlinuz
APPEND  initrd=/networkboot-centos6/initrd.img  inst.repo=http://192.168.0.101/centos6 ks=http://192.168.0.101/centos6/centos6_graphical.cfg

LABEL centos6_x64_Minimal
MENU LABEL ^Install CentOS 6 X64 Minimal
KERNEL /networkboot-centos6/vmlinuz
APPEND  initrd=/networkboot-centos6/initrd.img  inst.repo=http://192.168.0.101/centos6 ks=http://192.168.0.101/centos6/centos6_minimal.cfg
#If you don't want to assign kickstart configuration then commect the following kickstart option.

LABEL CentOS6 RESCUE
MENU LABEL ^Boot CentOS6 on Rescue Mode
KERNEL /networkboot-centos6/vmlinuz
APPEND  initrd=/networkboot-centos6/initrd.img inst.repo=http://192.168.0.101/centos6 rescue ks=http://192.168.0.101/centos6/centos6_rescue.cfg

  • Start and enable xinetd service and add required firewall rules.

    # systemctl start xinetd
    # systemctl enable xinetd
    # firewall-cmd --add-port=69/udp --permanent
    # firewall-cmd --reload

  • Restart all the services used for PXE server.

# systemctl restart httpd dhcpd xinetd


PXE Testing

Boot the system from network from BIOS menu and install os through pxeboot server.


You May Also Like

avatar

About the Author: TekFik

TekFik is a technical blogging site helps techies and engineers to solve their day to day issues and also allows everyone to share knowledge and feedback. Please feel free to contact us at tekfik.rd@gmail.com if there is anything.

4 Comments

  1. Just wanna remark that you have a very nice web site, I love the design and style it actually stands out.

Leave a Reply

Your email address will not be published. Required fields are marked *