Vous êtes sur la page 1sur 7

HOW TO CONFIGURE PXE BOOT SERVER IN LINUX

PXE is an abbreviation for Reboot execution Environment which describes a client server standardized
environment to boot from a network a software assembly on a client i.e. an Operating System. It is also
pronounced as "pixie" and is mostly used to boot the client machine with a installation media stored on
the PXE server using network interface.

In this article I will show you step by step guide to configure a PXE boot server using http and
ftp in which you can use either one suiting your requirement.

I will be using Red Hat Linux 6 (32-bit) for my purpose

Server IP: 192.168.1.42

Pre-requisites

dhcp
tftp-server
syslinux
http/ftp (any one)

Install the required packages using yum

[root@ldap ~]# yum -y install dhcp tftp-server syslinux http ftp vsftpd

Prepare installation media on PXE server

Next we need to copy all the files from the installation media(CD/DVD,ISO) to our PXE server.

You can also mount the media file on the PXE server in case you don't want to copy all the files
but using that way you will only be able to configure your PXE server for one OS. For
configuring multiple OS you will have to copy the OS files into separate directory for different
OS.

In my case I want to configure a PXE server to install CentOS 6.2

Let us create separate directory to save all the installation files


# mkdir -p /var/lib/tftpboot/images/centos/6/i386/
# mkdir -p /var/lib/tftpboot/images/centos/6/x86_64/

Next copy the installation files from the installation media. If you have iso images of the OS you
can use WinSCP(on windows) to copy all the files. If the image is mounted on your Linux
machine then you can copy using scp command.

To skip the lengthy process as of now we will just mount the dvd to relevant destination.
# mount /dev/sr0 /var/lib/tftpboot/images/centos/6/i386/
mount: block device /dev/sr0 is write-protected, mounting read-only
NOTE: In my case the cdrom is mounted on /dev/sr0 which can be different for you.

Mount DVD to /mnt & copy all file below directive

[root@ldap ~]# cp -vr /mnt/* /var/lib/tftpboot/images/centos/6/i386/


[root@ldap ~]# cp -vr /mnt/* /var/lib/tftpboot/images/centos/6/x86_64/

Configure HTTP server

[root@ldap ~]# vim /etc/httpd/conf/httpd.conf

NameVirtualHost *:80

<VirtualHost 192.168.19.71:80>
ServerAdmin webmaster@ldap.server.com
DocumentRoot /var/lib/tftpboot/images
ServerName ldap.server.com
ErrorLog logs/ldap.server.com-error_log
CustomLog logs/ldap.server.com-access_log common
</VirtualHost>
<Directory /var/lib/tftpboot/images>
AllowOverride None
Options Indexes FollowSymlinks
Order allow,deny
Allow from all
</Directory>
Restart the httpd services & on service on bootup system

[root@ldap ~]# /etc/init.d/httpd restart


Stopping httpd: [ OK ]
Starting httpd [ OK ]

[root@ldap ~]# chkconfig httpd --level 35 on ; chkconfig --list httpd


httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off

Manually browse to the server ip and verify if you can see all the files.

http://192.168.19.71/centos/6/i386/

http://192.168.19.71/centos/6/x86_64

Configure FTP server

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

Restart the VSFTPD services & on service on bootup system

[root@nagios ~]# /etc/init.d/vsftpd restart


Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]

[root@ldap ~]# chkconfig vsftpd --level 35 on ; chkconfig --list vsftpd


vsftpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
Configure TFTP server

Once these packages are installed copy the below files from the specified directory to
/var/lib/tftpboot

# 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/

Next we will create the configuration file required for tftp server

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

Create a new file "default" under "/var/lib/tftpboot/pxelinux.cfg" and add


the below entry

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

MENU TITLE PXE Menu

MENU seperator
LABEL CentOS 6.2
KERNEL images/centos/6/x86_64/images/pxeboot/vmlinuz
APPEND initrd=images/centos/6/x86_64/images/pxeboot/initrd.img
method=http://192.168.19.71/centos/6/x86_64 devfs=nomount

MENU seperator
LABEL Local
LOCALBOOT 0Here two things which you need to change

KERNEL - defines the location from where the PXELINUX bootloader will load
APPEND - defines the location for PXE initrd image file to load
For FTP server
There is not much change for ftp server just replace the below line in the above file
APPEND initrd=images/centos/6/i386/images/pxeboot/initrd.img

method=ftp://192.168.19.71/centos/6/i386 devfs=nomount

Enable the tftp service in xinetd

Next we will create the configuration file required for tftp server

[root@ldap ~]# vim /etc/xinetd.d/tftp


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
}

Restart the relevant services

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


Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@ldap ~]# chkconfig xinetd --level 35 on ; chkconfig xinetd --list
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
Configure DHCP server

[root@ldap ~]# cat /etc/dhcp/dhcpd.conf


ddns-update-style none;
authoritative;
log-facility local7;
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.19.255;
option routers 192.168.19.1;
subnet 192.168.19.0 netmask 255.255.255.0 {
range 192.168.19.131 192.168.19.140;
}

next-server 192.168.19.71;
filename "pxelinux.0";

IMPORTANT NOTE: In your dhcp server make sure you add these lines
next-server 192.168.19.71;
filename "pxelinux.0"; as these define the address of your tftp server and the file to
look for after getting the IP Address from dhcp server

Restart the relevant services

[root@ldap ~]# /etc/init.d/dhcpd restart


Shutting down dhcpd: [ OK ]
Starting dhcpd: [ OK ]
[root@ldap ~]# chkconfig dhcpd --level 35 on ; chkconfig dhcpd --list
dhcpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
Iptables rules

For DHCP server


# iptables -I INPUT -m state --state NEW -p udp --dport 69 -j ACCEPT
For HTTP server
# iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
For FTP server
# iptables -I INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
You are all set to test your PXE server. Boot a machine and select the option of Network Boot
from Bios. You should see the below screen