Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with iPXE and PHP
2012-11-30, 01:25
Post: #1
Issue with iPXE and PHP
Hi! I was wondering if someone could give me a sanity check please because something is going wrong with my attempt to implement a PHP bootserver...

Essentially the problem is that iPXE gets the first script but hangs after getting the second (with no error).

I have DHCP, TFTP and Apache set up correctly. I am able to build iPXE with the embedded demo script from the documentation. That works fine (loads the kernel from http://demo.ipxe.org etc).

So what I am trying to do is to have an embedded ipxe script that points to my local webserver: http://bs1/boot.php?mac=zzzzzzzzzzzz etc. This is the script I embedded:


#!ipxe

dhcp
chain http://bs1/boot.php?mac=${net0/mac}


(FYI, I tried it with the FQDN and iPXE kept giving me dns error, so I just put http://bs1 now...).


The reason I am passing the mac address is that I intend to serve different images according to the machines mac address (guess thats obvious!).

The PHP script I have on my webserver is:


<?PHP
header ("Content-type: text/plain");
$ma = $_GET['mac'];

echo "#!ipxe\n";
echo "dhcp\n";
echo "chain http://boot.ipxe.org/demo/boot.php";

?>


As you can see, I have pointed this script to your demo site as a test and last-resort because I tried pointing it to local kernel and initrd and it hung then too. So iPXE wont access mine or your files, but simply hangs and shows no error. Help!!
Am I missing something obvious?

I wondered if it was due to formatting of the php or something...
Find all posts by this user
Quote this message in a reply
2012-12-02, 22:45
Post: #2
RE: Issue with iPXE and PHP
First; you do not need a "dhcp" command in the script that is downloaded from the web-server. You've already performed the DHCP in the embedded script. Doing it again just wastes time and might potentially cause problems (though it normally shouldn't).

Second; the fact that you say that you're having problems resolving the DNS name makes me wonder if your network services are properly configured. If you boot a regular Live-CD, are you able to ping the FQDN of bs1 without any more setup? If not, then I think you might have a DHCP and/or DNS failure in your network. When/if you have fixed that, you should verify that you can point a normal web browser at your web server and it will display the ipxe script (http://bs1/boot.php) as normal text in the browser. If you don't get that you might have some error either in your web server config or your PHP setup.

Third; you don't really need any server-side programming to do this. Take a look at https://gist.github.com/2234639 to see how I implement something similar to PXELINUX's loader feature using just iPXE scripting in bootstrap.ipxe.
Visit this user's website Find all posts by this user
Quote this message in a reply
2012-12-05, 01:19
Post: #3
RE: Issue with iPXE and PHP
When exactly does iPXE hang? Right it fetches your php page and tries to execute it?

If that's the case please enter the iPXE command line, fetch the image manually and execute 'imgstat':

dhcp
kernel http://bs1/boot.php?mac=${net0/mac}
imgstat

It should say something like "Script" next to that file. It probably says "PXE" or "NBP" or something similar instead. If that's the case you may have some issues with iPXE incorrectly detecting the shebang line("#!ipxe"). Is there maybe some issue with the character encoding? Is the very first thing that script outputs really "#!ipxe\n" with absolutely nothing before it? You should also check with a browser that the content type really is text/plain.
Find all posts by this user
Quote this message in a reply
2012-12-05, 11:23 (This post was last modified: 2012-12-05 11:25 by Torgeir.)
Post: #4
RE: Issue with iPXE and PHP
Only thing I can think of:

I use this on top of every php page just like this:

PHP Code:
<?php 
# my red hat server did not like just <? 
# i had to have <?php
# <? has always work for me before

# these two always on top
header "Content-type: text/plain" );
echo 
"#!ipxe \n";

# then i do stuff like
$mac $_REQUEST['mac'];

if (
$mac "010101010") {
     
$client 1;
}

