RSS Feed
May 30

HowTo: Setup your own PXE Boot Server using Ubuntu Server

Posted on Sunday, May 30, 2010 in Tutorials

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 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. 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:

  1. Login to your server.
    .
  2. 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.

  3. 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
  4. 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
  5. Save your changes by pressing CTRL+X and then “Y” and then Enter.
    .
  6. 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
  7. 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"
  8. Save your changes by pressing CTRL+X and then “Y” and then Enter.
    .
  9. Now we just need to restart the inetd and tftp services with:
    $ sudo service inetutils-inetd restart
    $ sudo service tftpd-hpa restart
  10. 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
  11. 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.)
    .

  12. Now we need to setup the initial PXE boot process:
    $ sudo mkdir /srv/tftp/pxelinux.cfg
    $ sudo nano /srv/tftp/pxelinux.cfg/default
  13. 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.

  14. Press CTRL+X and then “Y” and then Enter to save your changes.
    .
  15. Now let’s setup our actual boot menu that we’ll be choosing options from:
    $ sudo nano /srv/tftp/mybootmenu.cfg
  16. 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

  17. Press CTRL+X, then press “Y” and then Enter to save your changes.
    .
  18. 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
    
  19. 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
  20. 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)
    .

  21. Press CTRL+X, then “Y” and then Enter to save your changes.
    .
  22. Restart the DHCP daemon with:
     

    $ sudo service dhcp3-server restart
  23. 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.An example of configuring Smoothwall to allow PXE booting
    .
  24. 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:

  25. 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.
    .
  26. 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
  27. Now let’s add a menu entry for it:
    $ sudo nano /srv/tftp/mybootmenu.cfg
  28. Modify the file so that it now looks like the following (add just the bolded lines):
    menu hshift 13
    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
    menu end
  29. Save your changes and exit.
    .
  30. Ensure the permissions of everything, including our newly copied files, have the correct permissions for TFTP to work:
    $ sudo chmod 777 -R /srv
  31. 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):
  32. 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!
    .
  33. 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.
    .
  34. 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).
    .
  35. Copy the re-saved image file into /srv/tftp/ubuntu-installer/i386/boot-screens and overwrite the original splash.png file.
    .
  36. Ensure that the permissions of the newly added file is set correctly again with:
    $ sudo chmod 777 -R /srv
  37. 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 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!

31 people like this post.

