Table of Contents

Configure PXE (Network Boot) installation Server on CentOS 7

PXE (Preboot eXecution Environment) Server allows unattended or automated OS installation over the Network.The main benefit of pxe is that we don’t need any bootable drive to boot OS(Operating system) and we do not need to to burn any ISO file into DVD or usb device.

Once the PXE server is configured we can install hundreds of System at the same time over the network.As it works on Client-Server architecture, to get the OS installation on clients, boot the clients via PXE option.

FIXME

Installation des Servers

In this article i am going to setup PXE Server on CentOS 7.x and then will try to install OS on the client using pxe boot.

Below are details of my Setup:

  • OS (Operating System) = CentOS 7.x
  • IP Address = 192.168.1.11
  • Hostname = pxe.example.com
  • SeLinux = Enabled
  • Firewall = Enabled

Step 1 - Install required packages for PXE Setup

To install and Configure pxe server on centos 7.x we need the following packages “dhcp, tftp-server, ftp server(vsftpd), xinted”. Open the terminal execute beneath command :

# yum install dhcp tftp tftp-server syslinux vsftpd xinetd

Step 2 - Configure DHCP Server for PXE

When we install dhcp package then a sample configuration file of dhcp server is created at /usr/share/doc/dhcp*/dhcpd.conf.example, the real the configuration file of dhcp is at /etc/dhcp/dhcpd.conf.

Copy the following lines into the file ‘/etc/dhcp/dhcpd.conf’, replace the ip subnet and other details as per your environment.

# vim /etc/dhcp/dhcpd.conf

# DHCP Server Configuration file.

ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
allow unknown-clients;

# internal subnet for my DHCP Server
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.60 172.168.1.70;
option domain-name-servers 172.168.1.11;
option domain-name "pxe.example.com";
option routers 192.168.1.11;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;

# IP of PXE Server
next-server 192.168.1.11;
filename "pxelinux.0";
}

Step 3 - Edit and Config tftp server

TFTP (Trivial File Transfer Protocol ) is used to transfer files from data server to its clients without any kind of authentication. In case of PXE server setup tftp is used for bootstrap loading. To config tftp server, edit its configuration file /etc/xinetd.d/tftp, change the parameter ‘disable = yes‘ to ‘disable = no’ and leave the other parameters as it is.

# 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
}

All the network boot related files are to be placed in tftp root directory: /var/lib/tftpboot

Run the following commands to copy required network boot files in /var/lib/tftpboot/

# cp -v /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
# cp -v /usr/share/syslinux/menu.c32 /var/lib/tftpboot
# cp -v /usr/share/syslinux/memdisk /var/lib/tftpboot
# cp -v /usr/share/syslinux/mboot.c32 /var/lib/tftpboot
# cp -v /usr/share/syslinux/chain.c32 /var/lib/tftpboot

# mkdir /var/lib/tftpboot/pxelinux.cfg
# mkdir /var/lib/tftpboot/networkboot

Step 4 - Mount ISO file and copy its contents to local ftp server

In my case i have already downloaded CentOS 7.x iso file on my PXE Server. Run the beneath commands to mount iso file and then copy its contents in ftp server’s directory /var/ftp/pub

# mount -o loop CentOS-7-x86_64-DVD-1511.iso /mnt/

# cd /mnt/
# cp -av * /var/ftp/pub/

Copy Kernel file (vmlimz) and initrd file from mounted iso file to ‘/var/lib/tftpboot/networkboot/

# cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/networkboot/
# cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/networkboot/

After this, we can unmount the iso file using the ‘umount’ command

# umount /mnt/

Step 5 - Create kickStart & PXE menu file.

Before creating kickstart file, let’s first create the root password in an encrypted string because we will using that encrypted password string in kickstart file.

# openssl passwd -1 MY-STR0NGpW123!

$6$bDp6BGDIUOTz487Q$Kw3w/B7Pb/T8bj/qOI1yXeHU.zdNPZbMo2N8GSKzHUxxdcTskfPkFx6SMkA5pAj/kFmUPpIRvC8DhKBievJUM/

System default kickstart file is placed under /root with name anaconda-ks.cfg. We will now creating our own kickstart-file under the folder /var/ftp/pub with the name centos7.cfg

