CentOS 7 PXE Server

To install PXE server on Centos to provide automated installation for PCs and servers through our network without human interaction, the client needs and IP at boot for connecting to PXE server which is provided by DHCP , and need minimal boot files to start boot menu which will be provided by TFTP-Server , and xinetd for protection , with the help of syslinux package to provide files that makes a boot menu easily , of course our installation needs a place to store ISO files and publish it for client which can be provided by Web Server like apache or FTP Server like VSFTPD , we will use VSFTPD in this tutprial, so let’s go..

01. Install Requirements:
 yum -y install dhcp vsftpd tftp-server xinetd syslinux
02. Configure DHCP:

make sure to use your IP subnet and range correctly to fit your network size and requirements
vim /etc/dhcp/dhcpd.conf

ddns-update-style interim;
 ignore client-updates;
 authoritative;
 allow booting;
 allow bootp;
 allow unknown-clients;
 # A slightly different configuration for an internal subnet.
 subnet 192.168.0.0 netmask 255.255.255.0 {
 range 192.168.1.100 192.168.1.200;
 option domain-name-servers 192.168.1.10;
 option domain-name "pxe.akm.local";
 option routers 192.168.1.10;
 default-lease-time 600;
 max-lease-time 7200;

# PXE SERVER IP
 next-server 192.168.1.10;  #  DHCP server ip
 filename "pxelinux.0";  # IMPORTANT
 }
03. Configure Xinetd to allow tftp:

vim /etc/xinetd.d/tftp
CHANGE :

disable = yes

TO

disable = no

04. TFTP server Configuration:

chmod 777 /var/lib/tftpboot/

mkdir /var/lib/tftpboot/pxelinux.cfg
mkdir /var/lib/tftpboot/netboot/

*Copy file provided by syslinux package to help making a boot menu :

 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/
05. Copy Installation files from Linux ISO :

mount ISO to a path then copy its content to folder in FTP path, for example:

 mount centos-7.iso /mnt
 mkdir /var/ftp/pub/centos7
 cp -R /mnt/* /var/ftp/pub/centos7/
06. Allow Booting by copying required boot file:

you can get this files (vmlinuz and initrd.img) from CentOS Repo or from ISO.

Copy initrd.img  and vmlinuz from mount folder to /tftpboot/netboot/

 cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/netboot/
 cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/netboot/
07. Create PXE menu :

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

default menu.c32
 prompt 0
 timeout 100
 MENU TITLE akm.local PXE Menu

LABEL centos7_x64
 MENU LABEL CentOS 7 X64 By A.K.M
 KERNEL /netboot/vmlinuz
 APPEND  initrd=/netboot/initrd.img  inst.repo=ftp://192.168.1.10/pub/centos7/  ks=ftp://192.168.1.10/pub/cento7/ks.cfg

*Make sure to use ftp url correctly

08. kickstart file:

*make sure the name and path is the same as in menu file in the last step.

*to use encrypted passwords for root in kickstart file:

yum -y install openssl
openssl passwd -1 “mypassword”

copy the output hash and use it

Example:

openssl passwd -1 "akm" 
#! should output something like this:
$1$7WYOJvcR$3qXaSZVexQDuIPbszPfJQ/

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

# enable firewall and allow ssh service
#firewall --enabled --service=ssh
# OR disable it to prevent some problems
firewall --disabled
 # install NOT upgrade
 install
 # installation files path
 url --url="ftp://192.168.1.10/pub/centos7"
 # root password encrypted
 rootpw --iscrypted $1$7WYOJvcR$3qXaSZVexQDuIPbszPfJQ/
 # passwd algorithm for passwords
 auth useshadow passalgo=sha512
 # install mode: text OR graphical
 text
 firstboot disable
 # allow reboot after finishing without prompt
 reboot
 # keyboard and language setting
 keyboard us
 lang en_US
 # disable selinux , i don't think it is required
 selinux disabled
 # timezone, use your own zone
 timezone Africa/Cairo
 # automatic partitioning and install mbr bootloader , you may customize partitioning if you want, read about it
 bootloader location=mbr
 clearpart --all --initlabel
 autopart
 # loggine level
 logging level=info
 # adding users
 user --name=akm --password="$1$5PcknTDn$rRu6/UxXkiThEbiJTCHgr/" --iscrypted

# installing required packages, @core is minimal installation , read before editing
 %packages
  @core
 %end

09. Enable and Start Services:
 systemctl start vsftpd
 systemctl start dhcp
 systemctl start xinetd
 systemctl enable vsftpd
 systemctl enable dhcp
 systemctl enable xinetd
10. Firewall Configuration:
 firewall-cmd --permanent --add-service=ftp --add-service=tftp --add-service=dhcp
 firewall-cmd --reload
NOW start any client maching in your network or your virtual environment and boot from network
Enjoy !.
Advertisements

One thought on “CentOS 7 PXE Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s