You can create a script to automate a sequence of iPXE commands. Any command that can be typed at the iPXE command line can also be used in a script. You can find a full list of commands in the iPXE command reference.

An iPXE script is a plain text file starting with the magic line #!ipxe and containing a sequence of iPXE commands. For example, here is a simple script that acquires an IP address via DHCP and then boots the iPXE demonstration image:

#!ipxe
dhcp
chain http://boot.ipxe.org/demo/boot.php

Here is another simple script that creates a VLAN and then boots from it:

#!ipxe
vcreate --tag 24 net0
autoboot net0-24

Here is a slightly more sophisticated script that persistently retries DHCP until it succeeds in obtaining a boot filename:

You can create an iPXE script using any text editor, such as emacs, or vi, or even Windows Notepad. An iPXE script does not need to have any particular file extension (such as .txt or .ipxe); iPXE will recognise it as a script provided that it starts with the magic line #!ipxe.1)

iPXE will terminate a script immediately if any line of the script fails. For example, if you have the script:

#!ipxe
dhcp
route

then the script will terminate immediately if the dhcp command fails, without proceeding to the next line. You can override this behaviour using the || operator:

#!ipxe
dhcp ||
route

In this example, the empty command after the || operator is treated as “do nothing, successfully” (similar to /bin/true on a Unix-like operating system). Even if the dhcp command fails, the overall status of this line of the script will therefore always be “successful”.

You can embed a script within iPXE to override its default behaviour. For example, you may wish to build a version of iPXE containing an embedded script that uses DHCP to obtain an IP address but then boots from a predefined SAN target.

An iPXE script does not have to be a static text file. For example, you could direct iPXE to boot from the URL

http://192.168.0.1/boot.php?mac=${net0/mac}&asset=${asset:uristring}

which would expand to a URL such as

http://192.168.0.1/boot.php?mac=52:54:00:12:34:56&asset=BKQ42M1

The boot.php program running on the web server could dynamically generate a script based on the information provided in the URL. For example, boot.php could look up the asset tag in a MySQL database to determine the correct iSCSI target to boot from, and then dynamically generate a script such as

1)
For the sake of backwards compatibility, iPXE will also recognise legacy gPXE scripts starting with the magic line #!gpxe. However, gPXE is not capable of running iPXE scripts, since the iPXE script language is substantially more advanced than the gPXE script language.

scripting.txt · Last modified: 2014/03/14 00:22 by mcb30

All uses of this content must include an attribution to the iPXE
project and the URL http://ipxe.org