Archives May 2010

HowTo: Get an Ubuntu Live CD to boot off a PXE server

Following 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 into a network-bootable version!

Network booting the Live CD has obvious advantages – aside from booting faster than CD (especially on a gigabit network), it is indispensable as an emergency boot medium in a workplace environment, especially for broken Windows systems, and allows for Ubuntu effortless installations on netbook PC’s that don’t have optical drives and saves you having to have a USB stick handy.

Pre-requisites

  • You need a working Linux PXE boot server. Doesn’t have to be Ubuntu, but it needs to be Linux. You cannot use a Windows PXE server.
  • An Ubuntu 10.04 Live CD ISO or physical CD. Can be the 32-bit or 64-bit ISO, but you can also setup both of them at once!
  • At least 700MB of drive space on your PXE server, more if you want to have more than one CD available.
  • This tutorial was put together using Ubuntu Server 10.04 Lucid Lynx, but should work with all future releases and older versions to at least Ubuntu Server 8.04 Hardy Heron.

Getting it together

  1. Login to your PXE server and mount the CD or ISO image (in this example we are copying the 32-bit disc). Assuming the CD is mounted at /media/cdrom, copy the CD’s files to your server as follows:

    $ sudo mkdir -p /srv/tftp/ubuntu-livecd-boot/i386
    $ sudo mkdir -p /srv/ubuntu-livecd/i386
    $ sudo cp -av /media/cdrom/* /srv/ubuntu-livecd/i386
    $ sudo cp -av /media/cdrom/.disk /srv/ubuntu-livecd/i386
    $ sudo cp -av /media/cdrom/casper/initrd.lz /srv/tftp/ubuntu-livecd-boot/i386
    $ sudo cp -av /media/cdrom/casper/vmlinuz /srv/tftp/ubuntu-livecd-boot/i386
  1. (if you want to setup the 64-bit disc, then replace all instances of “i386″ with “amd64″, or you can setup both architectures by setting up both directories)
  2. Make sure the permissions of the files to be loaded by TFTP are correct:

    $ sudo chmod 777 -R /srv/tftp
  3. The astute of you will have noticed that we have copied the Ubuntu CD outside of the TFTP directory and that we have made a separate copy of only two of the disc’s files inside the TFTP directory. Why is this? Well, the vmlinuz and initrd.lz files are the only files that TFTP will need to download to get started with the boot process. After that, we will use NFS to deliver the rest of the Live CD, so let’s set that up:

    $ sudo apt-get install nfs-kernel-server

    Note: I should point out that the files that are copied to the NFS share do not have to be on the PXE server. The NFS server can be any box as NFS is not related to PXE at all.
  4. Once that is installed, we need to define an NFS share. This is done in the NFS exports file, so let’s get that into a text editor:

    $ sudo nano /etc/exports
  5. Add the following line to the bottom of the file:

    # Ubuntu Live CD files for PXE booting
    /srv/ubuntu-livecd/i386        *(ro,async,no_root_squash,no_subtree_check)


    …if you are setting up the 64-bit version, replace “i386″ with “amd64″, or if setting up both architectures, list it as follows:

    # Ubuntu Live CD files for PXE booting
    /srv/ubuntu-livecd/i386        *(ro,async,no_root_squash,no_subtree_check)
    /srv/ubuntu-livecd/amd64       *(ro,async,no_root_squash,no_subtree_check)


    A breakdown of the parameters on the right is as follows:
    • The asterisk means “share with everyone on this network, regardless of who they are”.
    • The “ro” parameter means to share the data as read-only.
    • The “async” parameter allows the NFS server to reply before data is written to the share. Since it’s mounted as read-only anyway, the parameter is only there to keep NFS’ syntax happy.
    • The “no_root_squash” parameter means to allow the NFS client to use the mount as a root filesystem, otherwise it’s mounted as “nobody” instead of “root”. Since the LiveCD is essentially a diskless client, we need to be able to define the NFS mount as a root volume.
    • The “no_subtree_check” parameter helps to speed up transfers. Normally NFS will check to see if a requested file exists in an exported sub-directory. This slows things down, so turning this off means the only check that is made is that the requested file exists on the exported filesystem. Subtree checking can also cause issues when an open file is renamed, but since the export is read-only, this is irrelevant.
  6. Save your changes with CTRL+X, then “Y” and then Enter.
  7. Now have NFS re-read its export file and begin sharing the specified directories with:

    $ sudo exportfs -a
  8. We’re nearly ready to rock and/or roll. All we need to do now is prepare the PXE boot menu to launch the Live CD for us. Assuming you followed by previous tutorial and your boot menu file is called mybootmenu.cfg:

    $ sudo nano /srv/tftp/mybootmenu.cfg
  9. Assuming your NFS server’s IP address is 192.168.0.10, insert the following lines for a 32-bit Live CD entry:

    label Live CD 32-bit
        kernel ubuntu-livecd-boot/i386/vmlinuz
        append boot=casper netboot=nfs nfsroot=192.168.0.10:/srv/ubuntu-livecd/i386 initrd=ubuntu-livecd-boot/i386/initrd.lz -- splash quiet


    …and if you are doing 64-bit, you can replace or add as a separate menu option the following:

    label Live CD 64-bit
        kernel ubuntu-livecd-boot/amd64/vmlinuz
        append boot=casper netboot=nfs nfsroot=192.168.0.10:/srv/ubuntu-livecd/amd64 initrd=ubuntu-livecd-boot/amd64/initrd.lz — splash quiet

    The kernel line is the actual kernel that is loaded to run the session. The append line tells the boot process several things. First up, the casper directory contains the boot files (a SquashFS image in the case of the Live CD), the root of the NFS file system is located on the server with the IP 192.168.0.10 under the path /srv/ubuntu-livecd/i386 (or amd64) and that the image to fire up the RAM disk with is located under ubuntu-livecd/i386/initrd.lz and finally we have advised the boot process to suppress console messages and display the splash screen while loading. From this point on, the initrd.lz is extracted and will grab the SquashFS image from the casper directory via NFS, extract it and commence running it. All other files that the disc needs to do its thing (such as when installing Ubuntu from the Live environment) are also provided by the NFS share.
  10. Save your changes by pressing CTRL+X, then “Y” and then Enter.
  11. You’re now ready to go – reboot your PXE workstation and you should now see an entry for your Live CD. Upon choosing it, your system should fire up with the Live environment! Once booted, you can even do an Ubuntu install to the PC you started on as though you’d booted from a CD or USB device!

The PXE boot menu

Enjoy! Smilie: :)

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.

Network Cable Ball

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! Smilie: :) ).
  • 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.
Configuring the PXE boot file in Smoothwall Express
  1. 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”Smilie: ;) 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:
Beginning PXE boot…
  1. If your PXE server is working, within a few seconds you will see your boot menu!
Boot menu success!
  1. …and if you hit Enter on “cool options” you will now see a sub-menu showing your two options that we created.
The secondary menu.
  1. 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
  2. Now let’s add a menu entry for it:

    $ sudo nano /srv/tftp/mybootmenu.cfg
  3. 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
  4. Save your changes and exit.
  5. Ensure the permissions of everything, including our newly copied files, have the correct permissions for TFTP to work:

    $ sudo chmod 777 -R /srv
  6. 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):
Our HDD boot menu entry
  1. 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!
  2. 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.
  3. 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).
  4. Copy the re-saved image file into /srv/tftp/ubuntu-installer/i386/boot-screens and overwrite the original splash.png file.
  5. Ensure that the permissions of the newly added file is set correctly again with:

    $ sudo chmod 777 -R /srv/tftp
  6. And when you reboot your PXE workstation again, your menu will now look like:
The updated Ubuntu logo in out PXE menu
  1. 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!