Setting Up a PXE Server on an RPM-based OS
Alteeve Wiki :: How To :: Setting Up a PXE Server on an RPM-based OS |
About this Tutorial
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 EL6 and that the machine's eth1 device has been statically set to 10.255.255.254 and is the interface and IP address machines will use to talk to the PXE server.
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.
Configuring Needed Services
dhcp
First you will need a DHCP server. Here is a good little tutorial to follow. Come back once you finish.
Addition to the DHCP Configuration File
We need to add a section to the DHCP server configuration file, dhcpd.conf. We need to add an option to the relevant subnet directive(s) indicating where interested clients can go to get the PXE boot configuration. In this example, the PXE server and DHCP server are one in the same, but this is by choice only.
The section to add is below.
# These two options tell clients where to go to get the file needed to
# start the boot process.
next-server 10.255.255.254;
filename "pxelinux.0";
The updated dhcpd.conf file should look something like the example below.
Note: EL5 distributions store this file at /etc/dhcpd.conf.
vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
### Global options
# General domain information (DNS IPs are valid public DNS servers from google).
option domain-name "alteeve.ca";
option domain-name-servers 8.8.8.8, 8.8.4.4;
# Tell the server that it's authoritative on our network.
authoritative;
# This is required for EL5 operating systems but is optional on EL6 and newer
# Fedoras (F13+, at least). It controls how dynamic DNS updating is handled. In
# our case, we aren't concerned about DDNS so we'll set it to 'none'.
ddns-update-style none;
### Subnet options
subnet 10.255.0.0 netmask 255.255.0.0 {
# These two options tell clients where to go to get the file needed to
# start the boot process.
next-server 10.255.255.254;
filename "pxelinux.0";
# This is the DHCP server, but not the actual Internet gateway. So this
# Argument points our clients to the right box.
option routers 10.255.255.254;
# Set our range. This can be whatever you want so long as it fits in
# your netmask.
range 10.255.1.10 10.255.1.250;
# 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;
}
Restart the DHCP server and you're done.
/etc/init.d/dhcpd restart
Starting dhcpd: [ OK ]
tftp
We will use the 'trivial FTP' program as it is a PXE-compliant FTP program that can transfers the boot files from the PXE server to the client. It runs as an xinetd package, so we will need to make sure it is installed as well. All told, it lives up to it's name as it is quite trivial to setup.
First, install them.
yum install tftp-server xinetd
Then edit /etc/xinted.d/tftp and change disable = yes to disable = no. The edited file should now 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 = no
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 xinetd on
/etc/init.d/xinetd restart
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]
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.
Note: On EL5, the server_args value is -s /tftpboot. You can leave this as-is and adapt the rest of the tutorial to this directory if you wish. Otherwise, change this to /var/lib/tftpboot. Changing it is recommended as it will facilitate future upgrades or migrations of your configuration.
So now we need to install a package called syslinux.
yum install syslinux
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.
rsync -a /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
rsync -a /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/
Note: On EL5, only pxelinux.0 exists and it is in /usr/lib/syslinux/. The vesamenu.c32 can be copied from an EL6 machine or downloaded from this server
For EL5 users;
rsync -a /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/
wget -c https://alteeve.ca/files/pxe/tftpboot/vesamenu.c32 -P /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 10.255.1.10, the PXE server will start by looking for a configuration file called 0AFF010A. 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 10.255.1.10. 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/0AFF010A
/var/lib/tftpboot/pxelinux.cfg/0AFF010
/var/lib/tftpboot/pxelinux.cfg/0AFF01
/var/lib/tftpboot/pxelinux.cfg/0AFF0
/var/lib/tftpboot/pxelinux.cfg/0AFF
/var/lib/tftpboot/pxelinux.cfg/0AF
/var/lib/tftpboot/pxelinux.cfg/0A
/var/lib/tftpboot/pxelinux.cfg/0
/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.
- Direct download: /var/lib/tftpboot/pxelinux.cfg/default
- Direct download: /var/lib/tftpboot/an-pxe_splash_1024_768.png
vim /var/lib/tftpboot/pxelinux.cfg/default
# Use the high-colour menu system. This file, and the low-colour 'menu.c32'
# version, are provided by the syslinux package and can be found in the
# '/var/lib/tftpboot' directory. Copy it to '/var/lib/tftpboot'.
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. This
# is really meant for files matched to MAC addresses.
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
# This file must be in or under the '/var/lib/tftpboot' folder.
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
# Below, the hash (#) character is replaced with the countdown timer. The
# '{,s}' allows for pluralizing a word and is used when the value is >= '2'.
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. The colour is expressed as
# two hex characters between '00' and 'ff' for alpha, red, green and blue
# respectively (#AARRGGBB).
# 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
# I feel it is safest to return booting to the client as the first and default
# option. This entry below will do just that.
LABEL next
MENU LABEL ^A) Boot the next device as configured in your BIOS
MENU DEFAULT
localboot
## To keep the menu from getting out of hand, I like to create sub-menus.
## The sub-menus are simply additional files in the same directory as this
## file with one or more boot options or, if you wish, further sub-menus.
# As I build a lot of clusters, I like to have a section dedicated to boot
# options used to build cluster nodes. These are the EL6 + RHCS 3 nodes.
MENU BEGIN cluster_rhel
MENU TITLE Cluster 3 nodes - RHEL 6
LABEL Previous
MENU LABEL ^B) Previous Menu
MENU EXIT
MENU SEPARATOR
MENU INCLUDE pxelinux.cfg/cluster3-rhel.menu
MENU END
# As I build a lot of clusters, I like to have a section dedicated to boot
# options used to build cluster nodes. These are the EL6 + RHCS 3 nodes.
MENU BEGIN cluster_centos
MENU TITLE Cluster 3 nodes - CentOS 6
LABEL Previous
MENU LABEL ^C) Previous Menu
MENU EXIT
MENU SEPARATOR
MENU INCLUDE pxelinux.cfg/cluster3-centos.menu
MENU END
# As I build a lot of clusters, I like to have a section dedicated to boot
# options used to build cluster nodes. These are the EL6 + RHCS 3 nodes.
MENU BEGIN cluster_fedora
MENU TITLE Cluster 3 nodes - Fedora
LABEL Previous
MENU LABEL ^D) Previous Menu
MENU EXIT
MENU SEPARATOR
MENU INCLUDE pxelinux.cfg/cluster3-fedora.menu
MENU END
# This section covers base options without pre-defined kickstart (or other)
# automation scripts.
MENU BEGIN base
MENU TITLE Base installations (as if booting from media)
LABEL Previous
MENU LABEL ^E) Previous Menu
MENU EXIT
MENU SEPARATOR
MENU INCLUDE pxelinux.cfg/base.menu
MENU END
# This section covers generic server installs
MENU BEGIN stock
MENU TITLE Stock installations (common, generic server types)
LABEL Previous
MENU LABEL ^F) Previous Menu
MENU EXIT
MENU SEPARATOR
MENU INCLUDE pxelinux.cfg/stock.menu
MENU END
The default file above points to four sub-menu files. How many you use, if you use any at all, is up to you. You can also use any file name you want, or any directory under /var/lib/tftpboot/.
To save space on this page, The sub-menu files mentioned above are their own pages and are linked below. These will hopefully act as useful references for your own sub-menu files, should you wish to use 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
Label blocks are the actual boot options made available within the PXE menu. 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, from the cluster3-rhel.menu file:
LABEL rhel6_an-node01
MENU LABEL ^1) Install AN!Node01; Storage Node 01 - Cluster 3
KERNEL boot/rhel6/x86_64/vmlinuz
APPEND initrd=boot/rhel6/x86_64/initrd.img ks=http://10.255.255.254/rhel6/x86_64/ks/an-node01.ks #ksdevice=eth1
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 below.
- 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.
The Apache configuration section below covers in more detail how to make the kickstart and OS installation files available.
Labels For Fedora 17+
Fedora 17 (and newer) requires a special kernel option in order to locate the installation files. Without it, you will find that your install fails with an error like:
[ 84.985068] dracut Warning: Unable to process initqueue
dracut Warning: Unable to process initqueue
[ 84.985892] dracut Warning: /dev/root does not exist
dracut Warning: /dev/root does not exist
Dropping to debug shell.
dracut:/# _
You need to add the inst.repo= option to point to where you mounted the Fedora 17 ISO on your web server.
LABEL f17_x86_64
MENU LABEL ^3) Fedora 17 x86_64
KERNEL boot/f17/x86_64/vmlinuz
APPEND initrd=boot/f17/x86_64/initrd.img inst.repo=http://10.255.255.254/f17/x86_64/img/
Menus
Menus are very useful when you have more than a few entries in your PXE server. They allow for creating groups of bootable options based on whatever given criteria works for you.
Let's look at the "cluster" menu from above.
MENU BEGIN cluster_rhel
MENU TITLE Cluster 3 nodes - RHEL 6
LABEL Previous
MENU LABEL ^B) Previous Menu
MENU EXIT
MENU SEPARATOR
MENU INCLUDE pxelinux.cfg/cluster3-rhel.menu
MENU END
- MENU BEGIN ...
This begins the section and is followed by a name that should (must?) be unique.
- MENU TITLE ...
This is the text shown at the top of the sub-menu once selected.
- LABEL ...
This is the text shown as the first option in the sub-menu that returns to the previous screen.
- MENU LABEL ...
This is the text that the user selects to descend into the sub-menu.
Note: I use the ^ character to enable a letter to select the menu option but it doesn't seem to work. Please let me know if you have further information on how, or if, sub-menu options are selected with a key press.
- MENU EXIT ...
I am not sure, exactly, what this option does.
- MENU SEPARATOR ...
I am not sure, exactly, what this option does.
- MENU INCLUDE ...
This is the path and file to include when building this sub-menu. The path is relative to the tftpboot server_args directory, as set in /etc/xinetd.d/tftp file.
- MENU END
This closes the sub-menu section.
There are other options, though none seem to be well documented at the moment. I got this far thanks to this page. Any additional information on these and other options would be welcome!
Setting Up Apache
We will use the Apache web server to make our operating system images available. First, install the server.
yum install httpd
The default install of Apache2 will work fine for us, so we won't adjust it. Let's start it now.
/etc/init.d/httpd start
Test access by loading http://10.255.255.254 a machine on your network, replacing 10.255.255.254 with a resolvable name or IP address of your machine. If this doesn't work, make sure TCP port 80 is open on your firewall/PXE server.
Setting Up The DocumentRoot
Apache has a variable called DocumentRoot in it's main configuration file /etc/httpd/conf/httpd.conf. Anything in or under the directory specified in this variable will be exposed on your web server. The default directory is /var/www/html and this will be where we put our various kickstart files, ISO files and under which we will mount those ISO files.
The Default Page
There is no need to create an index.html page, as the image kickstart scripts and image files will be called directly. Personally though, I like to put together a simple page listing the various installations I've made available on the PXE server. If nothing else, it helps identify the machine when you call it in a browser.
If you decide to create one, please use whatever website tool, text editor or IDE you prefer. For reference, below are the very simple, probably not W3C compliant static HTML page I use along with a trivial CSS file.
Put the index.html (and associated files) directly in the DocumentRoot directory. By default, Apache2 will look for a file named index.html and load it if it is found.
Making The Install Files For An OS Available
At the end of the day, the only thing that matters here is that all of the installation files and kickstart scripts are somewhere under the DocumentRoot directory. I will describe here the layout that I like, but feel free to adjust it however you see fit.
Further, different operating systems will need to be configured differently. For the purpose of this tutorial, I will be showing how RPM-based Linux distributions are configured. If you are using different operating systems, you should be able to build on the steps below.
Planning Your Directory Structure
Under the DocumentRoot directory, we will need to create a set of directories to store the operating system files and associated kickstart scripts in. I've found the following structure works well.
- <DocumentRoot>/<os_name>/<architecture>/[ks|iso|img].
Using CentOS v6, x86_64 with the default Apache DocumentRoot as an example, you would create the following directories. Note that I like to shorten Operating System names to the shortest version practical to save typing. Feel free to use the full names if you prefer verbose URLs.
- /var/www/html/c6/x86_64/ks: Kickstart scripts go here
- /var/www/html/c6/x86_64/iso: The CentOS-6.3-x86_64-bin-DVD1.iso file is saved here. Alternatively, you can find a mirror closer to you.
- /var/www/html/c6/x86_64/img: The ISO file above is mounted here.
If you wanted to also make the i386 version of CentOS available, simply replace x86_64 with i386 above.
CentOS 6 x86_64
Let's walk through the actual steps needed to make CentOS 6.3 x86_64 available on Apache now.
First, create the directory structure.
mkdir -p /var/www/html/c6/x86_64/{iso,img,ks}
Now, download the ISO if you have not yet done so. If you have, move it into place.
cd /var/www/html/c6/x86_64/iso
wget -c http://mirror.csclub.uwaterloo.ca/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-bin-DVD1.iso
Now we mount the ISO using a loop-back device.
mount -o loop /var/www/html/c6/x86_64/iso/CentOS-6.3-x86_64-bin-DVD1.iso /var/www/html/c6/x86_64/img
df -hP
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/luks-51fbeed6-2efc-4eef-a8d6-8431a4fcceb8 454G 18G 414G 5% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 1008M 92M 866M 10% /boot
/var/www/html/c6/x86_64/iso/CentOS-6.3-x86_64-bin-DVD1.iso 4.2G 4.2G 0 100% /var/www/html/c6/x86_64/img
Lastly, copy any kickstart scripts into the /var/www/html/c6/x86_64/ks/ directory. These scripts will be called by the user after they select an automated install option from the PXE menu.
That's it! You can now use make CentOS 6.3 available as a PXE boot option in your menu.
Mounting And Unmounting Many ISOs
If you make any real use of your PXE server, you will probably find that you will have a lot of ISO files to mount and unmount. To simplify this task, I like to create a couple of bash scripts called, simply, mount_iso.sh and umount_iso.sh.
These are simple shell scripts meant to mount and unmount all ISOs with one command. You need to be sure that you keep them up to date as you add and remove operating systems.
You will certainly want to adjust these to suit your setup. With that said, here are my scripts that you can use as templates.
Mount;
vim /root/mount_iso.sh
#!/bin/bash
# This is used to mount the various ISO used by the PXE server on this server.
echo -n "Mounting RHEL 6.3, x86_64... "
mount -o loop /var/www/html/rhel6/x86_64/iso/rhel-server-6.3-x86_64-dvd.iso /var/www/html/rhel6/x86_64/img
echo "Done!"
echo -n "Mounting CentOS 6.3, x86_64... "
mount -o loop /var/www/html/c6/x86_64/iso/CentOS-6.3-x86_64-bin-DVD1.iso /var/www/html/c6/x86_64/img
echo "Done!"
echo -n "Mounting Fedora 16, x86_64... "
mount -o loop /var/www/html/f16/x86_64/iso/Fedora-16-x86_64-DVD.iso /var/www/html/f16/x86_64/img
echo "Done!"
Unmount;
vim /root/umount_iso.sh
#!/bin/bash
# This is used to unmount the various ISO used by the PXE server on this server.
echo -n "Unmounting RHEL 6.3, x86_64... "
umount /var/www/html/rhel6/x86_64/img
echo "Done!"
echo -n "Unmounting CentOS 6.3, x86_64... "
umount /var/www/html/c6/x86_64/img
echo "Done!"
echo -n "Unmounting Fedora 16, x86_64... "
umount /var/www/html/f16/x86_64/img
echo "Done!"
Increasing Maximum number of Mountable ISOs
By default the loop driver only creates 8 loop back devices. Each mounted ISO takes one of those and there for limits the total number of ISOs that can be mounted at any one time.
There exist two places to change the maximum number of loop back devices. The recommend method is to add max_loop option to a new config file in /etc/modprobe.d/.
vim /etc/modprobe.d/loop.conf
options loop max_loop=64
The second options is to add max_loop=64 to the kernel boot line.
Adjust the number after max_loop= to suit your installations needs.
Setting Up The Boot Environment
All boot options, except localboot, need to have a kernel made available via the PXE server. Specifically, these kernels must exist somewhere under the /var/lib/tftpboot directory. What kernel or boot image a given operating system will need depends entirely on that operating system. For this section, we will continue to use CentOS 6 x86_64 as an example.
Planning Your Directory Structure, Take Two
As with Apache, we're potentially going to copy a lot of boot images and other files. It makes sense to have an organized directory structure to put them all in. As before, I will share what I do, but please feel free to do what you find works best for you.
I like to create a dedicated directory called boot and then mimic the layout from Apache, minus the last set of three directories.
- <tftpboot>/boot/<os_name>/<architecture>/
Using CentOS 6 x86_64 with the default tftpboot install, I will create the following directory.
mkdir -p /var/lib/tftpboot/boot/c6/x86_64
The Bootable Kernel
Remember in the earlier LABEL c6_an-node01 example there was the APPEND initrd=boot/c6/x86_64/initrd.img ... line? The boot/c6/x86_64/initrd.img is the kernel, in the directory we just created!
The last piece of the puzzle then is; Where does the initrd.img file come from?
With most Linux distributions, there is an isolinux directory in the root of the installation DVD. The files needed to boot the DVD's installer (or "rescue mode") are in this directory. These are the same files we need to boot over PXE. If you have followed this tutorial up to this point, then you should be able to see the contents of this directory in your file browser. My PXE server uses the IP address 10.255.255.254, so I can go to http://10.255.255.254/c6/x86_64/img/isolinux and see, among other files, initrd.img.
With the directory created and the ISO mounted, all that is left is to copy the contents of the isolinux files.
rsync -av /var/www/html/c6/x86_64/img/isolinux/* /var/lib/tftpboot/boot/c6/x86_64/
sending incremental file list
TRANS.TBL
boot.cat
boot.msg
grub.conf
initrd.img
isolinux.bin
isolinux.cfg
memtest
splash.jpg
vesamenu.c32
vmlinuz
sent 35199717 bytes received 221 bytes 23466625.33 bytes/sec
total size is 35194744 speedup is 1.00
And we're done!
Now repeat the relevant steps for the rest of the operating systems you want to support via PXE.
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. |