Setting Up a PXE Server on an RPM-based OS

From Alteeve Wiki
Revision as of 18:29, 12 August 2010 by Digimer (talk | contribs)
Jump to navigation Jump to search

 AN!Wiki :: How To :: Setting Up a PXE Server on an RPM-based OS

Note: This tutorial should be safe to follow now, but it's still in development and has a couple gaps in it. Please feel free to contribute!

This tutorial covers the steps needed to make a PXE server. It will be used for hosting multiple Operating Systems that can be booted from a machine's network card. The main reason for this setup is to host installation media removing the requirement for have optical drives in machines. It also saves you from having a pile of optical discs kicking around.

Prerequisite

This tutorial assumes that you have a fresh install of Fedora 13 and that the machine's eth0 device has been statically set to 192.168.1.10 and the subnet's router is set to 192.168.1.1. This should be easy to adapt to other distributions and network configurations.

Parts Needed

A PXE boot server is fairly strait forward. You need:

  • dhcp; This answers a workstation's request for an IP during the boot process.
  • tftp-server; This is a PXE compliant FTP server than handles passing the core boot files to the remote machine.
  • syslinux; This handles those special boot files that the remote machine needs to boot.
  • httpd; Once the boot files start up the remote machine, generally you will tell it to pull the main files from a webserver. This is the Apache webserver that will server that purpose.

dhcp

You're probably familiar with DHCP from a client perspective; It's the method used to get an IP address from most networks when you join them. This is a pretty old and simple protocol and is easy to setup.

A Word On Network Separation

Before you do though, you must take into account any other DHCP servers on your network. More to the point, you need to make sure there are no other DHCP servers on your network. The reason is that, when you try to PXE-boot a machine, it's up to the DHCP server that responds first to tell the client about the PXE server. If a "normal" DHCP server answers first, there simply won't be any instructions and your machine will not actually boot.

Configuration File

The core file to edit is /etc/dhcp/dhcpd.conf.

Note: On many systems, this *used* to be /etc/dhcpd.conf, but on Fedora 13 it's been moved into it's own directory. If you are adapting this tutorial for another operating system, please check to see where your server expects this file to be.

vim /etc/dhcp/dhcpd.conf
### Global options
# General domain information
option domain-name "alteeve.com";
option domain-name-servers 192.139.81.117, 192.139.81.1;

# Tell the server that it's authoritive on our network.
authoritive;

### Subnet options
subnet 192.168.1.0 netmask 255.255.255.0 {
	# This is the DHCP server, but not the actual Internet gateway. So this
	# Argument points our clients to the right box.
	option routers 192.168.1.1;
	
	# Set our range. This can be whatever you want so long as it fits in
	# your netmask.
	range 192.168.1.100 192.168.1.220;
	
	# If clients don't ask, make the lease available for the following
	# number of seconds. If the client does ask, allow up to this number of
	# seconds. 86,400s = 24h.
	default-lease-time 86400;
	max-lease-time 86400;

	# These two options tell clients where to go to get the file needed to
	# start the boot process.
	next-server 192.168.1.10;
	filename "pxelinux.0";
}

Now set dhcpd to start with your machine and then start it up for the first time.

chkconfig dhcpd on
/etc/init.d/dhcpd start

Done!

This isn't meant to be a dhcpd tutorial, so I am not showing a lot of options you may find useful. Please take the time to read the man dhcpd.conf and man dhcp-options page to see all the other neat things you can do.

tftp

This is the PXE-compliant FTP program that transfers the boot files from the PXE server to the client. It is pretty trivial to set up.

Edit /etc/xinted.d/tftp and simply add disable = no. The edited file should look like this:

