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 "172.16.1.10";  
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 192.0.2.91
192.0.2.91 192.0.2.91 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 192.0.2.91, it will try:
/tftpboot/pxelinux.cfg/01-88-99-aa-bb-cc-dd
/tftpboot/pxelinux.cfg/C000025B
/tftpboot/pxelinux.cfg/C000025
... 
/tftpboot/pxelinux.cfg/C
/tftpboot/pxelinux.cfg/default
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
/usr/lib/syslinux/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 172.16.1.128
172.16.1.128 172.16.1.128 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=http://172.16.1.10/pxe/centos.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
DEFAULT menu
PROMPT 0
MENU TITLE Select a boot option
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local

LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT 0

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=http://172.16.1.10/pxe/centos.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=http://172.16.1.10/pxe/centos.ks ksdevice=link
MENU end

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

#Edit dhcpd configuration file
#The client OS is assigned  an fixed IP “172.16.1.128” 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 172.16.1.0 netmask 255.255.255.0 {
# --- default gateway
option routers                  172.16.1.254;
option subnet-mask              255.255.255.0;
option domain-name              "example.com";
option domain-name-servers      172.16.1.10;
range dynamic-bootp 172.16.1.128 172.16.1.200;
#time unit is 1 sec
default-lease-time 21600;
max-lease-time 43200;
next-server 172.16.1.10;
filename "pxelinux.0";
host host1 {
hardware ethernet 08:00:27:9b:ac:9b;
fixed-address 172.16.1.128;
}
} 
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”
image

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

image

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.