Monday, 6 July 2015

how to configure pxe boot in linux

 Preboot Execution Environment (PXE)
here I am going to configure pxe server in linux centos6.6 (or) RHEL6.6  
 Server IP: 172.66.0.224
 Subnet 
Mask:255.255.255.0
 Server Hostname: server.example.in

Pre-requisites for configuring a PXE Server

     Step 1:- First configure dhcp server for dynamic ip allocation
     Step 2:- Http (or) FTP server
     Step 3:- tftp-server configuration [ Trivial File Transfer Protocol ]
  Disable Selinux

[root@server~]vim /etc/sysconfig/selinux

SELINUX=disabled

Check whether selinux is diabled or not
[root@server ~]# getenforce
Disabled

[root@server ~]# chkconfig iptables off


[root@server ~]# service iptables stop


Then Install the required packages
# yum -y install dhcp tftp-server syslinux http ftp vsftpd
[root@server ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
option domain-name "example.in";
option domain-name-servers server.example.in;
default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 172.66.0.0 netmask 255.255.255.0 {
range dynamic-bootp 172.66.0.10 172.66.0.25;
option broadcast-address 172.66.0.255;
option routers 172.66.0.1;

  allow booting;
        allow bootp;

        next-server 172.66.0.224;
        filename "pxelinux.0";
}

# service dhcpd restart
Shutting down dhcpd:                                       [  OK  ]
Starting dhcpd:                                                  [  OK  ]
 

create separate directory to save all the installation files

# mkdir -p /var/lib/tftpboot/images/rhel6

Prepare installation media on PXE server

# mount /dev/sr0 /var/lib/tftpboot/images/rhel6

 (or)


If you have an iso file, just mount it on this newly created directory using this command

[root@server ~]# mount -t iso9660 -o loop /ISOS/rhel-server-6.6-x86_64-dvd.iso
/var/lib/tftpboot/images/rhel6/

Configure HTTP/FTP server

HTTP server

Go To Line NO :262
ServerAdmin root@server.example.in

Go To Line NO :276
ServerName server.example.in:80
Go To Line NO :292
DocumentRoot "/var/lib/tftpboot/images"

<VirtualHost 172.66.0.224:80>
    ServerAdmin root@server.example.in
    DocumentRoot /var/lib/tftpboot/images
    ServerName server.example.in
</VirtualHost>

<Directory /var/lib/tftpboot/images>
AllowOverride None
Options Indexes FollowSymlinks
Order allow,deny
Allow from all
</Directory>

# /etc/init.d/httpd restart
Manually browse this url
http://172.66.0.224/rhel6

# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
anon_root=/var/lib/tftpboot/images

# /etc/init.d/vsftpd restart

Manually browse this url
ftp://172.66.0.224/rhel6

Configure TFTP server
# cp /usr/share/syslinux/pxelinux.0     /var/lib/tftpboot/
# cp /usr/share/syslinux/chain.c32     /var/lib/tftpboot/
# cp /usr/share/syslinux/menu.c32     /var/lib/tftpboot/
# cp /usr/share/syslinux/memdisk     /var/lib/tftpboot/
# cp /usr/share/syslinux/mboot.c32     /var/lib/tftpboot/

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

# vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
TIMEOUT 100
ONTIMEOUT Local

MENU TITLE PXE Menu

MENU seperator
LABEL RHEL 6.6
KERNEL images/rhel6/images/pxeboot/vmlinuz
APPEND initrd=images/rhel6/images/pxeboot/initrd.img
method=http://172.66.0.224/rhel6 devfs=nomount
APPEND initrd=images/rhel6/images/pxeboot/initrd.img
method=ftp://172.66.0.224/rhel6 devfs=nomount

[root@server ~]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
#      protocol.  The tftp protocol is often used to boot diskless \
#      workstations, download configuration files to network-aware printers,
#      \
#      and to start the installation process for some operating systems.
service tftp
{
        socket_type              = dgram
        protocol            = udp
        wait                  = yes
        user                  = root
        server                       = /usr/sbin/in.tftpd
        server_args              = -s /var/lib/tftpboot
        disable                      = no
        per_source               = 11
        cps                   = 100 2
        flags                 = IPv4
}
[root@server ~]# /etc/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]Configure DHCP server


[root@server ~]# chkconfig dhcpd on
[root@server ~]# chkconfig httpd on
[root@server ~]# chkconfig xinetd on
[root@server ~]# chkconfig vsftpd on



 Next we have to test your PXE server by boot a machine & select the option “Network Boot” from bios
Finally You should see the screen like this 








If you want to configure PXE with Kickstart Please follow with these step:- 



[root@server ~]# mkdir /var/lib/tftpboot/images/Kickstart



[root@server ~]# cp /root/anaconda-ks.cfg /var/lib/tftpboot/images/Kickstart/rhel-ks.cfg



[root@server ~]# chmod 644 /var/lib/tftpboot/images/Kickstart/rhel-ks.cfg



[root@server ~]# openssl passwd -1

Password:
Verifying - Password:
$1$A83yvaDO$y8kao5aS1FrDxWjl50o9c1

[root@server ~]# vim /var/lib/tftpboot/images/Kickstart/rhel-ks.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.66.0.224/rhel6"
# Root password
rootpw --iscrypted $1$tsz92mVC$.gXLh0Wu8PdmF5LvCFNG9.
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Asia/Kolkata
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all  
# Disk partitioning information
part / --fstype="ext4" --size=10000
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=1000

%packages
@basic-desktop
@desktop-debugging
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@legacy-x
@remote-desktop-clients
@x11
abrt-gui
alacarte
audit-viewer
bitmap-fixed-fonts
bitmap-lucida-typewriter-fonts
bltk
byzanz
cjkuni-fonts-ghostscript
dvgrab
firstaidkit-gui
freerdp
gconf-editor
gedit-plugins
gnome-games
gnome-pilot
gnome-pilot-conduits
krb5-auth-dialog
libXmu
libXp
openmotif
openmotif22
oprofile-gui
pcp
policycoreutils-gui
qt-mysql
qt-odbc
qt-postgresql
qt3-MySQL
qt3-ODBC
qt3-PostgreSQL
rdesktop
rhythmbox-upnp
sabayon
sabayon-apply
seahorse-plugins
setroubleshoot
spice-client
spice-xpi
system-config-kickstart
system-config-lvm
tigervnc
tigervnc-server
totem-upnp
tsclient
vim-X11
vinagre
wireshark-gnome
xcb-util-image
xcb-util-keysyms
xcb-util-wm
xguest
xorg-x11-fonts-75dpi
xorg-x11-fonts-ISO8859-1-75dpi
xorg-x11-fonts-ISO8859-14-100dpi
xorg-x11-fonts-ISO8859-14-75dpi
xorg-x11-fonts-ISO8859-15-75dpi
xorg-x11-fonts-ISO8859-2-100dpi
xorg-x11-fonts-ISO8859-2-75dpi
xorg-x11-fonts-ISO8859-9-100dpi
xorg-x11-fonts-ISO8859-9-75dpi
xorg-x11-fonts-cyrillic
xorg-x11-fonts-ethiopic
xorg-x11-twm
xorg-x11-xdm
xrestop
xterm

%end

[root@server ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
TIMEOUT 100
ONTIMEOUT Local

MENU TITLE PXE Menu

MENU seperator
LABEL RHEL 6.6
KERNEL images/rhel6/images/pxeboot/vmlinuz
#APPEND initrd=images/rhel6/images/pxeboot/initrd.img
method=http://172.66.0.224/rhel6 devfs=nomount
#APPEND initrd=images/rhel6/images/pxeboot/initrd.img
method=ftp://172.66.0.224/rhel6 devfs=nomount
APPEND initrd=images/rhel6/images/pxeboot/initrd.img
ks=http://172.66.0.224/Kickstart/rhel-ks.cfg ksdevice=eth0


Restart the Xinetd Service

[root@server ~]# /etc/init.d/xinetd restart

Stopping xinetd:  [ OK ]
Starting xinetd:    [ OK ]



Whatever machines you want to install OS boot a machine & select the option called “Network Boot” from bios
After booting it will show you a Screen like this