# chain statement has to end with \n too...
echo "chain http://SERVER_NAME/boot.php?client=$client \n";
?>

I use FQDN, even HTTPS and an embedded script like this:

Code:
#!ipxe
isset ${net0/mac} && dhcp net0 || goto net1
set dhcp_mac ${net0/mac}
chain https://SERVER-NAME.${domain}/first.stage.php?MAC=${dhcp_mac}&DHCPSERVER=${net0.dhcp/dhcp-server:ipv4}&NIC=net0&DOMAIN=${domain}&PRODUCT=${smbios/product:string}

:net1
isset ${net1/mac} && dhcp net1 || goto net2
set dhcp_mac ${net1/mac}
chain https://SERVER-NAME.${domain}/first.stage.php?MAC=${dhcp_mac}&DHCPSERVER=${net0.dhcp/dhcp-server:ipv4}&NIC=net1&DOMAIN=${domain}&PRODUCT=${smbios/product:string}

:net2
isset ${net2/mac} && dhcp net2 || goto nonet
set dhcp_mac ${net2/mac}
chain https://SERVER-NAME.${domain}/first.stage.php?MAC=${dhcp_mac}&DHCPSERVER=${net0.dhcp/dhcp-server:ipv4}&NIC=net2&DOMAIN=${domain}&PRODUCT=${smbios/product:string}

:nonet
echo
echo Error! Could not configure network.
echo
prompt Press any key to reboot . . .
reboot

Torgeir
Can you run this simple php script?
http://forum.ipxe.org/showthread.php?tid=6333

Its intended to go in an loop Smile

Torgeir
Find all posts by this user
Quote this message in a reply
2017-12-15, 01:48
Post: #5
RE: Issue with iPXE and PHP
(2012-12-05 01:19)thomil Wrote:  When exactly does iPXE hang? Right it fetches your php page and tries to execute it?

If that's the case please enter the iPXE command line, fetch the image manually and execute 'imgstat':

dhcp
kernel http://bs1/boot.php?mac=${net0/mac}
imgstat

It should say something like "Script" next to that file. It probably says "PXE" or "NBP" or something similar instead. If that's the case you may have some issues with iPXE incorrectly detecting the shebang line("#!ipxe"). Is there maybe some issue with the character encoding? Is the very first thing that script outputs really "#!ipxe\n" with absolutely nothing before it? You should also check with a browser that the content type really is text/plain.
Hello thomil,

I am having same issue where ipxe is not detecting php scripts

My test script is like this
test.php
<?php

header ("Content-type: text/plain ");
echo "#!ipxe\n";
echo ":exit\n";
echo "echo Booting from local disks ...\n";
echo "exit 0\n";

?>

when i run imgstat on ipxe it Shows test.php as [PXE-NBP]

I have another script test2.php , and this script is shown as [script] when running imgstat

#!ipxe
echo ===== My iPXE Script =====
echo MAC address is ${net0/mac}"

Any help will be greatly appreciated

Thanks
Find all posts by this user
Quote this message in a reply
2017-12-17, 11:27
Post: #6
RE: Issue with iPXE and PHP
(2017-12-15 01:48)johnfortech Wrote:  I am having same issue where ipxe is not detecting php scripts

My test script is like this
test.php
<?php

header ("Content-type: text/plain ");
echo "#!ipxe\n";
echo ":exit\n";
echo "echo Booting from local disks ...\n";
echo "exit 0\n";

?>

when i run imgstat on ipxe it Shows test.php as [PXE-NBP]

Try to download that with wget or curl and check the actual resulting file.
all iPXE scripts must have the #!ipxe magic as the first bytes of data.

One thing that i see above is the space at the the end of Content-type: text/plain .

Also check your servers error_log if there is any warnings.
And finally use tcpdump or wireshark to see what is actually sent down the wire if the wget/curl above don't explain the reason.

Use GitHub Discussions
VRAM bin
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)