Copy the following content into the new kickstart file. Please modify the file as per your needs.

# vim /var/ftp/pub/centos7.cfg

#version=CentOS 7

# Action - Install OS instead of upgrade
install


# Accept Eula
eula --agreed

# Firewall configuration
firewall --disabled

repo --name="EPEL" --baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64

# Use FTP installation media
url --url="ftp://192.168.1.11/pub/"

rootpw --iscrypted $6$bDp6BGDIUOTz487Q$Kw3w/B7Pb/T8bj/qOI1yXeHU.zdNPZbMo2N8GSKzHUxxdcTskfPkFx6SMkA5pAj/kFmUPpIRvC8DhKBievJUM/

# System authorization information
auth useshadow passalgo=sha512

# Use graphical install
graphical
firstboot disable

# Keyboard layouts
keyboard --vckeymap=ch-de_sundeadkeys --xlayouts='ch (de_sundeadkeys)'

# System language
lang en_US.UTF-8

# SELinux State
selinux --enabled

# System timezone
timezone Europe/Zurich --isUtc --ntpservers=0.centos.pool.ntp.org,1.centos.pool.ntp.org,2.centos.pool.ntp.org,3.centos.pool.ntp.org


# System bootloader configuration
bootloader --location=mbr --boot-drive=sda

# Partition clearing information
clearpart --all --initlabel


# Disk partitioning information
part pv.01 --fstype="lvmpv" --ondisk=sda --size=1 --grow
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /boot/efi --fstype="efi" --ondisk=sda --size=200 --fsoptions="umask=0077,shortname=winnt"

volgroup root_vg01 pv.01
logvol swap  --fstype="swap" --size=1024 --name=swap --vgname=root_vg01
logvol /  --fstype="xfs" --name=root --vgname=root_vg01 --size=1 --grow


%packages
@base
@core
at
bash-completion
bind-utils
bzip2
curl
man-pages
nc
net-tools
ntp
ntpdate
unzip
vim-enhanced
wget
zip

%end

%addon com_redhat_kdump --disable --reserve-mb='auto'

%end

Now we create a default PXE menu file (/var/lib/tftpboot/pxelinux.cfg/default), by copy the following contents into the pxe default file.

# vim /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
timeout 300
ONTIMEOUT 1

menu title ########## blackGATE - PXE Boot Menu ##########

label 1
menu label ^1) Install CentOS 7_x64
menu default
KERNEL /networkboot/vmlinuz
APPEND initrd=/networkboot/initrd.img inst.repo=ftp://192.168.1.11/pub ks=ftp://192.168.1.11/pub/centos7.cfg

label 2
menu label ^2) Boot from local drive
localboot 0

Step 6 - Start and enable xinetd, dhcp and vsftpd service

Use the beneath commands to start and enable xinetd, dhcp and vsftpd.

# systemctl start xinetd
# systemctl enable xinetd

# systemctl start dhcpd.service
# systemctl enable dhcpd.service

# systemctl start vsftpd
# systemctl enable vsftpd

In Case SELinux is enabled, then set the following selinux rule for ftp server.

# setsebool -P allow_ftpd_full_access 1

At the End, open all the needed ports in the OS firewall using following firewall-cmd commands

# firewall-cmd --add-service=ftp --permanent
# firewall-cmd --add-service=dhcp --permanent
# firewall-cmd --add-port=69/tcp --permanent 
# firewall-cmd --add-port=69/udp --permanent 
# firewall-cmd --add-port=4011/udp --permanent

# firewall-cmd --reload

Up to this point, PXE server installation and configuration is completed now.

Step 7 - Boot the clients with pxe boot option.

FIXME

BILDER VON VM BOOT EINFügen

Alte Links: https://www.linuxtechi.com/configure-pxe-installation-server-centos-7/ https://askubuntu.com/questions/412574/pxe-boot-server-installation-steps-in-ubuntu-server-vm/414813


Neue Links, Besser erklährt: https://www.tecmint.com/multiple-centos-installations-using-kickstart/ https://www.tecmint.com/install-pxe-network-boot-server-in-centos-7/

https://fogproject.org/


Fine-Tuneing des Kickstartfiles