AFAIU, When tftp server is used for pxe booting, the client sends a request to the server, and the server sends back few files (initrd, kernel, config, ...). The server can decide which files to send to the client depending on the IP address of the client. The client does not know the URL of those files.

My questions is this:

I would like to test tftp server. I would like to run a command, or a (simple) script which contacts the tftp server, and receives the files, and saves these files on the disk.

In other word what I want to do is this:

  • On the server side, there is no difference: the server thinks the client wants to boot over PXE and sends the files to the client

  • On the client side: the client does not actually want to boot. It just wants to copy (save) the files to disk.

What would be the easiest way to do this?

  • I would use the tftp client to do this. An example of connecting to the server is shown here: mohammadthalif.wordpress.com/2010/03/05/… – slm Oct 7 '14 at 2:15
  • 1
    I think you have some misunderstandings about how PXE booting works. The tftp server doesn't push files to the client. The boot server offers a DHCP lease which contains the filenames it needs to go and download. You might be able to get that information if you can find a dhcp client with some sort of debug output option. – Patrick Oct 7 '14 at 3:11
  • @Patrick - the DHCP server has a next-server record, which is an IP address of the tftp server. I know the IP address of my tftp server already, so I can ignore the part involving DHCP entirely. How do I get the list of filenames from the tftp server ? – Martin Vegter Oct 7 '14 at 8:06
  • I just told you, it's in the DHCP lease. – Patrick Oct 7 '14 at 12:01
  • 1
    If you already know exactly how it works, then why are you asking for our help? Please go read the RFC before you continue this debate. – Patrick Oct 7 '14 at 16:05

The comment @Patrick made to your question was dead right: all the client machine needs to bootstrap PXE is to broadcast a DHCP request. The DHCP server (usually on the PXE boot server) will see the MAC address of the client device and will use it to

  • give the client an IP address
  • tell the client what files it should get from the PXE server

at that point, the client knows the address of the server and what to get from it. Unfortunately, there are a bunch of fiddly bits like there can be only one DHCP server which has the special configuration for the PXE client, a TFTP server needs to be running and so on.

There is a pretty good step by step guide at https://wiki.debian.org/PXEBootInstall. You didn't specify your distro, but most PXE systems will at least rhyme with that guide.

I know that your question says you don't want to know the address of the PXE server. But there is only one way (without writing your own client) that can be done, with a PXE client DHCP requester/processor. If you want to forego that part you throw away much of the capabilites needed to get you bootstrapped.

I know that you don't actually want to boot the machine which puts you in the position of implementing a lot of the PXE protocol for testing purposes. If you don't have a scratch machine available, I'm curious as to why you need to test PXE at all.

  • I have checked my DHCP server, and actually, the next-server entry contains only two things: 1) IP address of the tftp server, and 2) path to pxelinux.0 on the server. I know both. So I can skip the part with DHCP. But how will I get the list of files from the tftp server? It is the tftp server who decides which files to offer me (depending on my IP address. I don't know which files these are, or their URL. – Martin Vegter Oct 7 '14 at 8:13
  • 1
    What list of files? pxelinux.0 is all that there is. – Patrick Oct 7 '14 at 12:03
  • the list/URL of the boot image files. pxelinux.0 is just a loader (like lilo or grub). I need to retrieve the actual initrd and kernel files from the tftp server. – Martin Vegter Oct 7 '14 at 12:44
  • There is no list. Yes, pxelinux.0 is a bootloader. It is completely up to whatever code the PXE client pulls down whether it fetches anything else. If pxelinux.0 doesn't want to fetch anything, then it doesn't. You have to run it to determine if it wants to fetch anything else. – Patrick Oct 7 '14 at 13:13

How about using a real tftp client?

Those two which come to my mind:

  • but to use the tftp client, I need to know the URL of the files. But my whole point is, that the server thinks I am booting from PXE and sends me the files I need (depending on my IP address). I don't know which files it will be. – Martin Vegter Oct 7 '14 at 1:45
  • Unfortunately, that PXE booting involves other protocols as well (DHCP/BOOTP in this case). Either you know what the DHCP reply will contain (as you're administering that as well), so you know which TFTP server to ask (IP address), and which files to get, or you'll have to use some kind of command-line DHCP client as well (I used busybox udhcpc in a similar situation). – Laszlo Valko Oct 7 '14 at 1:49

I'm most familiar with how Cobbler sets up TFTP so I'm not sure if this is relevant but I'll offer this info up anyway. Cobbler sets up a bootloader using pxelinux.0 as @Patrick explains in the comments as well as @msw. But it also sets up a corresponding pxelinux.cfg/ directory along side it that contains MAC addresses for each system that will be connecting to the server.

These files contain pxelinux.cfg file info like this:

$ more 01-54-52-00-ff-ff-ff
default linux
prompt 0
timeout 1
label linux
        kernel /images/Centos56-x86_64/vmlinuz
        ipappend 2
        append initrd=/images/Centos56-x86_64/initrd.img ksdevice=bootif lang=  console=ttyS0,115200 text serial kssendmac  ks=

The actual Linux kernel that this VM will boot is contained in this TFTP accessible directory, /images/Centos56-x86_64/vmlinuz. The entire TFTP directory structure looks like this from the backside of the server:

$ ls -l /tftpboot/
total 348
drwxr-xr-x 2 root root   4096 Jun 22  2011 etc
drwxr-xr-x 2 root root   4096 Jul  9  2012 grub
drwxr-xr-x 6 root root   4096 Jul  9  2012 images
drwxr-xr-x 2 root root   4096 Jun 30  2011 images2
-rw-r--r-- 1 root root  20020 Jul  9  2012 memdisk
-rw-r--r-- 1 root root  39188 Jul  9  2012 menu.c32
drwxr-xr-x 2 root root   4096 Jun 22  2011 ppc
-rw-r--r-- 1 root root  14716 Jul  9  2012 pxelinux.0
drwxr-xr-x 2 root root   4096 Jul  9  2012 pxelinux.cfg
drwxr-xr-x 2 root root   4096 Jul  9  2012 s390x
-rw-r--r-- 1 root root 198192 Jul  9  2012 yaboot

The only thing that's initially accessible by the servers that are booting against this TFTP server, is as other's have described, the pxelinux.0 + the configuration file that corresponds to a particular server's MAC address.

Images directory

This looks like this if you're curious:

$ tree /tftpboot/images
|-- Centos56-x86_64
|   |-- initrd.img
|   `-- vmlinuz
|-- Centos56-xen-x86_64
|   |-- initrd.img
|   `-- vmlinuz
`-- Centos60-x86_64
    |-- initrd.img
    `-- vmlinuz

3 directories, 6 files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.