Table of Contents

pxe - How to use pxe in Linux

How to install Linux with pxe on CentOS 7



What is PXE?

PXE stands for Preboot eXecution Environment.

Necessities

Necessities Note
xinetd
dhcp /etc/dhcpd.conf
tftp-server /etc/xinetd.d/tftp
syslinux
syslinux-tftpboot
/var/lib/tftpboot/pxelinux.0
/var/lib/tftpboot/menu.c32
DVD Image DVD:/images/pxeboot/vmlinuz (Kernel)
DVD:/images/pxeboot/initrd.img (Initial RAM Disk)
httpd /etc/httpd.conf


Associated Files

/var/lib/tftpboot/pxelinux.0 pxelinux.0 is a pxe configuration file.
/var/lib/tftpboot/menu.c32
/var/lib/tftpboot/pxelinux.cfg/default PXE Menu File
/var/lib/tftpboot/centosXXX/vmlinuz copy from iso:/images/pxeboot/vmlinuz
/var/lib/tftpboot/centosXXX/initrd.img copy from iso:/images/pxeboot/initrd.img


Setup

TFTP Server

Installing

yum install tftp-server

/etc/xinetd.d/tftp

service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot
        disable                 = no                     <- Change from 'yes' to 'no'
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
# systemctl restart xinetd


DHCP

Install

yum install dhcp

/etc/dhcpd.conf

ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {
        option routers                  192.168.0.1;        <- GW
        option subnet-mask              255.255.255.0;

        option nis-domain               "domain.org";
        option domain-name              "domain.org";
        option domain-name-servers      192.168.0.10;       <- DNS Server's IP
        filename "pxelinux.0";    <- Program to be initially loaded
                                            Example: /var/lib/tftpboot/pxelinux.0

        range dynamic-bootp 192.168.0.128 192.168.0.254;
        default-lease-time 21600;
        max-lease-time 43200;
}
# systemctl restart dhcpd


copy files in ISO

/var/lib/tftpboot/

              centos5.4/
                         initrd.img
                         vmlinuz

              centos6.7/
                         initrd.img
                         vmlinuz

              centos7/
                         initrd.img
                         vmlinuz

              debian7.4/
                        boot-screens
                        initrd.gz
                        linux
                        pexelinux.0
                        pxelinux.cfg/default

/var/www/html/repo
                centos6.7
                centos7
# mount -o loop /tmp/CentOS-7-x86_64-Minimal-1503-01.iso /mnt

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

# mkdir -p /var/www/html/repo/centos7
# cp -r /mnt/* /var/ww/html/repo/centos7/


syslinux

Install

yum install syslinux syslinux-tftpboot

Check pxelinux.0 and menu.c32

# ls -l /var/lib/tftpboot/pxelinux.0
# ls -l /var/lib/tftpboot/menu.c32

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

default menu.c32
timeout 100

MENU TITLE ****  PXE Boot Menu  ****

label 1
        MENU LABEL ^1. Boot from Local HDD
        localboot 1

label 2
        MENU LABEL ^2. Install CentOS 5.4
        kernel centos5.4/vmlinuz
        append load initrd=centos5.4/initrd.img inst.repo=http://xx.xx.xx.xx/repo/centos5.4/

label 3
       menu label ^3) install centos 7
       kernel centos7/vmlinuz
       append load initrd=centos7/initrd.img ks=http://xx.xx.xx.xx/ks/centos7-ks.cfg


label 9
   menu label ^9) Boot from local drive
   localboot 


Apache httpd

Install

# yum install httpd
# systemctl restart httpd


How to boot

/tftpboot/linux-install/pxelinux.cfg/default

Example1 : http

default linux
prompt 0                <- '0' is defalt boot. '1' is boot pronpt.
timeout 100             <- 100ms = 10sec


label linux
kernel vmlinuz

#kickstart file is ks.cfg
append ks=http://192.168.0.10/ks.cfg noipv6 load initrd=initrd.img devfs=nomount