Home > Howtos > Ubuntu TFTPBoot with no hairloss (8.10 Hardy Heron)

Ubuntu TFTPBoot with no hairloss (8.10 Hardy Heron)

I found out something today that made me want to rip my hair out. The installation and configuration of Ubuntu for TFTP booting was insane and with no authoritative means to do it, spent way longer on trying to get the service working than should have been necessary

I was looking to get tftpd installed and working so I can start netbooting install images to the network for devices without a CDROM drive but could boot from the network. A long time ago, I had a Red Hat 8.0 box running the DHCP server and it was quite trivial to install, configure and add images to the box for network installation.

Well, time has certainly passed since then and the RedHat box succumbed to a faulty power supply. Now I have an Ubuntu box on the network handing out IP addresses. Now, mind you, there are thousands of these howtos on the Internet and a good bit of them will reference inetd.conf or the INET superserver, or xinetd or somewhat. If you are going to be doing this and you don’t want to install unnecessary services, here’s what I did and works just fine.

Prerequisites

You will need the following:

  • A copy of Ubuntu Hardy Heron running on a computer with a NIC
  • A copy of the Ultimate Boot CD (for pretty menus) available here: http://www.ultimatebootcd.com/
  • A copy of pxelinux.0 from here:Syslinux Wiki
  • (Optional) A copy of VMWare Server setup with a VM with network boot as primary boot device OR a second computer to test your booting
  • Installing and configuring tftpd-hpa

    Install the tftpd-hpa service:
    # apt-get install tftpd-hpa

    Edit the /etc/default/tftpd-hpa:
    #Defaults for tftpd-hpa
    RUN_DAEMON="yes"
    OPTIONS="-l -s /tftpboot"


    The -l parameter tells tftpd-hpa to run in “Listen” mode to accept connections and -s sets the root of the TFTP server. I don’t like using the /var/lib/tftpboot directory (old skool RedHat, I guess) so I specified a new directory. Be sure to set “RUN_DAEMON” to “yes” otherwise it will never start. Don’t start the service just yet.

    You will need to edit the DHCP server’s subnet declaration. Add these lines, replace {tftp server} with the IP address, not the host name of the server:

    next-server {tftp server};
    filename "/tftpboot/pxelinux.0";

    This tells the DHCP server that if the client supports network booting to give the client the IP of the TFTP server along with the path to the pxelinux.0 file. Make sure you restart the dhcp server otherwise you will not get the tftp server to work.

    Get the /tftpboot directory set up

    We have the service set up, now it’s time to set up the /tftpboot directory. We’ll start off by creating some directories:
    # mkdir /tftpboot
    # mkdir /tftpboot/menus
    # mkdir /tftpboot/images
    # mkdir /tftpboot/pxelinux.cfg

    The menus directory is where we will keep our menu structure and the images directory will contain the boot disk images of the items we present in the menus.
    Copy the files from the UBCD mount point into the /tftpboot directory:

  • copy the menu.c32 and chain.c32 from the UBCD to /tftpboot drectory
  • copy the defaults.cfg from the UBCD’s menus directory to /tftpboot/menus
  • copy the memtest image from the UBCD into /tftpboot/images
  • copy the pxelinux.0 from the SYSLINUX download into the /tftpboot directory
  • Edit the /tftpboot/pxelinux.cfg/default file:
    default main
    prompt 1
    timeout 600
    label main
    kernel menu.c32
    append menus/main.mnu

    This is the default configuration file that pxelinux looks for when it is loaded on the netbooting computer. It is mandatory that it go in pxelinux.cfg/ as just leaving it in the /tftpboot directory will result in a failure.

    Let’s make a menu

    Now that we have the configuration files in place, let’s write a menu.
    Edit the file main.mnu, save it as /tftpboot/menus/main.mnu:

    MENU INCLUDE /menus/defaults.cfg
    LABEL memtest
    MENU LABEL Memtest86 V3.3
    KERNEL /images/memtest
    APPEND -

    Here’s what the lines do:

  • The MENU INCLUDE includes the defaults.cfg file. This controls how our menus look, color, etc…
  • The LABEL defines the name of the image which is not shown. You will want to have a unique entry for all items in the menus
  • MENU LABEL is the item that is displayed for us to choose from.
  • KERNEL should point to the image to boot from (in this case, it’s memtest)
  • the APPEND statement is not used for this particular image, but is required for others that need additional options on the boot line.
  • Save the file and let’s test it out.

    Let’s test it out

    Now that we have everything set, let’s try it. Boot the test machine and it should give you a lot of fast scrolling text before it goes to the boot menu. Unfortunately, I can’t provide a screenshot, but it will display some configuration text then you’ll be dropped to a “boot:” prompt. If all goes well, you should see a blue menu with the Memtest 86 v3.3 displayed. Hit ENTER and see if it loads. If all goes well, Memtest should be running. If not, take a look at the “Troubleshooting” section.

    More Menus, Boot from hard drives and adding images

    So we have our first netbooting image, you can use the menus to generate additional sub-menus or distribution lists. You can use the menus on the UBCD as an example, but if you’re impatient, here’s some code snippets:

    Menus within menus

    To make a menu show up as an entry in another menu (like the “Mainboard Tools” submenu on the UBCD) use this code:

    LABEL mainboard
    MENU LABEL Mainboard Tools
    KERNEL menu.c32
    APPEND /menus/mboard.mnu

  • LABEL must be unique across all menus
  • MENU LABEL is the entry presented in the parent menu
  • KERNEL must remain menu.c32 (this is what renders the menus)
  • APPEND points to the menu file to load. In this case “mboard.mnu”

    Boot local Hard Drives

    If you want to boot the local hard drive (useful if you accidentally forget to tell the BIOS not to boot from network), add this entry:
    LABEL boothdd0
    MENU LABEL *Boot First Hard Disk
    KERNEL chain.c32
    APPEND hd0

  • Adjust hd0 to which hard drive you want. hd0 translates to primary master, HD3 would be secondary slave, etc…

    Add a Linux Bootdisk to the mix

    Adding a Linux Bootdisk is a lot easier than it sounds, and although I will not cover setting up the FTP server for it in this HOWTO, you’ll still want to boot the disk from the network. (Yes, I’ll write a follow up to this one that includes the FTP portion).

    For now, let’s assume you have the network boot floppy image that you want to add to the menu system. In this section, I’m going to use the RedHat 7.3 net boot floppy image, but any floppy image should work.
    First off, mount the floppy image:
    #mount -o loop bootnet.img /mnt/floppy
    Replace bootnet.img with the filename of the image to mount, and /mnt/floppy with a valid mountpoint.
    change directory to that mountpoint and look for a file called “syslinux.cfg”.
    You should see a listing that looks like this:
    default linux
    prompt 1
    timeout 600
    display boot.msg
    F1 boot.msg
    F2 general.msg
    F3 param.msg
    F4 rescue.msg
    F7 snake.msg
    label linux
    kernel vmlinuz
    append initrd=initrd.img lang= devfs=nomount ramdisk_size=8192 vga=788
    label text
    kernel vmlinuz
    append initrd=initrd.img lang= text devfs=nomount ramdisk_size=8192
    label expert
    kernel vmlinuz
    append expert initrd=initrd.img lang= devfs=nomount ramdisk_size=8192
    label ks
    kernel vmlinuz
    append ks initrd=initrd.img lang= devfs=nomount ramdisk_size=8192
    label nofb
    kernel vmlinuz
    append initrd=initrd.img lang= devfs=nomount nofb ramdisk_size=8192
    label lowres
    kernel vmlinuz
    append initrd=initrd.img lang= lowres devfs=nomount ramdisk_size=8192

    The syslinux.cfg contains the menu for the bootdisk, (much like our main.mnu file from earlier) and will give us what we need to copy in order to add the proper entries in our boot configuration and get the menu working. This file has the same basic syntax that our menu files do and they also tell us what we need to copy. In the example above, we need to copy vmlinuz and initrd.img as both files are referenced in the configuration:
    # cp vmlinuz /tftpboot/images/vmlinuz-rh73-netboot
    # cp initrd.img /tftpboot/images/initrd-rh73-netboot

    I highly recommend that you use this method of copying files. This will help you keep your images directory organized. Nothing sucks worse than deleting an “unused” file only to find that was the ramdisk image needed for another distribution’s installer!

    To add the image to the menu, we need to edit the /tftpboot/menus/main.mnu file again and add the following (that we got from the syslinux.cfg)
    label linux7.3
    menu label Install Redhat 7.3
    kernel /images/vmlinuz-rh73-netboot
    append initrd=/images/initrd-rh73-netboot lang= devfs=nomount ramdisk_size=8192 vga=788

    This is copied from the floppy image’s syslinux.cfg file and edited to reflect the paths to the images we copied to /tftpboot/images earlier. The only exception is the adding of the menu label line and the change of the label line for uniqueness.

    To test it out, just reboot the test computer, select “Install Redhat 7.3″ and you should be looking at the installer after a few minutes.

    Troubleshooting

    My TFTP server isn’t responding!

    Most commonly, this is due to something not right in /etc/default/tftpd-hpa, but you can check it by running this command:
    # /etc/init.d/tftpd-hpa start && ps auwx | grep tftp
    which should return something like the following code. If it doesn’t, check your tftpd-hpa file in /etc/default:
    root@littleblackbox:/tftpboot# /etc/init.d/tftpd-hpa start && ps auwx | grep tftp
    Starting HPA's tftpd: in.tftpd.
    root 11280 0.0 0.0 2220 276 ? Ss 21:26 0:00 /usr/sbin/in.tftpd -l -s /tftpboot
    root 11282 0.0 0.0 3004 768 pts/1 S+ 21:26 0:00 grep tftp
    The second line shows us that tftpd is running, and that the path is set to /tftpboot. This is the correct setup for our tftpboot installation and should work.

    TFTP says File Not Found!

    This is more than likely an issue with Ubuntu. It’s really fond of having multiple configurations in obscure places for the same file. You can check it to see what path is configured for it by running the following command:
    root@littleblackbox:/tftpboot# ps auwx | grep tftp
    root 11280 0.0 0.0 2220 276 ? Ss 21:26 0:00 /usr/sbin/in.tftpd -l -s /tftpboot
    root 11405 0.0 0.0 3004 760 pts/1 R+ 21:33 0:00 grep tftp

    The -s parameter is important, it’s how you set the root directory for the server. If you show something than other than tftpboot, check your /etc/default/tftpd-hpa file and make sure that the correct option is set.

    Menu item doesn’t show up correctly

    Go into the .mnu file and check that each “LABEL” entry has a MENU LABEL entry to go with it. Otherwise, it will fall back to the LABEL text.

    My image for {favorite tool} doesn’t work!

    If you are trying to install an image off of the UBCD and it uses dosubcd.gz, it likely will not work. dosubcd is a freeDOS implementation and once loaded will then load the files off of the CDROM. These images will not work as there’s no CDROM drive to load from (otherwise, what’s the point of using TFTPd?)

    If you’re installing something else not on the UBCD, you can try using the “generic” menu entry however, depending on how the image was created this may or may not work:

    label GenericMenu
    menu label Generic Menu Item
    kernel Kernelnamegoeshere
    append -

    Replace Kernelnamegoeshere with the kernel of the tool you wish to use. If this still doesn’t work, read the tool’s documentation and see if there is a way to get it to work by burning it onto a CD. If so, then the image will not work. The TFTP server can not distribute ISO images as bootable image files to work.

    Afterword and Credits

    I hope that you find this information useful. If you do a lot of work with linux installations, then by using this HOWTO and setting up an FTP server, you can minimize the CD-swapping hell that is most installations. You can also avoid having to find a DVD burner and a DVDROM that will read it. In my installation, I have set up Redhat 7.3, Ubuntu 8.04 and a couple of other proprietary firmwares by having the TFTP server available and at the ready.

    I would like to thank the guys that made the UBCD, as it is with their code on the Ultimate Boot CD that I was even able to find that a menu based image selection system was possible. They wrote the menu.c32 and the other files referenced as coming from the UBCD with the exception of Memtest86 which came from http://www.memtest86.com/

    All other names, trademarks and other such legal nonsense belong to whoever originally created them or whatever. All I did was write this process from information found by inspecting the configuration files downloaded from freely available sites on the Internet. Don’t sue me for copyright infringement because I am broke as hell.

    If you have any questions, feel free to post them here and as always, thank you for reading.

  • Categories: Howtos Tags: , , ,
    1. No comments yet.
    1. No trackbacks yet.