HowTo: Setup your own PXE Boot Server using Ubuntu Server
The Preboot eXecution Environment (PXE) provides a means of starting up a PC using a network adapter instead of the traditional method of hard-drive, USB flash stick, CD or floppy disk.
Why would you want to boot a PC from the network? Well, it opens the door to booting diskless workstations, eg: Internet Cafe PC’s, or if you regularly install tens or hundreds of PC’s, you can start the installer on all those machines at once without needing to have individual boot/install media for each machine. You can even use Linux PXE for starting Microsoft Windows network installers and tools.
This article is going to show you how to setup a standard Ubuntu 10.04 Lucid Lynx Server (will also work with Ubuntu 12.04 and 14.04) to respond to a PXE boot request and present a boot menu ONLY. I will put practical applications such as installing Ubuntu over the network or booting a Live CD over the network into separate future articles.
Pre-requisites:
- A PC or virtual machine with an installation of Ubuntu Server on it. This tutorial was written using an Ubuntu Lucid 10.04 Server, but these instructions will work equally well on nearly any version of Ubuntu Server (tested and working on Ubuntu 12.04 and 14.04). This tutorial will not detail the initial build of a server as it is relatively straight forward.
- A DHCP server that allows you to specific PXE boot information. Most consumer routers will not give you these options. Suitable DHCP servers are the DHCP daemon on Ubuntu Server, third-party Linux router solutions such as Smoothwall or pfSense, and Windows Server among others.
- If your DHCP server is a dedicated network/firewall device that you do not wish to use as a file server to serve the network boot files, then you will need a separate PC to be a file server as well.
- Some free disk space. PXE booting take bugger-all space, but whatever you plan to serve from it will need space. If you plan to setup the Ubuntu Live CD to be bootable from PXE, you will need 700MB+ of hard-drive space on that server. You will need more than this if you wish to host things like multiple LiveCD’s such as both the 32-bit and 64-bit versions, or multiple different distributions.
- A PC workstation that has PXE boot capability. Any PC built in the last 10 years should definitely have this capability, though you may be required to enable it in BIOS. If you do not have a PC that can do this, you can use a virtual machine such as Virtualbox instead (you could have a virtual machine PXE boot off a virtual PXE boot server too! ).
- A copy of Ubuntu Server 10.04 that suits your server’s architecture.
- A copy of the Ubuntu ALTERNATE Install CD 10.04 that we need to get some PXE boot files from. Unfortunately the Live CD does NOT contain the files we need.
At the end of this exercise we will have a PXE server that will boot into a selection menu that will give us choices of things to do. We’re also going to pretty up the menu with a background image instead of just having plain boring text, and we’ll do this using some of the existing elements on the Ubuntu CD as most of the work has been done for you already!
Getting it together:
- Login to your server.
- Let’s install the software we need:
$ sudo apt-get install tftpd-hpa inetutils-inetd
…this will install a Trivial FTP server which is essentially a super-simple FTP server plus the inetd daemon which will listen out for TFTP requests and direct them to the TFTP daemon.Before you ask, no you cannot use a regular FTP daemon like vsftpd or similar. It has to be a TFTP daemon. Beware: Ubuntu has two TFTP options in the repository – you must use the HPA version of the daemon as shown, as it handles large boot images while the other daemon does not. If you don’t use it, you will see boot errors. - By default Ubuntu sets up the TFTP daemon’s root directory to be /var/lib/tftpboot which may not suit your requirements. For the purposes of this tutorial, we will be changing this to /srv/tftp instead. To do this, we need to edit the /etc/inetd.conf file in a text editor:
$ sudo nano /etc/inetd.conf
- Scroll down to the bottom of the file and modify the tftp line (or add it if it’s missing) and substitute /var/lib/tftpboot bit on the end of that line with the path to your preferred directory:
tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /srv/tftp
- Save your changes by pressing CTRL+X and then “Y” and then Enter.
- Now we need to tell the Trivial FTP daemon where our TFTP root is. Open its config file with:
$ sudo nano /etc/default/tftpd-hpa
- Modify the TFTP_DIRECTORY line (usually the fourth line from the top) to be /srv/tftp:
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure" - Save your changes by pressing CTRL+X and then “Y” and then Enter.
- Now we just need to restart the inetd and tftp services with:
$ sudo service inetutils-inetd restart $ sudo service tftpd-hpa restart
- So that’s the TFTP daemon ready to serve files to a PXE agent. Now we need to create the directory where we will be putting all our PXE goodness into:
$ sudo mkdir -p /srv/tftp
- We now need to copy some files off the Ubuntu Alternate Install CD that make up the PXE boot files and the menu config files. I will use the 32-bit disc in this example, though the files are the same on the 64-bit disc for this step. Insert the CD or mount the downloaded Ubuntu Alternate Install CD ISO. In this case I will assume you have a physical CD mounted at /media/cdrom.
$ sudo cp /media/cdrom/install/netboot/pxelinux.0 /srv/tftp
$ sudo mkdir -p /srv/tftp/ubuntu-installer/i386
$ cd /media/cdrom/install/netboot/ubuntu-installer/i386
$ sudo cp -R boot-screens /srv/tftp/ubuntu-installer/i386
$ sudo cp initrd.gz linux /srv/tftp/ubuntu-installer/i386
(if you’re using the 64-bit CD, substitute all instances of “i386″ above with “amd64″ instead.) - Now we need to setup the initial PXE boot process:
$ sudo mkdir /srv/tftp/pxelinux.cfg
$ sudo nano /srv/tftp/pxelinux.cfg/default - You will now be looking at a blank text editor. In this, type the following:
include mybootmenu.cfg
default ubuntu-installer/i386/boot-screens/vesamenu.c32 prompt 0
timeout 100
The timeout 100 line will provide a 10 second countdown before it automatically chooses the default PXE menu option when you boot into it. If you do not want a timeout, then change this to timeout 0 instead. - Press CTRL+X and then “Y” and then Enter to save your changes.
- Now let’s setup our actual boot menu that we’ll be choosing options from:
$ sudo nano /srv/tftp/mybootmenu.cfg
- Again you’ll be looking at a blank text editor. Type (or copy & paste) in the following. Indenting text is not important, but makes it more readable:
menu hshift 13
menu width 49
menu margin 8
menu title My Customised Network Boot Menu
include ubuntu-installer/i386/boot-screens/stdmenu.cfg
menu begin Cool options
default myfirstoption
label myfirstoption
menu label This is a menu item
label mysecondoption
menu label This is another option
menu end - Press CTRL+X, then press “Y” and then Enter to save your changes.
- Finally, we need to change the permissions of all files concerned because TFTP will not read any files unless they are set to full access:
$ sudo chmod 777 -R /srv
- That’s PXE server side ready to go. Now we need to tell PXE clients where to find the PXE boot server. If you are NOT using Ubuntu as your DHCP server, then skip to step 23, otherwise do the following:
$ sudo nano /etc/dhcp3/dhcpd.conf
- This opens up the DHCP config file into your text editor. Assuming your PXE server is at 192.168.0.10, scroll right to the very bottom of this file and add the following:
next-server 192.168.0.10;
filename "pxelinux.0";
(note the semi-colon on the end) - Press CTRL+X, then “Y” and then Enter to save your changes.
- Restart the DHCP daemon with:
$ sudo service dhcp3-server restart
- If you’re using a non-Ubuntu DHCP server, then look for any “network boot” options and specify the PXE boot server’s IP address and path to the pxelinux.0 file there. For example, in Smoothwall, you would go to Services->DHCP and then check the “Network boot enabled” checkbox, then specify “192.168.0.10” (to suit our tutorial) into the “Boot server” box and “pxelinux.0″ in the “Boot filename” box and “/srv/tftp” in the “Root path” box.
- We should now be ready to try out our PXE boot server! On your test workstation or VM, enable booting off the network (in the case of PXE booting a Virtualbox VM, you must ensure that the network adapter is set to “bridged mode” instead of “NAT” and fire away. You should first see your PC launch its PXE agent, looking for a DHCP server to tell it where the PXE server is:
- If your PXE server is working, within a few seconds you will see your boot menu!
- …and if you hit Enter on “cool options” you will now see a sub-menu showing your two options that we created.
- Well this is all well and good, but the menu currently doesn’t actually DO anything other than show us a bunch of options. How about we provide something, say the Memory Test application from the Ubuntu Alternate Install CD? Plus we’ll add an option to boot from the first HDD in your system. If your CD is still mounted on the server, then go back into the terminal you’ve been working in and copy over the MemTest app as follows:
$ sudo cp /media/cdrom/install/mt86plus /srv/tftp
- Now let’s add a menu entry for it:
$ sudo nano /srv/tftp/mybootmenu.cfg
- Modify the file so that it now looks like the following (add just the bolded lines):
menu hshift 13
menu end
menu width 49
menu margin 8
menu title My Customised Network Boot Menu
include ubuntu-installer/i386/boot-screens/stdmenu.cfg
label Boot from the first HDD
localboot 0 label Memory Tester
kernel mt86plus
menu begin Cool options
default myfirstoption
label myfirstoption
menu label This is a menu item
label mysecondoption
menu label This is another option - Save your changes and exit.
- Ensure the permissions of everything, including our newly copied files, have the correct permissions for TFTP to work:
$ sudo chmod 777 -R /srv
- Reboot your test PC via PXE and this time you will see your menu sports the new menu options at the top (you could have equally placed them at the bottom too):
- Choosing “Memory Tester” from the menu will launch the MemTest app straight away, just like off the CD.
But by now you are probably wondering “Aren’t we building off Ubuntu 10.04? Why does the menu have the old logo on it? Can we change it?”
Sure, we can! - The Ubuntu 10.04 installer CD has got the new Ubuntu logo, but for some reason it’s only saved as a PCX file which won’t work for the PXE boot menu. We can fix this by simply re-saving the PCX file as a PNG file. To start with, get a copy of the splash.pcx file from the /isolinux directory on the Ubuntu CD. This is the new Ubuntu logo that you normally see on the CD’s boot menu.
- Load this file into an image editor such as The GIMP and re-save it as a PNG file, eg: splash.png (of course there’s nothing stopping you from creating your own graphic either – just make sure it’s no greater than 640×480 in size and indexed down to 16 colours).
- Copy the re-saved image file into /srv/tftp/ubuntu-installer/i386/boot-screens and overwrite the original splash.png file.
- Ensure that the permissions of the newly added file is set correctly again with:
$ sudo chmod 777 -R /srv/tftp
- And when you reboot your PXE workstation again, your menu will now look like:
- And there you have it. A working PXE server with menu!
I will document further uses of the PXE boot facility in future articles, including how to boot the Live CD environment without the CD or a USB key, setup the ability to use your local Ubuntu mirror as an installation source for new installs, how to launch tools like Clonezilla and DBAN, and also how to setup a diskless boot system that uses PXE to do a normal Ubuntu desktop boot directly off the network without a local hard-drive.
Stay tuned!
Leave a Reply