Bring on the comments!

  1. [...] my article about creating your own PXE network boot server, here is the first practical use you can put it to – taking the Ubuntu Live CD and turning it [...]

  2. Raf68 says:

    Is there a ; missing at step 20 ( at the “next-server” line ).

    Excellent explanations tough.

  3. HyRax says:

    Well spotted! Fixed.

  4. Onni says:

    Hi HyRax,

    Nice article, but when i tried to build it with Ubuntu Image 10.04.1 it fails, after searching for a while i found this article: https://help.ubuntu.com/community/PXEInstallServer witch says there is a bug in the Ubuntu 10.04 inetutils-inetd package and the workaround is to use the openbsd-inetd package instead.

    So keep up the good work..

  5. HyRax says:

    That’s unusual – I’m using 10.04 PXE myself without any issues and I’ve built several 10.04 PXE servers for clients which are all working nicely too!

    I have inetutils-inetd 2:1.6-3 installed. The Ubuntu Wiki article was last edited in July 2010, so things have likely changed since then.

  6. jokre says:

    Just a comment on step 13…

    I had to change the path
    boot-screens/vesamenu.c32
    to
    ubuntu-installer/i386/boot-screens/vesamenu.c32
    to get it to work. If not, I got error messages on the PXE client that it couldn’t find the vesamenu.c32 file during boot.

    Other than that, it’s a great walkthrough to get PXE boot to work on the network. I had some issues with the mentioned Ubuntu 10.04 inetutils-inetd bug, so I used the openbsd-inetd package and it solved the problem. Using inetutils-inetd just made the PXE client try (until reaching timeout) to
    connect to the server, but not ever succeeding. Replacing the inetd package
    solved it straight away and I could use the HowTo with no other modifications (added a DHCP server on the same machine though).

  7. HyRax says:

    Cheers on spotting the error with step 13 – that’s a big one. Not sure how that lasted for so long! Fixed.

    As for the inetd bug, I have to admit I have not experienced that problem myself (and I’ve built several 10.04 PXE servers for clients), but glad you managed to work it out.

  8. Karthik says:

    Hi

    Thanks for the wonderful explanation. But I had few issues with them.

    $ sudo cp /media/cdrom/install/netboot/pxelinux.0 /srv/tftp

    I’ve faced issue at this step, where I was not able to copy the file using terminal and I had to manually copy paste the file. I hope there should not be any issue with that. Is there a way to verify if that file got right stuff inside?

    $ sudo /etc/init.d/dhcpd restart
    When I tried this step, it throwed an weeoe stating “sudo: /etc/init.d/dhcp3: command not found

    I’m a beginner and trying to set up a server so that other systems in my small office can PXE boot over this server. I’ll be grateful if you can help me on this.

    I’m using Ubuntu 10.10 Maverick

  9. HyRax says:

    There is no issue with copying files using any other method.

    As for restarting DHCP, you are using a later release of Ubuntu where services are treated differently. Try using sudo service dhcp3-server restart instead, or alternatively, simply restart your server. I’ve updated my article to reflect this as a correction.

    Finally, if you are building this machine for use in an office, I would recommend using the LTS releases of Ubuntu instead (the most recent one being Lucid 10.04) as they are supported for five years on the server by Canonical, whereas the in-between releases like Maverick are only supported for 18 months. Use Maverick on the desktop instead.

  10. Karthik says:

    I tried the new command and that throws an error too.
    I’ve got another question. I’ve connected my server(I have only one network card in my server and if this works I’ll add another one to connect to modem) to a switch and connected another PC to that switch and trying to boot through that switch. Do you think this is advisable or should I need to include anything on the networking side (I thought this could help since your instructions doesn’t have anything related to networking).

  11. Karthik says:

    I tried the new command and that throws an error too. Anyways I’m downloading Lucid to reinstall the server (Thanks for the suggestion).
    I’ve got another question. I’ve connected my server(I have only one network card in my server and if this works I’ll add another one to connect to modem) to a switch and connected another PC to that switch and trying to boot through that switch. Do you think this is advisable or should I need to include anything on the networking side (I thought this could help since your instructions doesn’t have anything related to networking).

  12. Karthik says:

    I think I’ve got the issue. I don’t have the alternate version CD. Do I need to download server installation CD and Alternate CD separately?

  13. HyRax says:

    The instruction is pretty clear in the pre-requisites that you need the Alternate Install disc to get the required PXE boot files from it,

    The Server disc is only needed if you are planning on installing Ubuntu Server which is the suggested approach to this project. It’s perfectly possible to create a PXE server using the Ubuntu Desktop installation, but regardless, you still need the Alternate disc to get the PXE boot files from.

    As for setting up DHCP and a network in general, that is beyond the scope of this article. There are tonnes of articles out there that describe how to setup a DHCP server in Ubuntu. Exercise your Google-Fu – you will be rewarded.

  14. Karthik says:

    Is there any other way to get the PXE boot files other than downloading the whole bunch of files.

    Googling is what I’m doing for the past one week, still no luck with setting it up. I’m afraid I’ll have to let it go.

    Anyways thanks for you help so far. You’re doing a great job.

  15. HyRax says:

    The Alternate Install CD is only 700MB – it’s one ISO file.

    It’s also a useful disc for older machines that don’t have enough RAM to install via the Live CD. The installation process is also faster with the Alternate Disc. Why wouldn’t you want to download it?

    C’mon – stop being so picky. Get the tools to do the job you are wanting to do. Why make it harder for yourself by trying to find work arounds?

    As for Googling, search queries like “DHCP Server Ubuntu” bring up a host of tutorials on how to setup a DHCP server using Ubuntu.

  16. ducky says:

    Hi there,

    Very nice work with the tutorial!

    I would like to point out something at step 11.
    The install directory doesn’t have the netboot directory any more.
    I couldn’t find it either on ubuntu 10.10 or 10.04 LTS (ISO image downloaded from http://www.ubuntu.com)

    Maybe you could add the files to be downloaded or point to where they can be downloaded.

    But it is true that you point out assuming the reader has a physical cd from ubuntu.
    Maybe the files are then located at where you said.

    Anyway cheers and thank you!

  17. HyRax says:

    The required netboot files are located on the ALTERNATE INSTALL CD. They are NOT available on the Live CD. I clearly state this in the pre-requisites and even mention it in Step 11.

    Yes, I could post a link to an archive of the required files, but they could be dubious in nature. I would much rather people download from an official source so that there’s no chance that the files have been tampered with.

  18. Karthik says:

    I was able to setup DHCP and also I’ve downloaded the alternate CD to copy the files. Now when I boot another it shows an error “No boot file received”. Can you tell me where I’m going wrong?

  19. HyRax says:

    That means there is an error in your PXE configuration on the DHCP server.

    Go back and check your configuration and make sure your TFTP directory is world-readable as per step 18.

  20. Jeramy says:

    Great tutorial. Thank you for the detail.

  21. Chris says:

    Thank you so much. Great tutorial!

  22. Pete says:

    Thanks a lot for the guide, been looking for an easy way to get Ubuntu Live working over PXE in a mainly Windows environment and your guide has essentially done all the work for me.

    One question though… the splash.png logo pops up twice on the menu screen, once in the normal place and then once at the very bottom of the screen. I ran through the guide on a virtual server before and it didn’t do this, has only happened when I recreated the configuration on a physical host.

    Any ideas?

  23. HyRax says:

    Is the splash tiled on the screen or something? Or is the second image squashed in at the bottom?

    Try booting on a different PC with a different gfx chipset and see if the problem is still there. If it isn’t, then I’d say it’s a local rendering issue with just that PC, as I have personally never seen that issue.

  24. Pete says:

    It might be tiled somehow, it appears in the usual place, but then also right at the bottom of the screen directly behind where the timeout text is. I’ll try a different system in a bit, so far I tried PXE booting from a hyper-v machine and a few HP desktops but to be honest the HPs probably all had the same Intel chipset. It’s not the end of the world, I’m just trying to get the system to look neat for the boss :)

  25. Jared says:

    When I try to do step #19, I am given a blank text file. I think I may be missing something?

    Or maybe I’m supposed to be editing the dhcpd.conf file instead of dhcp.conf?

  26. HyRax says:

    You are absolutely right – it’s dhcpd.conf not dhcp.conf – that’s what happens when I get used to tab-completing everything, but then don’t copy & paste for tutorials! Fixed.

  27. Tony Khiami says:

    Is it possible to install WinXP using ubuntu PXE?

  28. HyRax says:

    Yes it is, but you need to either setup a FreeDOS environment with working network drivers (painful), or a WinPE image with working network drivers (less painful), to map a drive to a Samba share where the XP install files are and kick off the install.

    The Windows installer will prep the local HDD (partition/format), copy the install files locally and then reboot to continue the installation “natively”.

    This will be the subject of a future article once I get around to writing it!

  29. nolance says:

    my current Os is win7 and i want to text PXE functioning . so i installed ubuntu 11.04(desktop edition) in VirtualBox and then performed the steps 1-18 successfully.
    i used the netbook.tar.gz in place of alternate CD and 1-18 steps didnt show any problems.Also i changed the mode of the network adapter from NAT to Bridged Mode.
    and now i created another Blank virtualmachine with no OS inorder to install ubuntu from the previously created UbuntuVirtualMachine. and im stuck at step-19.i have installed dhcp server on the first virtual machine but i have absolutely no clue about how to proceed from there keeping in view the virtual machine im using and the IP address that im supposed to use for the 2 VMs to connect to each other.Please help me regarding this!

  30. HyRax says:

    You must ensure that you only have ONE DHCP SERVER on your network. That means disable the DHCP server on your router or whatever else is currently serving addresses on your network, or they will clash. Make sure that your VM’s are picking up an IP address from your new DHCP server, not your original DHCP server.

  31. Hans says:

    Hi,
    First: thanks for the great howto. Was looking for something exactly like this…

    I do have a problem though. Everything seems to be in order on my 10.04 PXE server that serves as a DHCP server as well. Booting the client PC from network seems to work, because I see the client getting an IP address. But then nothing happens anymore. The only thing I see on the server in syslog is from tftp: client does not accept options, but that does not seem to be a problem.
    Any idea why the client seems to hang after IP assignment ?

    Thanks,
    Hans

  32. Hans says:

    HOLD PRESSES !
    To answer my own question: It turns out that there were two pxelinux.0 files on the DVD.
    One with size 0, and one with size 15k.
    I copied the empty one over….
    After replacing this empty one with the right one, everything works perfectly.

    Thanks again.

  33. HyRax says:

    Two of them? Never seen that… Are you using an official ISO? Glad you got it sorted, though.

  34. Hans says:

    Yep,

    They are both on the 64 bit iso I downloaded from an Ubuntu mirror.
    The empty one is in install/netboot, the right one is in install/netboot/ubuntu-installer/amd64

  35. Benny says:

    For those of you already have a dhcp server you can use the ProxyDHCP method using dnsmasq instead of dhcp3-server. it can also be used as a tftp server.

  36. siLDes says:

    Hi there thanks for the great info …

    i followed all your steps … but
    when i boot using a diskless system

    is says ..

    Client IP : 192.168.1.200 Mask : 255.255.255.0 DHCP IP : 192.168.1.102 Gateway IP : 192.168.1.200

    PXE-E11: ARP timeout
    PXE-E38: TFTP cannot open connection
    PXE-M0F: Exiting PXE ROM.

    Help .. Thanks ..

  37. HyRax says:

    Looks to me that your server is not accepting TFTP requests. Either the TFTP daemon isn’t running or your server has a firewall blocking the connection, or you have SELinux installed, etc. Go over your configuration and double-check everything.

    Nine times out of ten, the issue will always be a small typo or you missed a step. If you follow everything here to the letter with a standard Ubuntu Server installation, you will have a perfectly working PXE boot server.

  38. siLDes says:

    XD … silly me … typo

  39. battler says:

    Installing a pxe server for my classroom, couldn’t have done it without you. excellent guide, just perfect!

  40. Will says:

    Great tutorial. It would have taken me forever to figure this out without your help.

    I ran into the same issue as Hans with the two versions of pxelinux.0 except mine was the 32-bit version of Server 10.04, also an official ISO.

    I’m working on a project where I need 10 workstations for browsing a network share only. This is working beautifully so far.

    Thanks!

  41. kiems says:

    Great tutorial, first time setting up pxe environment on Linux. Worked really well. Thanks for taking the time to write the article.

  42. Ben Sheppard says:

    When I try sudo service tftpd-hpa restart is says /srv/tftp missing: aborted
    Any Ideas?

  43. HyRax says:

    Have you done step 10 and 36?

Leave a Reply

Spam Protection by WP-SpamFree