vim /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
{
        disable                 = no
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = yes
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

Being an xinetd service, that is what we need to enable at boot time and then start.

chkconfig dhcpd xinetd
/etc/init.d/xinetd restart

Done!

pxelinux

In the xintd file for tftp was this line:

        server_args             = -s /var/lib/tftpboot

This determines where the PXE boot files will be setup. Some people like to change this to be /tftpboot, but we'll keep it there to keep things simple. In Fedora, this directory already exists and should be world-readable. If it isn't for some reason, create it and set the permissions to 0755 or 0777, depending on your security requirements.

Setting Up the Boot Environment

Next up, we need to copy a couple files into the tftpboot directory. These files are provided by the syslinux package we installed earlier and can be found in the /usr/share/syslinux/ directory.

The main files are:

  • pxelinux.0: This is the actual kernel that is passed to the client to begin the boot process. You'll notice this is the file specified in the dhcpd.conf file earlier in our setup. It boots the client far enough so that it can see the boot menu, if any, and then move on to find the main system to boot. This "main system" could be a boot DVD or a full OS.
  • vesamenu.c32: This is the 32-bit comboot file. This enables 32-bit colour images to be used for the boot menu (alpha+rr+gg+bb). This replaces the older 16-colour menu.c32 of earlier version that allow for very basic images.
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/

Client Configuration Files

Client configuration files will be placed in a new directory under tftpboot called pxelinux.cfg. So to start, we need to create it:

mkdir /var/lib/tftpboot/pxelinux.cfg

Before we talk about the contents of the configuration files, it is important to understand how the PXE server decides which one to use for a given client.

When a client connects, the PXE server looks at the client's MAC address and checks to see if there is a matching hyphen-separated configuration file. If that isn't found, it then looks at the client's IP address, as set by the DHCP server. It looks for configuration files matching the hexadecimal representation of the IP address. For example, If the client was given the IP address 192.168.1.200, the PXE server will start by looking for a configuration file called C0A801C8. If it doesn't find a matching file, it will then knock-off the right-most nibble and check again. It will do this until all the possible file names are checked.

If the PXE server finds no configuration file matching the MAC address or any variant on the IP address, it falls back to a configuration file called default.

Let's show this series using the example of a client with MAC address 00:24:7e:69:6f:0e and having been assigned the IP address 192.168.1.200. The PXE server will then look for the following configuration file names in the following order:

/var/lib/tftpboot/pxelinux.cfg/00-24-7E-69-6F-0E
/var/lib/tftpboot/pxelinux.cfg/C0A801C8
/var/lib/tftpboot/pxelinux.cfg/C0A801C
/var/lib/tftpboot/pxelinux.cfg/C0A801
/var/lib/tftpboot/pxelinux.cfg/C0A80
/var/lib/tftpboot/pxelinux.cfg/C0A8
/var/lib/tftpboot/pxelinux.cfg/C0A
/var/lib/tftpboot/pxelinux.cfg/C0
/var/lib/tftpboot/pxelinux.cfg/C
/var/lib/tftpboot/pxelinux.cfg/default

I've made a little script to convert decimal-type IP addresses into hexadecimal-type specifically to help in naming these configuration files. I am sure there are many others out there.

The Configuration Files

All of the possible configuration files can be setup using the same set of options and can be setup in similar ways. There is nothing special about any given configuration file. For this reason, we will cover the contents of the default configuration file only.

Below is the default configuration file we will use. Comments are embedded explaining each option.

vim /var/lib/tftpboot/pxelinux.cfg/default
# Use the high-colour menu system
UI vesamenu.c32

# Time out and use the default menu option. Defined as tenths of a second.
TIMEOUT 600

# Prompt the user. Set to '1' to automatically choose the default option.
PROMPT 0

# Set the boot menu to be 1024x768 with a nice background image. Be careful to
# ensure that all your user's can see this resolution! Default is 640x480.
MENU RESOLUTION 1024 768
MENU BACKGROUND an-pxe_splash_1024_768.png

# These do not need to be set. I set them here to show how you can customize or
# localize your PXE server's dialogue.
MENU TITLE    AN!PXE Boot Server
MENU AUTOBOOT Will boot the next device as configured in your BIOS in # second{,s}.
MENU TABMSG   Press the <tab> key to edit the boot parameters of the highlighted option.
MENU NOTABMSG Editing of this option is disabled.

# The following options set the various colours used in the menu. All possible
# options are specified except for F# help options.
# Format is: MENU COLOR <Item> <ANSI Seq.> <foreground> <background> <shadow type>
MENU COLOR screen      0  #80ffffff #00000000 std      # background colour not covered by the splash image
MENU COLOR border      0  #ffffffff #ee000000 std      # The wire-frame border
MENU COLOR title       0  #ffff3f7f #ee000000 std      # Menu title text
MENU COLOR sel         0  #ff00dfdf #ee000000 std      # Selected menu option
MENU COLOR hotsel      0  #ff7f7fff #ee000000 std      # The selected hotkey (set with ^ in MENU LABEL)
MENU COLOR unsel       0  #ffffffff #ee000000 std      # Unselected menu options
MENU COLOR hotkey      0  #ff7f7fff #ee000000 std      # Unselected hotkeys (set with ^ in MENU LABEL)
MENU COLOR tabmsg      0  #c07f7fff #00000000 std      # Tab text
MENU COLOR timeout_msg 0  #8000dfdf #00000000 std      # Timout text
MENU COLOR timeout     0  #c0ff3f7f #00000000 std      # Timout counter
MENU COLOR disabled    0  #807f7f7f #ee000000 std      # Disabled menu options, including SEPARATORs
MENU COLOR cmdmark     0  #c000ffff #ee000000 std      # Command line marker - The '> ' on the left when editing an option
MENU COLOR cmdline     0  #c0ffffff #ee000000 std      # Command line - The text being edited
# Options below haven't been tested, descriptions may be lacking.
MENU COLOR scrollbar   0  #40000000 #00000000 std      # Scroll bar
MENU COLOR pwdborder   0  #80ffffff #20ffffff std      # Password box wire-frame border
MENU COLOR pwdheader   0  #80ff8080 #20ffffff std      # Password box header
MENU COLOR pwdentry    0  #80ffffff #20ffffff std      # Password entry field
MENU COLOR help        0  #c0ffffff #00000000 std      # Help text, if set via 'TEXT HELP ... ENDTEXT'

# Now define the menu options
LABEL next
	MENU LABEL ^A)  Boot the next device as configured in your BIOS
	MENU DEFAULT
	localboot

