PXE Magic
Kyle Rankin
Sr. Systems Administrator, DevOps Engineer
Agenda
In this talk I'll cover...
- How to set up a PXE boot server
- How to PXE boot a client
- Kickstart
- pxelinux Menus
- Adapting Ubuntu PXE menus for personal use
"Pixie?"
- PXE = Preboot eXecution Environment
- Open standard developed by Intel
- Lets you boot an OS from a network card
- Comes on most newer laptops/desktops with integrated NICs
- Not OS-specific
Create a PXE boot server
You need three things:
- DHCP server
- TFTP server
- Boot loader (pxelinux recommended)
Create a PXE boot server
DHCP server
- Any relatively new DHCP server works--use distro package
- Configure DHCP server normally
- Add dynamic-bootp to "range" designation in subnet{}
- then add to the subnet{} (or host{}) section:
next-server ip_of_pxe_server;
filename "pxelinux.0";
For instance:
subnet 10.0.0.1 netmask 255.255.255.0 {
range dynamic-bootp 10.0.0.200 10.0.0.220;
next-server 10.0.0.1;
filename "pxelinux.0";
...
}
Create a PXE boot server
TFTP server
- Install tftp server...
- pxelinux needs a TFTP server that supports the 'tsize' option:
- Create a /tftpboot or /var/lib/tftpboot directory
- Confirm tftpd is running, or enabled in /etc/inetd.conf:
tftp dgram udp wait root /usr/sbin/in.tftpd \
/usr/sbin/in.tftpd -s /var/lib/tftpboot
With xinetd, set disable = no in /etc/xinetd.d/tftp
Create a PXE boot server
Install pxelinux
- Install syslinux (http://syslinux.zytor.com/pxe.php)
- Copy pxelinux.0 to /var/lib/tftpboot
- Copy kernels/initrd files to /var/lib/tftpboot
- Create /var/lib/tftpboot/pxelinux.cfg directory for config files
- Add per-host configuration files in /var/lib/tftpboot/pxelinux.cfg
Create a PXE boot server
/var/lib/tftpboot/pxelinux.cfg/ config files
- pxelinux config file search order:
- Files labeled 01-MACADDRESS, ie 88:99:AA:BB:CC:DD = 01-88-99-aa-bb-cc-dd
- Files labeled after IP in hex, removing one digit for each failure
- A file named default
- Configuration files use same syntax as syslinux:
default linux
label linux
kernel vmlinuz-centos-3.6
append text nofb load_ramdisk=1 \
initrd=initrd-centos-3.6.img \
network ks=http://10.0.0.1/ks/centos3.cfg
PXE boot a client
- Reboot machine, confirm boot order in BIOS
- Might have to enable Network Boot option in BIOS, then reboot
- Make note of MAC address
Kickstart
- Tool to automate RedHat (and RedHat-like) installs
- Debian equivalent = FAI (Fully Automated Installer) and Preseed
- Ubuntu supports a blend called "kickseed"
- Configure all install options in advance (or based on a current install)
- Store kickstart configs on a remote http/ftp server and access with boot option ks=
- With PXE boot, no need for boot CD/floppy--just netboot and the kickstart will begin
- Tip: Enable Spanning Tree Port Fast on your kickstart client's port
- For more info: RHEL Kickstart Guide
Other PXE Uses
- Memtest86+
- Linux/DOS Rescue Disks
pxelinux Menus by hand
- Used to create menus from scratch
Graphical pxelinux Menus
- Debian/Ubuntu provide nice graphical boot menus in tarballs
- Can be adapted to other distros
- To install, just download the tarball and extract in tftpboot dir:
$ cd /var/lib/tftpboot
$ sudo wget http://us.archive.ubuntu.com/ubuntu/dists/precise/
main/installer-i386/current/images/netboot/netboot.tar.gz
$ sudo tar xzf netboot.tar.gz
$ ls
netboot.tar.gz pxelinux.0 pxelinux.cfg ubuntu-installer version.info
Graphical Menu Result
Multi-OS Graphical pxelinux Menus
- Decided to adapt Ubuntu's menu for my needs
- First, wipe out /var/lib/tftpboot
- Each OS gets its own directory:
$ cd /var/lib/tftpboot
$ sudo mkdir precise
$ cd precise
$ sudo wget http://us.archive.ubuntu.com/ubuntu/dists/precise/
main/installer-i386/current/images/netboot/netboot.tar.gz
$ sudo tar xzf netboot.tar.gz
Build Base Config
- Next, copy some useful configuration files to act as our base:
$ cd /var/lib/tftpboot
$ sudo cp -a precise/ubuntu-installer/i386/boot-screens \
precise/ubuntu-installer/i386/pxelinux.0 \
precise/ubuntu-installer/i386/pxelinux.cfg .
boot-screens: contains GUI menu configuration
pxelinux.0: pxelinux binary
pxelinux.cfg: default pxelinux configuration
change paths in boot-screens configs since files moved:
$ cd /var/lib/tftpboot/boot-screens
$ sudo perl -pi -e 's|ubuntu-installer/i386/||' *
Copy Distro-specific config
- Specific menu config for precise is found under precise/ubuntu-installer/i386/boot-screens/txt.cfg:
default install
label install
menu label ^Install
menu default
kernel ubuntu-installer/i386/linux
append vga=788 initrd=ubuntu-installer/i386/initrd.gz -- quiet
label cli
menu label ^Command-line install
kernel ubuntu-installer/i386/linux
append tasks=standard pkgsel/language-pack-patterns= \
pkgsel/install-language-support=false vga=788 \
initrd=ubuntu-installer/i386/initrd.gz -- quiet
Copy Distro-specific config
- Make a copy of this file under boot-screens and update directory paths:
$ cd /var/lib/tftpboot/boot-screens
$ sudo cp ../precise/ubuntu-installer/i386/boot-screens/txt.cfg \
precise-i386.cfg
$ sudo perl -pi -e 's|ubuntu-installer|precise/ubuntu-installer|g' \
precise-i386.cfg
Sample from precise-i386.cfg:
default install
label install
menu label ^Install
menu default
kernel precise/ubuntu-installer/i386/linux
append vga=788 initrd=precise/ubuntu-installer/i386/initrd.gz -- quiet
Update core menu config
- Menu settings are configured in boot-screens/menu.cfg:
. . .
menu title Installer boot menu^G
include boot-screens/stdmenu.cfg
include boot-screens/txt.cfg
include boot-screens/gtk.cfg
menu begin advanced
menu title Advanced options
include boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include boot-screens/adtxt.cfg
include boot-screens/adgtk.cfg
menu end
Update core menu config
- Use existing menu as a guide, add our new config file:
. . .
menu title Installer boot menu^G
include boot-screens/stdmenu.cfg
menu begin precise-i386
menu title Precise 12.04 i386
include boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include boot-screens/precise-i386.cfg
menu end
include boot-screens/gtk.cfg
menu begin advanced
menu title Advanced options
. . .
Nested Menu Result
Add 64-bit option
- Similar steps as before, 64- and 32-bit can coexist in same dir:
$ cd /var/lib/tftpboot/precise
$ sudo rm netboot.tar.gz
$ sudo wget http://us.archive.ubuntu.com/ubuntu/dists/precise/
main/installer-amd64/current/images/netboot/netboot.tar.gz
$ sudo tar xzf netboot.tar.gz
boot-screens already exists, skip ahead to copying txt.cfg:
$ cd /var/lib/tftpboot/boot-screens
$ sudo cp ../precise/ubuntu-installer/amd64/boot-screens/txt.cfg \
precise-amd64.cfg
$ sudo perl -pi -e 's|ubuntu-installer|precise/ubuntu-installer|g' \
precise-amd64.cfg
Add 64-bit option - Edit menu.cfg
- edit menu.cfg and add the new menu entry:
. . .
menu begin precise-i386
menu title Precise 12.04 i386
include boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include boot-screens/precise-i386.cfg
menu end
menu begin precise-amd64
menu title Precise 12.04 amd64
include boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include boot-screens/precise-amd64.cfg
menu end
. . .
Add A New Distro
- Quantal (12.10) is out, let's add that:
$ cd /var/lib/tftpboot
$ sudo mkdir quantal
$ cd quantal
$ sudo wget http://us.archive.ubuntu.com/ubuntu/dists/quantal/
main/installer-i386/current/images/netboot/netboot.tar.gz
$ sudo tar xzf netboot.tar.gz
$ cd /var/lib/tftpboot/boot-screens
$ sudo cp ../quantal/ubuntu-installer/i386/boot-screens/txt.cfg \
quantal-i386.cfg
$ sudo perl -pi -e 's|ubuntu-installer|quantal/ubuntu-installer|g' \
quantal-i386.cfg
Add A New Distro
Edit menu.cfg
. . .
menu begin quantal-i386
menu title Quantal 12.10 i386
include boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include boot-screens/quantal-i386.cfg
menu end
. . .
Multi-Distro menu
Ubuntu Only?
- Just using Ubuntu as a launch pad
- Debian includes the same netboot.tar.gz with the same format
- Trivial to adapt menu.cfg and precise-i386.cfg to add other distros
- In those cases be sure to copy over netboot kernels and initrds to tftpboot
Questions?
Some useful links