Categories
OS Deployment

Advanced PXELinux Configuration and Semi-Automated Linux Installation

This article assumes that you have already read and completed the instructions from my previous PXE-related posts. You might want to read them first.

Advanced PXELinux Configuration

In a hurry? Take a look at the Advanced PXELinux summary instead.

Modify /var/lib/tftpboot/pxelinux.cfg/default, and change the following line:

default graphics

to:

default vesamenu.c32

…and then add the following lines to the global section of the file:

menu title PXE Boot Menu
menu autoboot Starting graphics-mode Linux installer in # seconds

Finally, you’ll need to modify each of your labels as follows:

  • add a menu label entry
  • add some text to a new TEXT HELP/ENDTEXT section
  • set a default boot image

Putting all of that together properly should result in a file that looks like this:

default vesamenu.c32
prompt 0
timeout 100
menu title PXE Boot Menu
menu autoboot Starting graphics-mode Linux installer in # seconds

label graphics
  menu default
  menu label Linux Installer (Graphics Mode)
  TEXT HELP
  Installs Linux using the GUI installer
  ENDTEXT
  kernel linux/vmlinuz
  append initrd=initrd.gz

label text
  menu label Linux Installer (Text Mode)
  TEXT HELP
  Installs Linux using a text-mode installer
  ENDTEXT
  kernel linux/vmlinuz
  append initrd=initrd.gz text

Optional Configuration

Using some of the examples from the syslinux website, I finally came up with a decent, user-friendly network boot menu, rather than using the default boot: prompt. First, you’ll need two new files: another pxelinux-related configuration file called /var/lib/tftpboot/pxelinux.cfg/graphics.conf, and a 640×480 image in PNG or JPEG format called /var/lib/tftpboot/pxelinux.cfg/boot.png. With the configuration below, graphics.conf defines a text-based menu with the specified color scheme. The syslinux guys have done a decent job of documenting the format for these entries in their wiki, and I’ve customized the colors below to match the color scheme the company I work for tends to prefer (red/white/black).

The syslinux documentation refers to both a simple and advanced menu system. I’ve never used the advanced menu system, as it does FAR more than I could ever want it to. The simple menu system is advanced enough for me. 😉 Anyway, on to the fun stuff. First, we need the graphics.conf file, so, as always, fire up your favorite text editor, and place the following in /var/lib/tftpboot/pxelinux.cfg/graphics.conf:

MENU WIDTH 78
MENU MARGIN 1
MENU COLOR BORDER       30;44      #00000000 #00000000 none
MENU COLOR TABMSG       1;44;36    #90000000 #00000000 none
MENU COLOR TITLE        1;44;36    #00000000 #ffff0000 none
MENU COLOR SEL          44;36      #dd000000 #20000000
menu color screen       37;47      #80ffffff #00000000 std
menu color unsel        37;47      #ff000000 #ffffffff none
menu color hotkey       1;30;47    #ffff0000 #20ff0000 none
menu color hotsel       1;7;30;47  #ffff0000 #20ff0000 all
menu color disabled     1;30;47    #ffff0000 #00000000 none
menu color scrollbar    30;47      #ffff0000 #00000000 std
menu color cmdmark      1;36;47    #e0ff0000 #00000000 std
menu color cmdline      30;47      #ff000000 #00000000 none
menu color pwdborder    31;47      #80ffffff #20ffffff std
menu color pwdheader    31;47      #e0ff0000 #20ffffff std
menu color pwdentry     30;47      #ff000000 #00000000 none
menu color timeout_msg  30;47      #ff000000 #00000000 none
menu color timeout      1;30;47    #ff000000 #00000000 none
menu color help         30;47      #ff000000 #00000000 none
MENU BACKGROUND pxelinux.cfg/boot.png
MENU AUTOBOOT Automatic boot in # second{,s}...
NOESCAPE 0

Note: If you want to be able to return to the boot: prompt for whatever reason, change NOESCAPE from 0 to 1.

Next, create a 640×480 background image in PNG or JPEG format, and save it as /var/lib/tftpboot/pxelinux.cfg/boot.png. If you save it somewhere else, update the relative path in graphics.conf to point to the right file. No matter where you save it, it must be accessible via TFTP – which means it must be stored under /var/lib/tftpboot/, if you’re using my tftpd-hpa configuration.

Note: Since the color scheme defined in graphics.conf uses red/black text on a white background, you’ll probably want an image that also uses a white background.

Automating RedHat/Fedora Core Linux Installations

In a hurry? Take a look at the Automated Linux Installs summary instead

This is shockingly easy to do. All you need to do is a single installation of RHEL or FC, and you’ll have everything you need to automate subsequent installations. First, you need the installation media on an NFS or HTTP server on your network. As with the DHCP and TFTP servers, this can be a separate server, or it can be on the same server. If you have a spare Linux system already, simply mount the installation media and copy it to an NFS exported directory, or somewhere in your web server’s DocumentRoot. Second, we’ll use our existing boot image to install Linux over the network. And, finally, we’ll update our PXELinux configuration to automate subsequent installations. The following instructions assume that you have copied the installation media to /export/install/linux/. If not, then you need to adjust the instructions accordingly.