LABEL generic_f13_x86_64
	MENU LABEL ^B)  Generic Fedora 13 x86_64 install
	KERNEL boot/f13/x86_64/vmlinuz
	APPEND initrd=boot/f13/x86_64/initrd.img

LABEL generic_f13_i386
	MENU LABEL ^C)  Generic Fedora 13 i386 install
	KERNEL boot/f13/i386/vmlinuz
	APPEND initrd=boot/f13/i386/initrd.img

LABEL ubuntu_live_x86_64
	MENU LABEL ^D)  Ubuntu 10.04 x86_64, Live DVD
	KERNEL boot/ubuntu_10.04/x86_64/vmlinuz
	APPENT initrd=boot/ubuntu_10.04/x86_64/initrd.img

LABEL ubuntu_live_i386
	MENU LABEL ^E)  Ubuntu 10.04 i386, Live DVD
	KERNEL boot/ubuntu_10.04/i386/vmlinuz
	APPENT initrd=boot/ubuntu_10.04/i386/initrd.img

MENU SEPARATOR

LABEL an-node01
	MENU LABEL ^1)  Install 'an-node01 x86_64'; DRBD/iSCSI Host 1
	KERNEL boot/f13/x86_64/vmlinuz
	APPEND initrd=boot/f13/x86_64/initrd.img ks=http://192.168.1.10/f13/x86_64/ks/an-node01.ks ksdevice=eth0

LABEL an-node02
	MENU LABEL ^2)  Install 'an-node02 x86_64'; DRBD/iSCSI Host 2
	KERNEL boot/f13/x86_64/vmlinuz
	APPEND initrd=boot/f13/x86_64/initrd.img ks=http://192.168.1.10/f13/x86_64/ks/an-node02.ks ksdevice=eth0

To keep things simple, this configuration file doesn't use sub-menus.

Options

Let's now take a look at the various parts. This is an overview only, for a complete list of options please read /usr/share/doc/syslinux-3.84/menu.txt. Update the version number to match your installed version.

Wherever a colour can be specified, the format is #AARRGGBB. That is, alpha (transparency), red, green and blue intensity expressed as a 256 range specified using two hexadecimal characters per option.

  • UI vesamenu.c32

This loads the 32-bit colour COMBOOT image. This allows for the full colour range plus 8-bit alpha (transparency) to be available at boot time. It's what allows for a much more attractive boot menu. To read details on the innards of the COMBOOT format, read /usr/share/doc/syslinux-3.84/comboot.txt. Update the version number to match your installed version.

  • TIMEOUT 600

This is the amount of time, in tenths of a second, that the PXE loader will wait before performing the default action. If the user navigates through the menu. the timer will stop and wait for the user to make a selection. To prevent an install from running accidentally, the default option should always be a non-damaging option.

  • prompt 0

This tells the PXE server to prompt the user to make a choice. If this is set to 1 then the PXE server will use the default option.

  • MENU RESOLUTION 1024 768

