• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • Life always offers you a second chance ... Its called tomorrow !!!

    Tuesday, August 05, 2014

    How to configure PXE boot server in Linux using Red Hat 6

    PXE is an abbreviation for Preboot 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.6

    Pre-requisites

    • dhcp
    • tftp-server
    • syslinux
    • http/ftp (any one)
    Install the required packages using yum
    # 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 confiure 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 lenghty 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.

    Configure HTTP/FTP server

    You can use either of the mentioned servers for your purpose. But I will show you the configuration of all three so that you can choose any one as per your requirement.

    HTTP server
    # vi /etc/httpd/conf/httpd.conf
    At the end of the file add the following lines
    <VirtualHost 192.168.1.6:80>
        ServerAdmin root@test.example.com
        DocumentRoot /var/lib/tftpboot/images
        ServerName test.example.com
        ErrorLog logs/test.example.com-error_log
        CustomLog logs/test.example.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
    # service httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]

    Manually browse to the server ip and verify if you can see all the files.
    http://192.168.1.6/centos/6/i386/

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

    Manually browse to the server ip and verify if you can see all the files.
    ftp://192.168.1.6/centos/6/i386/

    Restart the services
    # /etc/init.d/vsftpd restart
    Shutting down vsftpd:                                      [  OK  ]
    Starting vsftpd for vsftpd:                                [  OK  ]

    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

    For HTTP server
    # 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/i386/images/pxeboot/vmlinuz
    APPEND initrd=images/centos/6/i386/images/pxeboot/initrd.img method=http://192.168.1.6/centos/6/i386 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.1.6/centos/6/i386 devfs=nomount

    Enable the tftp service in xinetd
    # vi /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
    # /etc/init.d/xinetd restart
    Stopping xinetd:                                           [  OK  ]
    Starting xinetd:                                           [  OK  ]

    Configure DHCP server

    # vi /etc/dhcp/dhcpd.conf
    option domain-name "example.com";
    option domain-name-servers test.example.com;
    default-lease-time 600;
    max-lease-time 7200;
    authoritative;

    subnet 192.168.1.0 netmask 255.255.255.0 {
    range dynamic-bootp 192.168.1.20 192.168.1.25;
    option broadcast-address 192.168.1.255;
    option routers 192.168.1.1;

      allow booting;
            allow bootp;

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

    IMPORTANT NOTE: In your dhcp server make sure you add these lines
            next-server 192.168.1.6;
            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
    # service dhcpd restart
    Shutting down dhcpd:                                       [  OK  ]
    Starting dhcpd:                                            [  OK  ]

    Make sure the services start after reboot
    # chkconfig httpd on
    # chkconfig xinetd on
    # chkconfig dhcpd on

    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


    Related Articles:
    What are the different types of Virtual Web Hosting in Apache
    VSFTPD configuration
    How to configure DHCP in Linux

    Follow the below links for more tutorials

    What is the difference/comparison between Unix and Linux ?
    What are the maximum and minimum limits for RHEL 4 vs 5 vs 6 ?
    Step by Step Linux Boot Process Explained In Detail
    What is the difference between ext3 and ext4 filesystem in Linux ?
    How to configure Private Network in VMware Workstation
    10 examples to help you understand top command usage in Unix/Linux
    Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler
    Tutorial for Monitoring Tools SAR and KSAR with examples in Linux
    15 tips to enhance security of your Linux machine
    Why is Linux more secure than windows and any other OS
    Understanding Load Average in Linux and when to be worried about it?
    Disk Attachment Technology FC vs SAS vs iSCSI
    Understanding UMASK value in Linux
    How to keep a track of all the commands run by any user in Linux
    How do you check Linux machine is Physical or Virtual remotely?
    RAID levels 0, 1, 2, 3, 4, 5, 6, 0+1, 1+0 features explained in detail

    13 comments:

    1. Hi Deepak,

      i have facing this issue " Unable to retrieve ftp://192.168.1.6/centos/6/images/install.img"

      How to resolve this issue

      ReplyDelete
      Replies
      1. Try to access the page on your browser or using ftp client using proper authentication which is used in the configuration and see if you are getting any error to do the same.

        Check your firewall and selinux
        Look out in the logs for any hint which can guide you towards the issue.

        Delete
    2. hi
      am using rhel6.2....i got a warning message while i am starting the httpd service..../var/lib/tftp/images does not exist......but I hae the directory and mount iso to that directory....let me know what is the problem behind this....

      ReplyDelete
      Replies
      1. My wild guess could be...In case you are following my article, I used /var/lib/tftpboot/images instead of /var/lib/tftp/images.

        So are you sure you have used the directory names properly?

        Delete
    3. Thans for your reply...Actually there is a problem in SELinux policy Permission mentioned in /var/log/messages...I cleared it by generating a local policy module....But There is an another problem...I completed all the steps you have mentioned and my client system get dhcp ip and get pxe boot menu...but it is not booting the os,after timeout it is booting from local drive...what is the problem?

      ReplyDelete
      Replies
      1. Are you able to access your files on http or ftp server as per the permission provided?

        Check your firewall and selinux properly.

        Delete
    4. In Linux PXE, Can we upload Windows ISO Images? and do Windows OS Installations?

      ReplyDelete
      Replies
      1. I have never tried so cannot say 100% but I believe it should work when you copy the installation files and provide the source location. You can try and let us know as well.

        Thanks

        Delete
    5. Hi Deepak & Tamil Selvan,

      i have facing this issue " Unable to retrieve ftp://192.168.1.6/centos/6/images/install.img"

      How to resolve this issue

      please step by step solution.

      ReplyDelete
    6. Hi Meepak,
      mount /dev/sr0 /var/lib/tftpboot/images/centos/6/i386/
      mount: block device /dev/sr0 is write-protected, mounting read-only

      but operating system not found.
      please help me.

      ReplyDelete
    7. Hi Deepak,

      Please post the KICKSTART configuration also.

      Thanks in advance.

      ReplyDelete
      Replies
      1. Hi achal, you can use system-config-kickstart in redhat and centos on GUI

        it will guide you step by step towards creating your own kickstart file.... use /root/anaconda-ks.cfg as reference

        Delete
    8. Hi Deepak,

      Please post KICKSTART configuration also step by step.

      Thanks

      ReplyDelete