Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DHCP passing options/variables to iPXE
2012-08-08, 11:46
Post: #1
DHCP passing options/variables to iPXE
Morning all. I've just over to the new built in menu support courtesy of a few examples from robinsmidsrod setup. (Thanks!)

Right now however i'm working on trying to pass an alternate 'base-url' into iPXE so I can work on it from different locations. Normally the base-url is referenced to a local lan address where iPXE is run, but I also back up a copy to a webhost which I use when i'm working on tweaks from home. The base-url needs then needs to be set to the webhost address instead.

I've been looking at the dhcp options that can be specified and spotted the 'scriptlet' option which looks promising as a solution, but i can't seem to find any way to actually have iPXE recognise it..

I've updated the dhcpd.conf for my home network to have the following specified:

Code:
option space ipxe;
option ipxe.scriptlet code 81 = string;
<snip>
if exists user-class and option user-class = "iPXE" {
      filename "http://server.address.com/menu/menu.ipxe";
      option ipxe.scriptlet "http://server.address.com";
}
else { filename "/pxe/undionly.kpxe"; }

As I understand it, the scriptlet may actually have to point to a proper ipxe script, but if i break the boot sequence with CTRL-B after the initial undionly.kpxe load, and go into config the scriptlet variable still shows as as <not specified>. Likewise if i let it boot normally to the menu and then go into the config no change. I also tried using some other option variables with the same results.

Right now i'm running the undionly.kpxe from boot.ipxe.org/undionly.kpxe, and haven't got as far as re-checking if the option is enabled in that version or not, but thought i'd ask the question since I can't find alot of information on passing variables like this.

Essentially at the end of the day I don't need it to be the scriptlet variable, but basically the aim is to have the script interpret in the following manner:
isset ${dhcp-url-variable} && set base-url ${dhcp-url-variable} || set base-url http://local.address.lan

Thoughts?
Find all posts by this user
Quote this message in a reply
2012-08-08, 12:05
Post: #2
RE: DHCP passing options/variables to iPXE
(2012-08-08 11:46)jpwise Wrote:  As I understand it, the scriptlet may actually have to point to a proper ipxe script, but if i break the boot sequence with CTRL-B after the initial undionly.kpxe load, and go into config the scriptlet variable still shows as as <not specified>. Likewise if i let it boot normally to the menu and then go into the config no change. I also tried using some other option variables with the same results.

Firstly, you'll need to issue a new DHCP request from within iPXE before going into config.

Secondly, the scriptlet variable is intended to contain a sequence of iPXE commands: it's an alternative to using an embedded image. It's not relevant to your situation. Use the site-local DHCP options (128-135) instead, e.g.:

Code:
option site-local-128 code 128 = string;

option site-local-128 "http://server.address.com";

and then

Code:
iPXE> dhcp
iPXE> echo ${128:string}

Michael
Visit this user's website Find all posts by this user
Quote this message in a reply
2012-08-08, 12:30
Post: #3
RE: DHCP passing options/variables to iPXE
Excellent! - Exactly what I was after.

I was already doing the dhcp to request the updated settings, but looks like i did miss mentioning it. Either way, the site-local-128 was exactly what i was after. Smile

Have just implemented it now and it's working a charm. Thank you again for your help.
Find all posts by this user
Quote this message in a reply
2012-08-14, 14:45
Post: #4
RE: DHCP passing options/variables to iPXE
(2012-08-08 12:30)jpwise Wrote:  Excellent! - Exactly what I was after.

I was already doing the dhcp to request the updated settings, but looks like i did miss mentioning it. Either way, the site-local-128 was exactly what i was after. Smile

Have just implemented it now and it's working a charm. Thank you again for your help.

As a follow-up note, you should also be able to use custom encapsulated options. For example:

Code:
option space myopts;
option my-encap-opts code 128 = encapsulate myopts;
option myopts.scriptname code 1 = string;

option myopts.scriptname "http://bla/script.ipxe";

and then, from within iPXE:

Code:
echo ${128.1:string}
Visit this user's website Find all posts by this user
Quote this message in a reply
2012-08-15, 13:57
Post: #5
RE: DHCP passing options/variables to iPXE
(2012-08-14 14:45)mcb30 Wrote:  As a follow-up note, you should also be able to use custom encapsulated options. For example:

Code:
option space myopts;
option my-encap-opts code 128 = encapsulate myopts;
option myopts.scriptname code 1 = string;

option myopts.scriptname "http://bla/script.ipxe";

and then, from within iPXE:

Code:
echo ${128.1:string}

Smile

Think i might re-tweak things a bit now i know that. Was up to 3 variables being passed for different purposes.

You mentioned earlier dhcp options 128-135 were locally definable, do you now what the limit is using encapsulation? 1-255?

The three variables so far for anyone thats curious are base-url, nfs-ip, and dev-menu - using iseq to display an extra menu entry if dev menu is set to 'yes'. Smile it gives me somewhere to test new tools with and then just relocate in script to enable for everyone else.

Thanks again.
Jp.
Find all posts by this user
Quote this message in a reply
2012-08-15, 14:03
Post: #6
RE: DHCP passing options/variables to iPXE
(2012-08-15 13:57)jpwise Wrote:  You mentioned earlier dhcp options 128-135 were locally definable, do you now what the limit is using encapsulation? 1-255?

1-254 inclusive. 0 has a special meaning as "pad byte", and 255 has a special meaning as "end of options". (255 is redundant within an encapsulated-options field, but avoid it anyway.)

Michael
Visit this user's website Find all posts by this user
Quote this message in a reply
2012-08-15, 14:13
Post: #7
RE: DHCP passing options/variables to iPXE
Cool. Thank you again for the quick response and clarification. Smile
Find all posts by this user
Quote this message in a reply
Post Reply 




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