Monday, 20 August 2012

Installing and Configuring PXE Boot for CentOS

Installing and Configuring PXE Boot for CentOS


In our PREVIOUS ARTICLE we talked about how to set up the network for our PXE Boot environment.

Now let's continue with the actual installation and configuration part.

Power ON the new CentOS VM and make a note of the hostname as well as the VM's IP address.

NOTE: The IP Address in this case is the first IP from the DHCP settings of our VMware Network Editor (PREVIOUS ARTICLE)

Run the following Commands:

# hostname
# ifconfig

Next, make sure that the CentOS ISO is mounted to the VM and available for use. Type in the command mount and check the output. You should see the ISO mounted as shown below:

# mount

For this tutorial, I have actually created a local CentOS Repository for installing the required packages as my network doesn't connect to CentOS's online update mirrors (NO Internet !!)

If you face the same issue, you can create your own CentOS Local Repo by following the instructions HERE.

If you have Internet connectivity, then just carry on with the steps as shown below.

We will first install the DHCP Server

# yum install dhcp

Once installed, we need to configure the DHCP. To do so, type in the following command:

# vi /etc/dhcpd.conf

In this file, add the following lines as suited to your network. (PLS DO NOT BLINDLY COPY PASTE.. You will have to make the necessary IP changes wherever required)

   ddns-update-style interim
   ignore client-updates

    # Set the DNS server to be used by the
    # DHCP clients.
        option domain-name "CLOUD.LAB";
        option domain-name-servers;

    # Set the Subnet mask
       option subnet-mask;

       subnet netmask {


         # The range of IP addresses the server
         # will issue to DHCP enabled PC clients
         # booting up on the network

         # Following parameters are required for the PXE Boot 
               allow unknow-clients;
               allow booting;
               allow bootp;

         # PXE directives
               filename "pxelinux.0";

The above assumes that the network of your PXE Boot Server is, so replace that value with what ever value is either assigned to your NIC or that you want assigned to your NIC.

"next-server" is used to tell the clients where to go for the PXE boot process. So if you wanted to stand up a DHCP server separate from your TFTP/PXE server, you would change "next-server" to the IP address of the TFPT/PXE server. In our case, we are using them on the same machine.

Notice that in domain-name-servers I used Although I don't have a DNS running on this IP, you can still provide a dummy value to this, or provide your actual DNS IP as well.

With this, we have configured our DHCP for PXE Boot.
NOTE: If there are any issues in your DHCP conf file, then you will not be able to start the service successfully. It will prompt you errors.

Next, install the TFTP Server with the following command:

# yum install tftp-server

Once the TFTP Server is installed, we need to make one change in its configuration file. Type the following command:

# vi /etc/xinetd.d/tftp

In this file, change the value of "disable" to NO as shown.

Now that you are done configuring the TFTP Server, we now start with the actual PXE Boot setup.

In your root (/) directory, make a new directory called tftpboot

NOTE: In some cases, this folder will have been already created. In that case, ignore the warning.

Subsequently, within tftpboot, we create sub-directories called images and pxelinux.cfg

We then apply read/ write permission to the tftpboot directory as shown below:

# mkdir /tftpboot
# mkdir /tftpboot/images
# mkdir /tftpboot/pxelinux.cfg
# chmod -R 777 /tftpboot/

Copy the following files from /usr/lib/syslinux folder and place them in the tftpboot folder as shown:

# cp /usr/lib/syslinux/pxelinux.0 /tftpboot
# cp /usr/lib/syslinux/menu.c32 /tftpboot
# cp /usr/lib/syslinux/memdisk /tftpboot
# cp /usr/lib/syslinux/mboot.c32 /tftpboot
# cp /usr/lib/syslinux/chain.c32 /tftpboot

Once the necessary files have been copied over, create a new file called "default" under /tftpboot/pxelinux.cfg directory.

vi /tftpboot/pxelinux.cfg/default
Add the following text in the new file:

default menu.c32
prompt 0
timeout 600
MENU TITLE ###### PXE Boot Menu #######

This is the very basic PXE Boot Menu that you just wrote out. We will populate things into it in the coming steps.

We now create a base directory for the OS images. 

NOTE: Create directories for each OS release you are supporting. I am using CentOS in this case, so creating a "centos" named directory in /tftpboot/images

NOTE: For each "Release" and "ARCH" of your desired OS, copy "vmlinuz" and "initrd.img" from the ISO directory of that $Release/$ARCH to /tftpboot/images/$OS/$RELEASE/$ARCH as shown below:

# mkdir -p /tftpboot/images/centos/5/x86_64

Now, copy the initrd.img file from the mounted CentOS ISO to the specific folder in /tftpboot directory
# cp /media/CentOS_5.8_Final/images/pxeboot/initrd.img /tftpboot/images/centos/5/x86_64/

Do the same for the vmlinux file as well

# cp /media/CentOS_5.8_Final/images/pxeboot/vmlinux /tftpboot/images/centos/5/x86_64/

You should have both these files present now in /tftpboot/images/centos/5/x86_64/ directory as shown:

Now that that's done, we now copy the entire ISO content to the HDD, such that when the client boots using PXE, this ISO is made available to it from the PXE Server

To do so, follow the following steps:

# cd /var/www/html
# mkdir CentOS

Copy the contents of your mounted ISO to this folder
# cp -R /media/CentOS_5.8_Final/* CentOS/

NOTE: This copy operation will take time as the entire ISO contents are getting copied to HDD. Be patient !! Once done, you will be able to see the entire structure of the ISO as shown below::

We now prepare the Apache Server. This Apache Server will server as the medium through which the copied ISO content (previous step) will be provided to the new VM once it boots using the PXE Menu.

Edit the following file:

# vi /etc/httpd/conf/httpd.conf

In this file, make changes ONLY in two places.




Save the file once you are done editing.

Restart the httpd service

# service httpd restart

NOTE: If there are any errors in your httpd.conf file, the service will not start up correctly.

To check whether the Apache Server started correctly, open a browser window and type in the PXE Server's IP Address. You should see a Apache Test Page presented to you. If you prefix the IP address with the CentOS folder that we created and copied the ISO contents into, then you should see the entire ISO contents as shown below:

This means that the Apache server is configured correctly.

Coming back to the /tftpboot/pxelinux.cfg directory, we will now add the necessary values to boot a CentOS 5.8 VM using PXE Boot

Append the following text to the existing "default" file

LABEL CentOS 5 (DVD - 64-BIT)
KERNEL images/centos/5/x86_64/vmlinuz
APPEND vga-=normal initrd=images/centos/5/x86_64/initrd.img
method=http://<YOUR PXE SERVER IP>/CentOS ip=dhcp
url --url http://<YOUR PXE SERVER IP>/CentOS
NOTE: There is no "enter" in the APPEND line.. its a continuous statement

Save the file and exit.

Restart the DHCP, the Apache and the PXE Service

# service httpd restart
# service dhcpd restart
# service xinetd restart

With this, we are now ready with our PXE Server. The NEXT STEPs will show you how to actually boot using this PXE Server and finally, Automate your Linux installations using KickStart.

No comments :

Post a Comment

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