This tells the boot loader to run at the set resolution, 1024x768 in this example. The default is to run up as vga (640x480). Be sure when pushing a higher resolution that all of your potential users have machines that support the given resolution.

  • MENU BACKGROUND an-pxe_splash_1024_768.png

This is the background image to use. This must exist in or under the /var/lib/tftpboot/ directory. If you want to use a subdirectory, specify it as a relative path. For example, if you want to store images in /var/lib/tftpboot/images/, then this would be set to images/an-pxe_splash_1024_768.png. The format of the image can be JPEG or The format of the image can be JPNG (other image formats may work). The image itself should match the size of the screen.

  • MENU TITLE AN!PXE Boot Server
  • MENU AUTOBOOT Will boot the next device as configured in your BIOS in # second{,s}.
  • MENU TABMSG Press the <tab> key to edit the boot parameters of the highlighted option.
  • MENU NOTABMSG Editing of this option is disabled.

These options allow you to customize or localize the text. None need to be specified.

The AUTOBOOT option is a little special to accommodate the count-down. The # will be replaced by the time remaining. The {,s} tells the string to add an s to the end of seconds when the time remaining is greater than one.

  • MENU COLOR x

These options control the colour and transparency of the various text-elements, borders and backgrounds. None of them need to be specified and all have sane default values. Most of the available options are shown in the example above.

Each entry is formatted like so:

MENU COLOR <type> <ansi> <foreground> <background> <shadow>

The <type> is the name of the element you are manipulating. The only 'type' not show in the example above is msgXX where XX is a number between 1 and 12. These are used to control "help windows" that can be shown to the user when they press an F[1-12] key.

The <ansi> number(s) tell the boot loader how to format the text using ANSI code. This is set to 0, "reset", in our example to clear any ANSI formatting. You can specify multiple ANSI codes by separating them with ; (semi-colons).

The <foreground and <background> values are the hexadecimal notation for the transparency and colour in the format #AARRGGBB as mentioned earlier.

The <shadow> is the type of drop-shadow to render for the <type>. Valid options are:

  • none: No shadowing.
  • std, standard: Foreground pixels are raised.
  • all: both foreground and background pixels are raised.
  • rev, reverse: Background pixels are raised.

Labels

The rest of the configuration file contains "label" blocks. There are many options available here that are not shown in this example. If you are curious, please read /usr/share/doc/syslinux-3.84/menu.txt which was installed on your system when you installed syslinux. Of course, replace 3.84 with the version you have installed.

First example;

LABEL next
	MENU LABEL ^A)  Boot the next device as configured in your BIOS
	MENU DEFAULT
	localboot

This example is a good one to always use as the first, and default, option.

The LABEL next defines this option group. The name next has no special meaning, but can be used for more complex setups later. For now, just be sure to keep this name simple with no spaces.

The MENU LABEL ... option control two things. First, it's the text shown to the user. Second, the ^A sets the keyboard key that the user can press to select the option. Whatever character comes immediately after the (caret), A in this example, becomes the mapped key. Please note that the ^ can come anywhere in the title text. Ensure that no two entries have the same character mapped!

The MENU DEFAULT command tells the boot loader to automatically boot this option if the TIMEOUT expires. Only one entry may have this option.

The localboot is a special command the skips the PXE boot loader. Your BIOS should proceed to boot the next device in it's boot order list. Generally this will boot the local hard drive.

Another example:

LABEL an-node01
	MENU LABEL ^1)  Install 'an-node01 x86_64'; DRBD/iSCSI Host 1
	KERNEL boot/f13/x86_64/vmlinuz
	APPEND initrd=boot/f13/x86_64/initrd.img ks=http://192.168.1.10/f13/x86_64/ks/an-node01.ks ksdevice=eth0

This is a pretty typical entry. The two new options to note are:

  • KERNEL ...

This is the path to the boot kernel used to start the OS or it's installer. Most distributions make use of a small kernel to run up their installer or Live CD/DVD environment. The PXE server will search for the kernel relative to the tftpboot directory. Where to get the proper boot kernel will depend on the distribution you are setting up. Some examples will be shown shortly.

  • APPEND ...

This argument allows you to pass arguments to the KERNEL specified above. Which options can be passed will, again, depend on the distribution you are setting up. In this example, an initrd image is specified, a kickstart script is set and the network device to use to search for the kickstart script are defined.

Setting Up Apache

We will use the Apache web server to make our operating system images available.

Credits

References used:

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.