IPXE: Difference between revisions

From Leo's Notes
This page was last edited on 6 June 2017, at 21:58.
No edit summary
No edit summary
Line 75: Line 75:
}}
}}


=== Notes ===
=== Script Termination ===
Script execution will stop whenever a command fails.
Script execution will stop whenever a command fails.


Line 104: Line 104:


Install the {{code|syslinux-devel}} package.
Install the {{code|syslinux-devel}} package.
== Booting into SCCM ==
Suppose you have a customized SCCM .iso that you want to boot instead of having to manually boot each computer.
To get iPXE to boot this image:
# Set up boot files by extracting files from the iso and modify boot.wim and place them on a web server
# Set up iPXE to boot WinPE from the modified boot.wim file
=== 1. The files ===
Extract the following files from the iso.
* bootmgr
* bcd
* boot.sdi
* boot.wim
Obtain {{code|wimboot}} from http://git.ipxe.org/releases/wimboot/wimboot-latest.zip
Customization made to the SCCM image will be under the SMS directory in the iso. Since we are only loading the boot.wim image rather than the entire iso, these customization must be copied into the boot.wim file using ImageX (from the Windows Automated Installation Kit or WAIK). While there is a linux utility of the same name from {{code|wimlib}}, it didn't work for me as it just creates a corrupt .wim that doesn't boot properly.
Create winpeshl.ini and bootstrap.vbs.
{{highlight|lang=terminal|code=
> mkdir mnt
> imagex /mountrw boot.wim 1 mnt
> xcopy /e /f /y iso\sms mnt\sms
> copy winpeshl.ini mnt\windows\system32\
> copy bootstrap.vbs mnt\sms\bin\x64\
> magex /unmount /commit mnt
}}
Copy the files to a web server.
=== 2. Setting up iPXE ===
Create a custom iPXE ROM with the following script.
{{highlight|lang=text|code=
#!ipxe
:retry_dhcp
dhcp || goto retry_dhcp
:boot
set url http://pages.cpsc.ucalgary.ca/~leo/boot/win/
kernel ${url}/wimboot
# initrd ${url}/bootmgr bootmgr
initrd ${url}/bcd bcd
initrd ${url}/boot.sdi boot.sdi
initrd ${url}/boot.wim boot.wim
boot || boot
}}


[[Category:Linux]]
[[Category:Linux]]


{{Navbox Linux}}
{{Navbox Linux}}

Revision as of 21:58, 6 June 2017

iPXE is a PXE boot firmware which can be used to PXE boot systems that may not have support. iPXE supersedes the older and no longer actively maintained gPXE boot firmware.

Building

You can build the iPXE image from source pretty easily with the added benefit of being able to customize the image with custom embedded iPXE scripts (see scripting section below).

Example

The following script will build iPXE with an embedded script which automatically boots from a HTTP resource.

# git clone git://git.ipxe.org/ipxe.git
# cd git

# cat <<EOF > arch.ipxe
#!ipxe
dhcp
set 209:string cfg/arch.cfg
set 210:string http://linbuild.cs.ucalgary.ca/archlinux/boot/
chain ${210:string}pxelinux.0
EOF

# make bin/ipxe.lkrn EMBED=arch.ipxe

You may also make a USB image by making bin/ipxe.usb and then dd'ing the image to the USB device.


Scripting

For more information, see iPXE's documentation.

Commands

See iPXE's command reference

Common commands that will be used are:

Command Description
dhcp Obtain IP address via DHCP
boot, imgexec, chain Downloads and boots an executable image
initrd, module, imgfetch Downloads an executable image
isset Checks if a value exists (typically for settings).
echo Prints text to console
goto Go to a specific label

When booting a kernel with arguments, put it after the kernel uri or path, and not after the initrd command.

Eg:

#!ipxe

kernel vmlinuz-3.16.0-rc4 bootfile=http://boot.ipxe.org/demo/boot.php fastboot initrd=initrd.img
initrd initrd.img
boot

Flow Control

Create a script label using a colon followed by the label name. Program execution will jump to the label using the goto command.

Use the bash-like || to run a command when something fails or && when something succeeds. Eg:

true && echo Success
false || echo Failure

Script Termination

Script execution will stop whenever a command fails.

To make the script continue even if a command can error out (such as dhcp, use the || operator at the end of the command which will always make the command succeed. (ie. dhcp || is analogous to dhcp || true).

Example Scripts

#!ipxe

:retry_dhcp
dhcp && isset ${filename} | goto retry_dhcp

# Boot image provided by DHCP
echo Booting from ${filename}
chain {$filename}

Troubleshooting

If you get the following error while building:

[VERSION] bin/version.udionly.kpxe.o
[LD] bin/udionly.kpxe.tmp
--defsym:2: undefined symbol `obj_udionly' referenced in expression
make: *** [bin/udionly.kpxe.tmp] Error 1
rm bin/version.udionly.kpxe.o

Install the syslinux-devel package.

Booting into SCCM

Suppose you have a customized SCCM .iso that you want to boot instead of having to manually boot each computer.

To get iPXE to boot this image:

  1. Set up boot files by extracting files from the iso and modify boot.wim and place them on a web server
  2. Set up iPXE to boot WinPE from the modified boot.wim file

1. The files

Extract the following files from the iso.

  • bootmgr
  • bcd
  • boot.sdi
  • boot.wim

Obtain wimboot from http://git.ipxe.org/releases/wimboot/wimboot-latest.zip

Customization made to the SCCM image will be under the SMS directory in the iso. Since we are only loading the boot.wim image rather than the entire iso, these customization must be copied into the boot.wim file using ImageX (from the Windows Automated Installation Kit or WAIK). While there is a linux utility of the same name from wimlib, it didn't work for me as it just creates a corrupt .wim that doesn't boot properly.

Create winpeshl.ini and bootstrap.vbs.

> mkdir mnt
> imagex /mountrw boot.wim 1 mnt
> xcopy /e /f /y iso\sms mnt\sms
> copy winpeshl.ini mnt\windows\system32\
> copy bootstrap.vbs mnt\sms\bin\x64\
> magex /unmount /commit mnt

Copy the files to a web server.

2. Setting up iPXE

Create a custom iPXE ROM with the following script.

#!ipxe

:retry_dhcp
dhcp