Wednesday, November 10, 2010

Boot Linux kernel from PXE Server

It is nice and easy if we can setup an environment to perform installation of Linux via high speed LAN. The most usual method I install Linux is to burn a small boot ISO file to CDRW and use the CDRW disc to start the installation via HTTP or FTP. I learn from PXELinux and found it is a nice option to try. To setup a Linux machine via LAN, you need the following:
  1. A DHCP server that support BOOTP
  2. TFTP Server
  3. PXELinux kernel boot file
  4. Linux installation ISO file

PXELinux

You may obtain PXE Linux Boot Kernel file from http://www.kernel.org/pub/linux/utils/boot/syslinux/

Download the version of SYSLINUX you prefer and extract the tar file.  The PXE Linux Boot Kernel file name is pxelinux.0.

You should copy the pxelinux.0 to root directory of TFTP service.

DHCP Configuration

Add the following setting to dhcpd.conf to enable BOOTP

allow booting;
allow bootp;

range dynamic-bootp 192.168.0.221 192.168.0.230;
next-server 192.168.0.2;
filename "pxelinux.0";

next-server is the server of TFTP server.

TFTP Server

# Install TFTP server

yum install tftp-server

After installation,  you may proceed to TFTP configuration.  The configuration file is located at /etc/xinetd.d/tftp

TFTP Server Configuration – Enable the service

service tftp
{
        disable = no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

TFTP Server Configuration – Firewall

-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT

TFTP Server Configuration – Log activities

Log activities of TFTP server Edit file /etc/xinetd.d/tftp and add "-v" option to tftpd. The flag can be specified multiple times for even higher verbosity.  You need to restart xinetd service to activate tftp logging.  The log details for TFTP may found in /var/log/messages.

service tftp
{
        disable = no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -v –v –s /var/lib/tftpboot
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

TFTP Server – Restart service

# /sbin/service xinetd restart

A useful example of using the log is to see what files are requested by PXE client when serving Microsoft Windows boot loader. File names are always case sensitive in TFTP operation.

TFTP Server – File name remapping

Microsoft windows or DOS use backslash (\) for folder separator. It always cause problem in those TFTP server running on Linux OS where forward slash (/) is used as folder separator. When serving windows boot loader, we may encounter the situation of we keep the boot loader files in folders. To solve this problem, we may use the file name remapping option available in tftp service.

service tftp
{
        disable = no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -v -m /var/lib/tftpboot/rules -s /var/lib/tftpboot
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

# vi /var/lib/tftpboot/rules
rg \\ /         # convert backslashes to slashes (useful for windows file names)

PXELinux boot menu

You may configure PXE boot menu in tftpboot/pxelinux.cfg

DEFAULT menu.c32
PROMPT 0

LABEL FC13.x86_64
        menu label Linux Fedora Core 13 x86_64 (ftp://bee/fc13.x86_64)
        KERNEL fc13.x86_64/vmlinuz
        APPEND initrd=fc13.x86_64/initrd.img

You should copy the kernel and initrd file from ISO images/pxeboot directory to tftpboot folder.

Boot PXE from client

Once the PXE server is up and ready, you may configure the client machine for network boot.  This is usually configure via BIOS setup while start the machine.  If the PXE server is setup properly, the PXE boot menu will load and you may start using PXE boot service.

Reference

    1. http://syslinux.zytor.com/wiki/index.php/PXELINUX