Skip to content

Instantly share code, notes, and snippets.

@agrif
Last active September 6, 2022 07:32
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save agrif/8025686 to your computer and use it in GitHub Desktop.
Save agrif/8025686 to your computer and use it in GitHub Desktop.
my current ipxe setup

All of this should go into a directory that is available via HTTP and NFS. In variables.ipxe you can provide the HTTP root and NFS root paths, which are used later. Also there are some variables to set the default iscsi root (without the last part after the colon) and the initiator iqn. These are used to auto-fill the iscsi menu options.

You should tell iPXE to boot bootstrap.ipxe.

The bootstrap process reads a bunch of files and sets a bunch of variables. Of importance, it will read the file macs/XXXXXXX.ipxe based on the mac address of the card. This file should do nothing more than set the name variable, which is then used to load names/${name}.ipxe. Between these, a bunch of variables are set, most notably the iscsi variables and ${arch}, which will be one of i386 or x86_64. The name file can then do what it pleases, and when it exits, the menu in default.ipxe is shown.

A whole bunch of things that are not included here, but which you should get:

  • grub4dos/grub.exe - a chainloadable pre-packaged grub
  • syslinux/
    • extlinux - can read and boot linux off extN
    • memdisk - can read and boot drives loaded into memory, including ISOs
    • syslinux can read and boot linux off FAT and other windows fs
  • memtest86 - neat to have around
  • windows/wimboot - able to boot WinPE images
  • windows/winpe-${arch} - WinPE images, straight from copype.exe
  • gentoo/minimal-${arch} - Gentoo minimal install CD info, which can be extracted from the CD with the included script.
  • ubuntu/xubuntu-${arch} - mounted xubuntu isos, which should be NFS-shared

Almost all of these have paths defined in variables.ipxe. Fedora is not listed here, because the installer can be loaded directly off the internet. Awesome, huh?

