{"id":53,"date":"2010-05-30T08:21:00","date_gmt":"2010-05-29T22:21:00","guid":{"rendered":"https:\/\/www.serenux.com\/?p=53"},"modified":"2021-01-14T08:47:45","modified_gmt":"2021-01-13T22:47:45","slug":"howto-setup-your-own-pxe-boot-server-using-ubuntu-server","status":"publish","type":"post","link":"https:\/\/www.serenux.com\/index.php\/2010\/05\/30\/howto-setup-your-own-pxe-boot-server-using-ubuntu-server\/","title":{"rendered":"HowTo: Setup your own PXE Boot Server using Ubuntu Server"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150311192753im_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/NetworkCableBall.png\" alt=\"Network Cable Ball\"\/><\/figure><\/div>\n\n\n\n<p>Why would you want to boot a PC from the network? Well, it opens the door to booting diskless workstations, eg: Internet Cafe PC\u2019s, or if you regularly install tens or hundreds of PC\u2019s, 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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><em><strong>Pre-requisites:<\/strong><\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>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.<\/li><li>A DHCP server that allows you to specific PXE boot information. Most consumer routers will&nbsp;not&nbsp;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.<\/li><li>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.<\/li><li>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\u2019s such as both the 32-bit and 64-bit versions, or multiple different distributions.<\/li><li>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!&nbsp;<img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150311192753im_\/http:\/\/www.serenux.com\/wp-content\/themes\/grey-opaque\/plugins\/lazy-load\/images\/1x1.trans.gif\" alt=\"Smilie: :)\">&nbsp;).<\/li><li>A copy of Ubuntu Server 10.04 that suits your server\u2019s architecture.<\/li><li>A copy of the Ubuntu ALTERNATE Install CD 10.04 that we need to get some PXE boot files from. Unfortunately&nbsp;<strong>the Live CD does NOT contain the files we need.<\/strong><\/li><\/ul>\n\n\n\n<p>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\u2019re also going to pretty up the menu with a background image instead of just having plain boring text, and we\u2019ll do this using some of the existing elements on the Ubuntu CD as most of the work has been done for you already!<\/p>\n\n\n\n<p><em><strong>Getting it together:<\/strong><\/em><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Login to your server.<br><\/li><li>Let\u2019s install the software we need:<br><br><code>$ sudo apt-get install tftpd-hpa inetutils-inetd<\/code><br><br>\u2026this 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\u00a0<em>vsftpd<\/em>\u00a0or similar. It has to be a TFTP daemon. Beware: Ubuntu has two TFTP options in the repository \u2013 you\u00a0<em>must<\/em>\u00a0use the HPA version of the daemon as shown, as it handles large boot images while the other daemon does not. If you don\u2019t use it, you will see boot errors.<br><\/li><li>By default Ubuntu sets up the TFTP daemon\u2019s root directory to be\u00a0<em>\/var\/lib\/tftpboot<\/em>\u00a0which may not suit your requirements. For the purposes of this tutorial, we will be changing this to\u00a0<em>\/srv\/tftp<\/em>\u00a0instead. To do this, we need to edit the\u00a0<em>\/etc\/inetd.conf<\/em>\u00a0file in a text editor:<br><br><code>$ sudo nano \/etc\/inetd.conf<\/code><br><\/li><li>Scroll down to the bottom of the file and modify the\u00a0<em>tftp<\/em>\u00a0line (or add it if it\u2019s missing) and substitute\u00a0<em>\/var\/lib\/tftpboot<\/em>\u00a0bit on the end of that line with the path to your preferred directory:<br><br><code>tftp\u00a0\u00a0\u00a0 dgram\u00a0\u00a0 udp\u00a0\u00a0\u00a0 wait\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0 \/usr\/sbin\/in.tftpd \/usr\/sbin\/in.tftpd -s <strong>\/srv\/tftp<\/strong><br><\/code><\/li><li>Save your changes by pressing CTRL+X and then \u201cY\u201d and then Enter.<br><\/li><li>Now we need to tell the Trivial FTP daemon where our TFTP root is. Open its config file with:<br><br><code>$ sudo nano \/etc\/default\/tftpd-hpa<\/code><br><\/li><li>Modify the\u00a0<em>TFTP_DIRECTORY<\/em>\u00a0line (usually the fourth line from the top) to be\u00a0<em>\/srv\/tftp<\/em>:<br><br><code># \/etc\/default\/tftpd-hpa<br><br>TFTP_USERNAME=\"tftp\"<br><strong>TFTP_DIRECTORY=\"\/srv\/tftp\"<\/strong><br>TFTP_ADDRESS=\"0.0.0.0:69\"<br>TFTP_OPTIONS=\"--secure\"<\/code><br><\/li><li>Save your changes by pressing CTRL+X and then \u201cY\u201d and then Enter.<br><\/li><li>Now we just need to restart the inetd and tftp services with:<br><br><code>$ sudo service inetutils-inetd restart $ sudo service tftpd-hpa restart<\/code><br><\/li><li>So that\u2019s 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:<br><br><code>$ sudo mkdir -p \/srv\/tftp<\/code><br><\/li><li>We now need to copy some files off the Ubuntu\u00a0<strong>Alternate<\/strong>\u00a0Install 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\u00a0<strong>Alternate<\/strong>\u00a0Install CD ISO. In this case I will assume you have a physical CD mounted at\u00a0<em>\/media\/cdrom<\/em>.<br><br><code>$ sudo cp \/media\/cdrom\/install\/netboot\/pxelinux.0 \/srv\/tftp<br>$ sudo mkdir -p \/srv\/tftp\/ubuntu-installer\/i386<br>$ cd \/media\/cdrom\/install\/netboot\/ubuntu-installer\/i386<br>$ sudo cp -R boot-screens \/srv\/tftp\/ubuntu-installer\/i386<br>$ sudo cp initrd.gz linux \/srv\/tftp\/ubuntu-installer\/i386<\/code><br><br>(if you\u2019re using the 64-bit CD, substitute all instances of \u201ci386\u2033 above with \u201camd64\u2033 instead.)<br><\/li><li>Now we need to setup the initial PXE boot process:<br><br><code>$ sudo mkdir \/srv\/tftp\/pxelinux.cfg<br>$ sudo nano \/srv\/tftp\/pxelinux.cfg\/default<\/code><br><\/li><li>You will now be looking at a blank text editor. In this, type the following:<br><br><code>include mybootmenu.cfg<br>default ubuntu-installer\/i386\/boot-screens\/vesamenu.c32 prompt 0<br>timeout 100<\/code><br><br>The\u00a0<em>timeout 100<\/em>\u00a0line 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\u00a0<em>timeout 0<\/em>\u00a0instead.<br><\/li><li>Press CTRL+X and then \u201cY\u201d and then Enter to save your changes.<br><\/li><li>Now let\u2019s setup our actual boot menu that we\u2019ll be choosing options from:<br><br><code>$ sudo nano \/srv\/tftp\/mybootmenu.cfg<\/code><br><\/li><li>Again you\u2019ll be looking at a blank text editor. Type (or copy &amp; paste) in the following. Indenting text is not important, but makes it more readable:<br><br><code>menu hshift 13<br>menu width 49<br>menu margin 8<br>menu title My Customised Network Boot Menu<br>include ubuntu-installer\/i386\/boot-screens\/stdmenu.cfg<br>menu begin Cool options<br> \u00a0 \u00a0 default myfirstoption<br> \u00a0 \u00a0 label myfirstoption<br> \u00a0 \u00a0 \u00a0 \u00a0 menu label This is a menu item<br> \u00a0 \u00a0 label mysecondoption<br> \u00a0 \u00a0 \u00a0 \u00a0 menu label This is another option<br>menu end<\/code><br><\/li><li>Press CTRL+X, then press \u201cY\u201d and then Enter to save your changes.<br><\/li><li>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:<br><br><code>$ sudo chmod 777 -R \/srv<\/code><br><\/li><li>That\u2019s PXE server side ready to go. Now we need to tell PXE clients where to find the PXE boot server.\u00a0<em>If you are NOT using Ubuntu as your DHCP server, then skip to step 23<\/em>, otherwise do the following:<br><br><code>$ sudo nano \/etc\/dhcp3\/dhcpd.conf<\/code><br><\/li><li>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:<br><br><code>next-server 192.168.0.10;<\/code><br><code>filename \"pxelinux.0\";<\/code><br><br>(note the semi-colon on the end)<br><\/li><li>Press CTRL+X, then \u201cY\u201d and then Enter to save your changes.<br><\/li><li>Restart the DHCP daemon with:<br><br><code>$ sudo service dhcp3-server restart<\/code><br><\/li><li>If you\u2019re using a non-Ubuntu\u00a0DHCP server, then look for any \u201cnetwork boot\u201d options and specify the PXE boot server\u2019s IP address and path to the\u00a0<em>pxelinux.0<\/em>\u00a0file there. For example, in Smoothwall, you would go to Services->DHCP and then check the \u201cNetwork boot enabled\u201d checkbox, then specify \u201c192.168.0.10\u201d (to suit our tutorial) into the \u201cBoot server\u201d box and \u201cpxelinux.0\u2033 in the \u201cBoot filename\u201d box and \u201c\/srv\/tftp\u201d in the \u201cRoot path\u201d box.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150319153140if_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/SmoothwallConfig.png\" alt=\"\"\/><figcaption>Configuring the PXE boot file in Smoothwall Express<\/figcaption><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"24\"><li>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 \u201cbridged mode\u201d instead of \u201cNAT\u201d<img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150311192753im_\/http:\/\/www.serenux.com\/wp-content\/themes\/grey-opaque\/plugins\/lazy-load\/images\/1x1.trans.gif\" alt=\"Smilie: ;)\">\u00a0and 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:<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150319153146if_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/PXEStartBooting.png\" alt=\"\"\/><figcaption>Beginning PXE boot&#8230;<\/figcaption><\/figure><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"25\"><li>If your PXE server is working, within a few seconds you will see your boot menu!<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150320084842if_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/PXEMenu1.png\" alt=\"\"\/><figcaption>Boot menu success!<\/figcaption><\/figure><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"25\"><li>\u2026and if you hit Enter on \u201ccool options\u201d you will now see a sub-menu showing your two options that we created.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150320084846if_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/PXEMenu2.png\" alt=\"\"\/><figcaption>The secondary menu.<\/figcaption><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"25\"><li><a href=\"https:\/\/web.archive.org\/web\/20150311192753\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/PXEMenu2.png\"><\/a><\/li><li>Well this is all well and good, but the menu currently doesn\u2019t 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\u2019ll 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\u2019ve been working in and copy over the MemTest app as follows:<br><br><code>$ sudo cp \/media\/cdrom\/install\/mt86plus \/srv\/tftp<\/code><br><\/li><li>Now let\u2019s add a menu entry for it:<br><br><code>$ sudo nano \/srv\/tftp\/mybootmenu.cfg<\/code><br><\/li><li>Modify the file so that it now looks like the following (add just the bolded lines):<br><br><code>menu hshift 13<br>menu width 49<br>menu margin 8<br>menu title My Customised Network Boot Menu<br>include ubuntu-installer\/i386\/boot-screens\/stdmenu.cfg<br><strong>label Boot from the first HDD<\/strong><br><strong> \u00a0\u00a0\u00a0 localboot 0 label Memory Tester<\/strong><br><strong> \u00a0\u00a0\u00a0 kernel mt86plus<\/strong><br>menu begin Cool options<br> \u00a0 \u00a0 default myfirstoption<br> \u00a0 \u00a0 label myfirstoption<br> \u00a0 \u00a0 \u00a0 \u00a0 menu label This is a menu item<br> \u00a0 \u00a0 label mysecondoption<br> \u00a0 \u00a0 \u00a0 \u00a0 menu label This is another option<br><\/code>menu end<br><\/li><li>Save your changes and exit.<br><\/li><li>Ensure the permissions of everything, including our newly copied files, have the correct permissions for TFTP to work:<br><br><code>$ sudo chmod 777 -R \/srv<\/code><br><\/li><li>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):<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150320084850if_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/PXEMenu3.png\" alt=\"\"\/><figcaption>Our HDD boot menu entry<\/figcaption><\/figure><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"32\"><li>Choosing \u201cMemory Tester\u201d from the menu will launch the MemTest app straight away, just like off the CD.<br><br>But by now you are probably wondering \u201cAren\u2019t we building off Ubuntu 10.04? Why does the menu have the old logo on it? Can we change it?\u201d <br><br>Sure, we can!<br><\/li><li>The Ubuntu 10.04 installer CD\u00a0has\u00a0got the new Ubuntu logo, but for some reason it\u2019s only saved as a PCX file which won\u2019t 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\u00a0<em>splash.pcx<\/em>\u00a0file from the\u00a0<em>\/isolinux<\/em>\u00a0directory on the Ubuntu CD. This is the new Ubuntu logo that you normally see on the CD\u2019s boot menu.<br><\/li><li>Load this file into an image editor such as The GIMP and re-save it as a PNG file, eg:\u00a0<em>splash.png<\/em>\u00a0(of course there\u2019s nothing stopping you from creating your own graphic either \u2013 just make sure it\u2019s no greater than 640\u00d7480 in size and indexed down to 16 colours).<br><\/li><li>Copy the re-saved image file into\u00a0<em>\/srv\/tftp\/ubuntu-installer\/i386\/boot-screens<\/em>\u00a0and overwrite the original\u00a0<em>splash.png<\/em>\u00a0file.<br><\/li><li>Ensure that the permissions of the newly added file is set correctly again with:<br><br><code>$ sudo chmod 777 -R \/srv\/tftp<\/code><br><\/li><li>And when you reboot your PXE workstation again, your menu will now look like:<br><\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150320084856if_\/http:\/\/www.serenux.com\/wp-content\/uploads\/2010\/05\/PXEMenu4.png\" alt=\"\"\/><figcaption>The updated Ubuntu logo in out PXE menu<\/figcaption><\/figure><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"32\"><li>And there you have it. A working PXE server with menu!<\/li><\/ol>\n\n\n\n<p>I will document further uses of the PXE boot facility in future articles, including&nbsp;<a href=\"https:\/\/web.archive.org\/web\/20150311192753\/http:\/\/www.serenux.com\/2010\/05\/howto-get-an-ubuntu-live-cd-to-boot-off-a-pxe-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to boot the Live CD environment without the CD or a USB key<\/a>, setup the ability to use your local Ubuntu mirror as an installation source for new installs, how to launch tools like Clonezilla and&nbsp;<a href=\"https:\/\/web.archive.org\/web\/20150311192753\/http:\/\/www.serenux.com\/2014\/05\/howto-setup-dariks-boot-and-nuke-dban-to-automatically-erase-storage-devices-via-pxe-boot\/\" target=\"_blank\" rel=\"noreferrer noopener\">DBAN<\/a>, and also&nbsp;<a href=\"https:\/\/web.archive.org\/web\/20150311192753\/http:\/\/www.serenux.com\/2011\/04\/howto-create-a-diskless-workstation-that-boots-from-pxe-using-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">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<\/a>.<\/p>\n\n\n\n<p>Stay tuned!&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019s, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":1,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}