Saturday, June 18, 2011

Setup PXE Boot Server for Linux Server Provisioning

PXE is Preboot eXecution Environment, for PXE to work, NIC and BIOS must both support PXE (Virtualbox pcnet type adapter supports pxe boot)
PXE boot server components
- DHCP Server    #assign ip address and redirect to tftp Server
- tftp Server         #download boot loaders and configuration file
- syslinux      #provides stage1 boot loader pxelinux.0, which  is installed in boot  server, independent of the OS to be provisioned
The PXE boot process
1. NIC requests DHCP information (DHCP DHCPDISCOVER to port 67/UDP)
2. DHCP server provides bootloader name and IP of tftp server
#relevant DHCP config
nextsever "";  
filename "pxelinux.0";
3. NIC uses tftp to fetch bootloader into RAM(tftp tftp-server -c get pxelinux.0)
4. BIOS executes bootloader
5. Bootloader uses tftp to find and retrieve configuration file in following order:
        [5.1] MAC address using hex and dashes, prefaced with ARP type code
        [5.2] IP address expressed in hex
#Convert decimal to hex by gethostip command
$gethostip C000025B
[5.3]Strips one digit of hex IP at a time from the right-hand side until file is found
[5.4]Last attempt is default
As an example, if the boot file name is /tftpboot/pxelinux.0, the Ethernet MAC address is 88:99:AA:BB:CC:DD and the IP  address, it will try:
6. Bootloader load kernel: vmlinuz and initrd.img defined in the configuration file retrieved.
Install PXE Boot Server components
The setup procedure is demonstrated in Centos 5
$yum install tftp dhcp syslinux
tftp  configuration is  /etc/xinetd.d/tftp  and controlled by  /etc/init.d/xinetd
Prepare  tftp directory structure  and populate initial files
$mkdir -p /tftpboot/{pxelinux.cfg,centos-i686-5.5}
pxelinux.cfg                #The directory for client OS configuration files
centos-i686-5.5           #An optional directory to hold vmlinuz, initrd.img specific to a Linux release 

#find pxelinux.0 on PXE boot Server and copy it to tftpboot
$rpm -ql syslinux | grep pxelinux.0
$cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
$cp /usr/lib/syslinux/menu.c32   /tftpboot/

#Copy vmlinuz and initrd.img in installation media for the client OS to be provisioned
$cp /media/cdrom/images/pxeboot/{initrd.img,vmlinuz} /tftpboot/centos-i686-5.5
Create PXE configuration file for client OS
#Derive the configuration file name from the ip to be assigned to client OS
$gethostip AC100180

#Edit config file
#reference: /usr/share/doc/syslinux*/syslinux.doc
#sample config: /media/cdrom/isolinux/isolinux.cfg
$vi /tftpboot/pxelinux.cfg/AC100180
default linux
prompt 1
#timeout in units of 1/10 s.
timeout 20
#dsplay boot.msg
label linux
kernel centos-i686-5.5/vmlinuz
append initrd=centos-i686-5.5/initrd.img ks= ksdevice=link

#if no config for the host defined, default to boot from none-pxe media
$vi /tftpboot/pxelinux.cfg/default
default normal
prompt 0
label normal
localboot 0
##instead of above method,loading specific kernel based on individual config, You can have only one default config, let user choose which kernel to load.
$ cat /tftpboot/pxelinux.cfg/default
MENU TITLE Select a boot option

LABEL local
MENU LABEL (local)

LABEL centos-i686-5.5
kernel /centos-i686-5.5/vmlinuz
MENU LABEL centos-i686-5.5
append initrd /centos-i686-5.5/initrd.img ks= ksdevice=link

LABEL centos-x86_64-5.5
kernel /centos-x86_64-5.5/vmlinuz
MENU LABEL centos-x86_64-5.5
append initrd=/centos-x86_64-5.5/initrd.img ks= ksdevice=link
MENU end

Setup DHCP Server
#Activate dhcpd  on specific NIC only.
$vi /etc/sysconfig/dhcpd

#Edit dhcpd configuration file
#The client OS is assigned  an fixed IP “” based on mac address, which can be #retrieved in /var/log/messages when client  boot  from pxe the first time.
$cat /etc/dhcpd.conf
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
ddns-update-style interim;
ignore client-updates;
subnet netmask {
# --- default gateway
option routers        ;
option subnet-mask    ;
option domain-name              "";
option domain-name-servers;
range dynamic-bootp;
#time unit is 1 sec
default-lease-time 21600;
max-lease-time 43200;
filename "pxelinux.0";
host host1 {
hardware ethernet 08:00:27:9b:ac:9b;
Start dhcp server
$service dhcp start
Boot Client
Change boot order in BIOS to prefer network boot and power on the Server to be provisioned
- Client boots up automatically after finding configuration file  “AC100180”

 - Client without its configuration file found, waiting for user’s input


No comments:

Post a Comment