Setting up the Installation Media

When creating your NFS/HTTP export, keep in mind that you may need to support both x86 and x64 versions of each operating system. I highly recommend creating and adhering to a standard directory structure when adding installation media that follows <some root>/<os name>/<major & minor release number>/<architecture>/ (e.g. /export/install/fedora/10.0/x86/, /export/install/fedora/10.0/x64/, /export/install/rhel/5.2/x86/, etc.). This makes it easy to maintain, and easy for your users to find if the automation breaks for whatever reason.

Note that you only have to do ONE of the following. I’d recommend using the HTTP export, as it will likely be faster (no NFS file locking required, less protocol overhead, more portable across operating systems, etc.).

NFS Export Using Linux

  • Install the nfs-utils package (emerge nfs-utils on Gentoo; apt-get install nfs-utils on Ubuntu)
  • Ensure that your kernel has NFS support as a module or compiled in (almost all will)
  • Copy the entire contents of the installation media to /export/install/linux/ (or whatever folder you prefer)
  • add /export/install/linux/ *(rw,no_root_squash,subtree_check) to /etc/exports
  • run exportfs -r or restart your NFS server (/etc/init.d/nfs-kernel-server restart on Gentoo; /etc/init.d/nfs restart on Ubuntu)

NFS Export Using Solaris

If you’re using ZFS:

  • create a new file system to store your installation media: zfs create -o sharenfs=on zfspool/install
  • copy the installation media into /zfspool/install/linux

If you’re not using ZFS, you’ll need to edit /etc/dfs/dfstab, and add share -F nfs -o rw /export/install/linux/. Note that if you want the NFS export to activate immediately, you can simply run the share command; otherwise, the export will activate when the system is rebooted.

HTTP Export Using Apache

  • Determine Apache’s DocumentRoot
  • Copy the entire contents of the installation media to DocumentRoot/linux/ (or whatever subfolder you prefer, but it must be under DocumentRoot for Apache to serve the files without requiring lengthy configuration changes)

HTTP Export Using IIS

  • Determine IIS’s wwwroot directory (typically, c:\inetpub\wwwroot)
  • Copy the entire contents of the installation media to wwwroot/linux/ (or whatever subfolder you prefer, but it must be under wwwroot for IIS to serve the files without requiring lengthy configuration changes)

Install the Reference System

Once you have your installation media in place, and you have your basic PXELinux configuration working, you’ll need to install what I call the reference system. This is a basic installation of Linux that will allow us to create further, automated installations. Here’s what you need to do:

  • use a PXE client to boot from the network
  • select the Linux Installer from the PXE menu and press ENTER (either graphics or text mode – doesn’t matter much for this installation, so use whatever works with your PXE client)
  • when prompted for the source location, choose appropriately: if you setup an HTTP export using Apache or IIS, you’ll want to choose HTTP; if you setup an NFS export, you’ll want to choose NFS
  • when prompted, enter the server name and path to your installation sources
  • install your distribution however you want (but keep in mind that the choices you make here will be applied to all future installations, so keep it simple and lean)
  • once the installation is complete, copy /root/anaconda.ks to your installation source export directory, and rename the file so that it’s obvious what distribution you installed (e.g. mv anaconda.ks fc10x86.ks)
  • modify /var/lib/tftpboot/pxelinux.cfg/default, adding ks=<protocol>://<server name>/<filename>.ks to the end of your Linux Installer lines, where <protocol> is either nfs or http depending on how you configured you installation source export location, <server name> is the system containing your installation sources, and <filename> is the path and filename of the renamed anaconda.ks file from the previous step:
default vesamenu.c32
prompt 0
timeout 100

menu title PXE Boot Menu
menu autoboot Starting graphics-mode Linux installer in # seconds

label graphics
  menu default
  menu label Linux Installer (Graphics Mode)
  TEXT HELP
  Installs Linux using the GUI installer
  ENDTEXT
  kernel linux/vmlinuz
  append initrd=initrd.gz ks=http://install/sources/server/and/path/anaconda.ks

label text
  menu label Linux Installer (Text Mode)
  TEXT HELP
  Installs Linux using a text-mode installer
  ENDTEXT
  kernel linux/vmlinuz
  append initrd=initrd.gz text ks=http://install/sources/server/and/path/anaconda.ks

The really nice thing about this setup is that the same anaconda.ks file can be used to install other releases of RedHat and its derivatives (like Fedora Core), simply by copying the .ks file and editing the source installation path to point to the new release’s sources. If you’re using NFS for your installation sources, you’d simply need to modify the nfs line in anaconda.ks to point to your NFS server and the path to the installation media: nfs --server=<server name> --dir=<path to sources>, where <server name> is your NFS server’s hostname and <path to sources> is the location of the installation sources on your NFS server.

Conclusion

At this point, you can reinstall on your reference system, and the installation should only prompt for the hostname and disk layout; all other installation-related questions should be automatically answered.