#!ipxe
# setup a default name
set name ${mac:hexraw}
# load the MAC-specific file, should just set name, that's all
chain --autofree macs/${mac:hexraw}.ipxe ||
# set up default variables
chain --autofree variables.ipxe ||
# load the name-specific file
chain --autofree names/${name}.ipxe ||
# now load the menu
chain --replace --autofree default.ipxe
#!ipxe
########## code starts here #########
:start
menu bifrost netboot for ${initiator-iqn}
#tem --gap -- ------------------------- ------------------------------
item --gap -- ------------------------- Tools ------------------------------
item memtest Memtest86
item grub Grub4Dos
item xubuntu Xubuntu
item gentoomin Gentoo
item fedorainstall Fedora Installer
item freedos FreeDOS
item freedosinstall FreeDOS Installer
item winpe WinPE
item --gap -- ------------------------- iSCSI ------------------------------
item iscsiinit Set iSCSI initiator
item iscsihook Hook iSCSI target
item iscsiboot Boot iSCSI target
item --gap -- ------------------------- PXE ------------------------------
item --key m masq Masquerade as...
item --key c config (c)onfigure iPXE
item shell drop to iPXE shell
item reboot reboot
item --key x exit e(x)it and continue BIOS boot
choose --timeout ${menutimeout} --default ${menudefault} selected || goto cancel
set menutimeout 0
goto ${selected}
:cancel
echo menu cancelled, dropping to shell
:shell
echo type 'exit' to get back to the menu
shell
goto start
:failed
echo something failed, dropping to shell
goto shell
:reboot
reboot
:exit
exit
:config
config
goto start
:masq
echo -n Masquerade as: && read masqas || goto start
set name ${masqas}
chain --autofree variables.ipxe ||
chain --autofree names/${name}.ipxe ||
chain --autofree --replace default.ipxe || goto failed
goto start
######## iSCSI ########
:iscsiinit
echo -n Initiator IQN: && read initiator-iqn || goto start
goto start
:iscsihook
set hookdrive ${iscsiroot}:${name}.
echo -n Target to hook: && read hookdrive || goto start
sanhook --drive 0x80 ${hookdrive} || goto failed
goto start
:iscsiboot
set bootdrive ${iscsiroot}:${name}.
echo -n Target to boot: && read bootdrive || goto start
sanboot --drive 0x80 ${bootdrive} || goto failed
goto start
######## Tools ########
:memtest
echo booting memtest86
chain memtest86 || goto failed
goto start
:grub
# from http://ipxe.org/appnote/work_around_bios_halting_on_ipxe_exit
echo booting grub4dos
chain ${grub4dos} --config-file="commandline" || goto failed
goto start
:xubuntu
# following guide from http://www.howtogeek.com/61263/
echo booting xubuntu
kernel ${xubuntupath}/casper/vmlinuz root=/dev/nfs boot=casper netboot=nfs nfsroot=${nfsroot}/${xubuntupath} initrd=${xubuntupath}/casper/initrd.lz --
initrd ${xubuntupath}/casper/initrd.lz
boot || goto failed
goto start
:gentoomin
# created using the method outlined at: http://blog.dastrup.com/?p=12
echo booting gentoo minimal
kernel ${gentoopath}/gentoo initrd=gentoo.igz root=/dev/ram0 init=/linuxrc loop=/image.squashfs cdroot real_root=/ dokeymap vga=791 nodhcp
initrd ${gentoopath}/gentoo.igz
boot || goto failed
goto start
:fedorainstall
# from http://ipxe.org/howto/fedora
echo booting fedora installer
kernel ${fedorarepo}/images/pxeboot/vmlinuz initrd=initrd.img repo=${fedorarepo}
initrd ${fedorarepo}/images/pxeboot/initrd.img
boot || goto failed
goto start
:freedosinstall
echo booting freedos installer
#sanboot --drive 0x81 ${root}/${freedospath}/fd11src.iso || goto failed
initrd ${freedospath}/fd11src.iso
chain ${memdisk} iso || goto failed
goto start
:freedos
echo booting freedos
#sanboot --drive 0x81 ${root}/${freedospath}/fdfullws.iso || goto failed
initrd ${freedospath}/fdfullws.iso
chain ${memdisk} iso || goto failed
goto start
:winpe
# slighly modified from http://ipxe.org/wimboot
# images created using copype.cmd, and copied directly
# http://technet.microsoft.com/en-us/library/cc709665(v=ws.10).aspx
# modified to have my realtek nic drivers
echo booting winpe
initrd ${winpepath}/ISO/bootmgr bootmgr
initrd ${winpepath}/ISO/boot/bcd BCD
initrd ${winpepath}/ISO/boot/boot.sdi boot.sdi
initrd ${winpepath}/winpe.wim boot.wim
chain ${wimboot} || goto failed
goto start
#!/bin/bash
# automates the procedure outlined at: http://blog.dastrup.com/?p=12
MOUNT=$1
OUT=$2
if [ x$MOUNT == "x" -o x$OUT == "x" ]; then
echo usage: $0 [MOUNT] [OUT]
exit 1
fi
echo converting gentoo iso mounted at $MOUNT into PXE-bootable stuff at $OUT
mkdir -p $OUT
cp $MOUNT/isolinux/gentoo $OUT/
cp $MOUNT/isolinux/gentoo.igz $OUT/
cp $MOUNT/image.squashfs $OUT/
mkdir -p $OUT/work
pushd $OUT/work > /dev/null 2>&1
echo decompressing initrd
xz -d -c ../gentoo.igz | cpio -idv > /dev/null 2>&1
mkdir -p mnt/cdrom
mv ../image.squashfs mnt/cdrom/
patch -p0 --ignore-whitespace <<'EOF'
--- init 2013-12-11 20:19:32.467354073 -0500
+++ init 2013-12-11 20:20:37.395542359 -0500
@@ -449,11 +449,6 @@
[ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
fi
- if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
- then
- bootstrapCD
- fi
-
if [ "${REAL_ROOT}" = '' ]
then
echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
@@ -590,7 +585,7 @@
else
bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
REAL_ROOT=""
- got_good_root=0
+ got_good_root=1
fi
done
@@ -669,8 +664,6 @@
[ -z "${LOOP}" ] && find_loop
[ -z "${LOOPTYPE}" ] && find_looptype
- cache_cd_contents
-
# If encrypted, find key and mount, otherwise mount as usual
if [ -n "${CRYPT_ROOT}" ]
then
@@ -711,7 +704,7 @@
# Upgrade to cached version if possible
[ "${DO_cache}" -a -f "${_CACHED_SQUASHFS_PATH}" ] \
&& _squashfs_path=${_CACHED_SQUASHFS_PATH}
- mount -t squashfs -o loop,ro "${_squashfs_path}" "${NEW_ROOT}/mnt/livecd" || {
+ mount -t squashfs -o loop,ro "/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd" || {
bad_msg "Squashfs filesystem could not be mounted, dropping into shell."
if [ -e /proc/filesystems ]; then
fgrep -q squashfs /proc/filesystems || \
EOF
echo recompressing initrd
#find . -print | cpio -o -H newc 2>/dev/null | xz -9 -c - > ../gentoo.igz
find . -print | cpio -o -H newc 2>/dev/null > ../gentoo.igz
popd > /dev/null 2>&1
rm -r $OUT/work
echo done.
#!ipxe
######### autodetect variables #########
cpuid --ext 29 && set arch x86_64 || set arch i386
######### file root paths ##########
set root http://192.168.1.1/tftpd
set nfsroot 192.168.1.1:/var/tftpd
######### iscsi #########
set iscsiroot iscsi:192.168.1.1::::iqn.2013-04.net.rakeri.bifrost
set initiator-iqn iqn.2013-04.net.rakeri.asgard.${name}:initiator
######## syslinux helpers ########
set memdisk syslinux/memdisk
######## wimboot ########
set wimboot windows/wimboot
######## grub4dos ########
set grub4dos grub4dos/grub.exe
######### various distro paths #########
set fedorarepo http://download.fedoraproject.org/pub/fedora/linux/releases/18/F$
set gentoopath gentoo/minimal-${arch}
set xubuntupath ubuntu/xubuntu-${arch}
set freedospath freedos
set win7path windows/seven-${arch}
set winpepath windows/winpe-${arch}
######### menu settings #########
set menutimeout 0
set menudefault 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment