PXE Boot Server on CentOS 6

To set up a PXE boot server on CentOS 6 we need to install and configure the following

  • DHCP Server
  • TFTP Server
  • Apache HTTP Server
  • Local mirror of a Linux distribution (optional)
  • UPDATE - 2013-04-21 - Added Fedora 18
  • UPDATE - 2013-05-06 - Added Ubuntu 12.04
  • UPDATE - 2013-08-16 - Added Fedora 19, removed Fedora 18

DHCP Server

yum install dhcp

Edit /etc/dhcp/dhcpd.conf

authoritative;
ddns-update-style none;

subnet 192.168.1.0 netmask 255.255.255.0 {

        option routers                  192.168.1.1;
        option subnet-mask              255.255.255.0;

        option domain-name              "example.com";
        option domain-name-servers      192.168.1.201, 192.168.1.202;

        option time-offset              0;
        option ntp-servers              192.168.1.201, 192.168.1.202;

        default-lease-time 42000;
        max-lease-time 84000;

        next-server 192.168.1.203;        # our TFTP server
        filename "/pxelinux.0";

        pool {
                default-lease-time 900;
                max-lease-time 1800;
                range 192.168.1.11 192.168.1.199;
        }
}

Enable and restart DHCP server

chkconfig dhcpd on
service dhcpd restart

TFTP Server

yum install tftp-server syslinux memtest86+
  • syslinux is the package pxelinux.0 comes from
  • memtest86+ is our memory test utility
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

mkdir -p /var/lib/tftpboot/images/memtest
cp /boot/memtest86+* /var/lib/tftpboot/images/memtest

PXE Boot Menu

we can create a nice PXE Boot menu to navigate through different options and pick different OSes to install.

First we will create a messages directory for our .msg files. All .msg files are 24x80 characters in size.

mkdir /var/lib/tftpboot/messages/

/var/lib/tftpboot/messages/help.msg

  _______       ______                    ____________      ______
  __  __ \_________  /_______ ________    __  ___/_  /_________  /______
  _  / / /_  ___/_  //_/  __ `/_  ___/    _____ \_  __/  __ \_  /_  ___/
  / /_/ /_(__  )_  ,<  / /_/ /_  /        ____/ // /_ / /_/ /  / / /__
  \____/ /____/ /_/|_| \__,_/ /_/         /____/ \__/ \____//_/  \___/


                            Main Menu



  F1 - Help                           This help screen
  F2 - Images                         Operating system images
  F3 - Rescue                         Rescue images
  F4 - Special                        diskwipe, memtest






===============================================================================
   [F1-Help]           F2-Images           F3-Rescue           F4-Special
===============================================================================

/var/lib/tftpboot/messages/images.msg

  _______       ______                    ____________      ______
  __  __ \_________  /_______ ________    __  ___/_  /_________  /______
  _  / / /_  ___/_  //_/  __ `/_  ___/    _____ \_  __/  __ \_  /_  ___/
  / /_/ /_(__  )_  ,<  / /_/ /_  /        ____/ // /_ / /_/ /  / / /__
  \____/ /____/ /_/|_| \__,_/ /_/         /____/ \__/ \____//_/  \___/


         Enter the name of operating system you wish to install



  centos-6.5-64         CentOS 6.5 64-bit
  fedora-19-64          Fedora 19 64-bit
  ubuntu-12.04-64       Ubuntu 12.04 64-bit







===============================================================================
    F1-Help           [F2-Images]          F3-Rescue           F4-Special
===============================================================================

/var/lib/tftpboot/messages/rescue.msg

  _______       ______                    ____________      ______
  __  __ \_________  /_______ ________    __  ___/_  /_________  /______
  _  / / /_  ___/_  //_/  __ `/_  ___/    _____ \_  __/  __ \_  /_  ___/
  / /_/ /_(__  )_  ,<  / /_/ /_  /        ____/ // /_ / /_/ /  / / /__
  \____/ /____/ /_/|_| \__,_/ /_/         /____/ \__/ \____//_/  \___/


           Enter the name of rescue image you wish to load



  rescue                CentOS 6.5 64-bit (rescue mode)









===============================================================================
    F1-Help            F2-Images          [F3-Rescue]          F4-Special
===============================================================================

/var/lib/tftpboot/messages/special.msg

  _______       ______                    ____________      ______
  __  __ \_________  /_______ ________    __  ___/_  /_________  /______
  _  / / /_  ___/_  //_/  __ `/_  ___/    _____ \_  __/  __ \_  /_  ___/
  / /_/ /_(__  )_  ,<  / /_/ /_  /        ____/ // /_ / /_/ /  / / /__
  \____/ /____/ /_/|_| \__,_/ /_/         /____/ \__/ \____//_/  \___/


                 Enter the name of action you want to run



  memtest                     Memtest86+









===============================================================================
    F1-Help            F2-Images           F3-Rescue          [F4-Special]
===============================================================================

PXE Configuration

  • /var/lib/tftpboot/pxelinux.cfg/ will contain the default PXE configuration file
  • /var/lib/tftpboot/images/ will contain the vmlinuz and initrd.img files of OSes we will want to install
mkdir /var/lib/tftpboot/pxelinux.cfg/
mkdir /var/lib/tftpboot/images/

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

default local
timeout 600
prompt 1
display messages/help.msg
F1 messages/help.msg
F2 messages/images.msg
F3 messages/rescue.msg
F4 messages/special.msg

label centos-6.5-64
  kernel images/centos-6.5-64/vmlinuz
  append initrd=images/centos-6.5-64/initrd.img nomodeset ksdevice=bootif ip=dhcp ks=http://192.168.1.203/ks/centos-6.5-64.cfg
  ipappend 2

label fedora-19-64
  kernel images/fedora-19-64/vmlinuz
  append initrd=images/fedora-19-64/initrd.img nomodeset ksdevice=bootif ip=dhcp ks=http://192.168.1.203/ks/fedora-19-64.cfg
  ipappend 2

label ubuntu-12.04-64
  kernel images/ubuntu-12.04-64/linux
  append initrd=images/ubuntu-12.04-64/initrd.gz auto=true interface=eth0 hostname=ubuntu1204 url=http://192.168.1.203/ks/ubuntu-12.04-64.cfg

label rescue
  kernel images/centos-6.5-64/vmlinuz
  append initrd=images/centos-6.5-64/initrd.img ksdevice=bootif ip=dhcp nomount rescue lang=en_US keymap=us method=http://192.168.1.203/dist/centos-6.5-64/
  ipappend 2

label memtest
  kernel images/memtest/memtest

label pxe
  pxe pxelinux.0

label local
  localboot 0

Enable and start TFTP Server

chkconfig tftp on
chkconfig xinetd on
service xinetd start

Apache Server

yum install httpd
chkconfig httpd on
service httpd start

Create Local Mirror of OSes

rsync -av --delete ftp.heanet.ie::pub/centos/6.5/os/x86_64/ /var/www/html/dist/centos-6.5-64/
rsync -av --delete ftp.heanet.ie::pub/fedora/linux/releases/19/Fedora/x86_64/os/ /var/www/html/dist/fedora-19-64/

Copy vzlinuz and initrd.img to /var/lib/tftpboot/images

mkdir /var/lib/tftpboot/images/centos-6.5-64
cp /var/www/html/dist/centos-6.5-64/images/pxeboot/vmlinuz /var/lib/tftpboot/images/centos-6.5-64/
cp /var/www/html/dist/centos-6.5-64/images/pxeboot/initrd.img /var/lib/tftpboot/images/centos-6.5-64/

mkdir /var/lib/tftpboot/images/fedora-19-64
cp /var/www/html/dist/fedora-19-64/images/pxeboot/vmlinuz /var/lib/tftpboot/images/fedora-19-64/
cp /var/www/html/dist/fedora-19-64/images/pxeboot/initrd.img /var/lib/tftpboot/images/fedora-19-64/

mkdir /var/lib/tftpboot/images/ubuntu-12.04-64
wget -O /var/lib/tftpboot/images/ubuntu-12.04-64/linux http://archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
wget -O /var/lib/tftpboot/images/ubuntu-12.04-64/initrd.gz http://archive.ubuntu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz

Kickstart and Preseed Files

And finally, here are the kickstart and preseed files

social