Update ipxe and grub configuration for clarity #1156

Also:

- Defined a menu for iPXE
- Support a IPXEMenuEntry tag to select the boot method
- Merge iPXE dracut support into default.ipxe (use IPXEMenuEntry=dracut)

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-02-12 11:43:43 -07:00
parent 34e8aa7402
commit fb9f269fc5
8 changed files with 358 additions and 244 deletions

View File

@@ -1,77 +1,170 @@
{{ if .ImageName }}
echo "================================================================================"
echo "Warewulf v4 now http booting grub: {{.Fqdn}} ({{.Hwaddr}})"
echo "================================================================================"
echo
echo "Warewulf Controller: {{.Ipaddr}}"
echo "Warewulf v4 (GRUB)"
echo
sleep 1
echo "Warewulf Server:"
echo "* Ipaddr: {{.Ipaddr}}"
echo "* Port: {{.Port}}"
echo
echo "This node:"
echo "* Fqdn: {{.Fqdn}}"
echo "* Hwaddr: {{.Hwaddr}}"
echo "* ImageName: {{.ImageName}}"
{{- if .KernelVersion }}
echo "* KernelVersion: {{.KernelVersion}}"
{{- else }}
echo "* KernelVersion: (image default)"
{{- end }}
echo "* KernelArgs: {{.KernelArgs}}"
{{- if not .ImageName }}
echo "!!"
echo "!! No image defined for {{.Fqdn}}."
echo "!! Rebooting in 30s...
echo "!!"
sleep 30
reboot
{{- end }}
echo "Reading asset key..."
smbios --type 3 --get-string 8 --set assetkey
uri="(http,{{.Ipaddr}}:{{.Port}})/provision/${net_default_mac}?assetkey=${assetkey}"
kernel="${uri}&stage=kernel"
image="${uri}&stage=image&compress=gz"
system="${uri}&stage=system&compress=gz"
runtime="${uri}&stage=runtime&compress=gz"
set default={{ or .Tags.GrubMenuEntry "ww4" }}
set timeout=5
set default={{ or .Tags.GrubMenuEntry "single-stage" }}
set timeout=2
menuentry "Network boot node: {{.Id}}" --id ww4 {
{{if .KernelVersion }}
echo "Kernel: {{.KernelVersion}}"
{{else}}
echo "Kernel: {{.ImageName}} (image default)"
{{end}}
echo "KernelArgs: {{.KernelArgs}}"
menuentry "Single-stage boot" --id single-stage {
echo "Warewulf Server:"
echo "* Ipaddr: {{.Ipaddr}}"
echo "* Port: {{.Port}}"
echo
echo "This node:"
echo "* Fqdn: {{.Fqdn}}"
echo "* Hwaddr: {{.Hwaddr}}"
echo "* ImageName: {{.ImageName}}"
{{- if .KernelVersion }}
echo "* KernelVersion: {{.KernelVersion}}"
{{- else }}
echo "* KernelVersion: (image default)"
{{- end }}
echo "* KernelArgs: {{.KernelArgs}}"
echo
echo "Downloading kernel image..."
linux $kernel wwid=${net_default_mac} {{.KernelArgs}}
if [ x$? = x0 ] ; then
echo "Loading Image: {{.ImageName}}"
initrd $image $system $runtime
boot
else
echo "MESSAGE: This node seems to be unconfigured. Please have your system administrator add a"
echo " configuration for this node with HW address: ${net_default_mac}"
echo ""
echo "Rebooting in 1 minute..."
sleep 60
reboot
if [ $? != 0 ]
then
echo "!!"
echo "!! Unable to load kernel."
echo "!! Rebooting in 15s..."
echo "!!"
fi
echo "Downloading images..."
image="${uri}&stage=image&compress=gz"
system="${uri}&stage=system&compress=gz"
runtime="${uri}&stage=runtime&compress=gz"
initrd $image $system $runtime
if [ $? != 0 ]
then
echo "!!"
echo "!! Unable to load images."
echo "!! Rebooting in 15s..."
echo "!!"
fi
echo "Booting..."
boot
}
menuentry "Network boot node with dracut: {{.Id}}" --id dracut {
menuentry "Single-stage boot (no compression)" --id single-stage-nocompress {
echo "Warewulf Server:"
echo "* Ipaddr: {{.Ipaddr}}"
echo "* Port: {{.Port}}"
echo
echo "This node:"
echo "* Fqdn: {{.Fqdn}}"
echo "* Hwaddr: {{.Hwaddr}}"
echo "* ImageName: {{.ImageName}}"
{{- if .KernelVersion }}
echo "* KernelVersion: {{.KernelVersion}}"
{{- else }}
echo "* KernelVersion: (image default)"
{{- end }}
echo "* KernelArgs: {{.KernelArgs}}"
echo
echo "Downloading kernel image..."
linux $kernel wwid=${net_default_mac} {{.KernelArgs}}
if [ $? != 0 ]
then
echo "!!"
echo "!! Unable to load kernel."
echo "!! Rebooting in 15s..."
echo "!!"
fi
echo "Downloading images..."
image="${uri}&stage=image"
system="${uri}&stage=system"
runtime="${uri}&stage=runtime"
initrd $image $system $runtime
if [ $? != 0 ]
then
echo "!!"
echo "!! Unable to load images."
echo "!! Rebooting in 15s..."
echo "!!"
fi
echo "Booting..."
boot
}
menuentry "Two stage boot with dracut" --id dracut {
echo "Warewulf Server:"
echo "* Ipaddr: {{.Ipaddr}}"
echo "* Port: {{.Port}}"
echo
echo "This node:"
echo "* Fqdn: {{.Fqdn}}"
echo "* Hwaddr: {{.Hwaddr}}"
echo "* ImageName: {{.ImageName}}"
{{- if .KernelVersion }}
echo "* KernelVersion: {{.KernelVersion}}"
{{- else }}
echo "* KernelVersion: (image default)"
{{- end }}
echo "* KernelArgs: {{.KernelArgs}}"
initramfs="${uri}&stage=initramfs"
wwinit_uri="http://{{.Ipaddr}}:{{.Port}}/provision/${net_default_mac}"
{{if .KernelVersion }}
echo "Kernel: {{.KernelVersion}}"
{{else}}
echo "Kernel: {{.ImageName}} (image default)"
{{end}}
echo "KernelArgs: {{.KernelArgs}}"
net_args="rd.neednet=1 {{range $devname, $netdev := .NetDevs}}{{if and $netdev.Hwaddr $netdev.Device}} ifname={{$netdev.Device}}:{{$netdev.Hwaddr}} {{end}}{{end}}"
wwinit_args="root=wwinit wwinit.uri=${wwinit_uri} init=/init"
echo
echo "Downloading kernel image..."
linux $kernel wwid=${net_default_mac} {{.KernelArgs}} $net_args $wwinit_args
if [ x$? = x0 ] ; then
echo "Loading Image: {{.ImageName}}"
initrd $initramfs
boot
else
echo "MESSAGE: This node seems to be unconfigured. Please have your system administrator add a"
echo " configuration for this node with HW address: ${net_default_mac}"
echo ""
echo "Rebooting in 1 minute..."
sleep 60
reboot
if [ $? != 0 ]
then
echo "!!"
echo "!! Unable to load kernel."
echo "!! Rebooting in 15s..."
echo "!!"
fi
}
menuentry "Chainload specific configfile" {
conf="(http,{{.Ipaddr}}:{{.Port}})/efiboot/grub.cfg?assetkey=${assetkey}"
configfile $conf
echo "Downloading initramfs..."
initrd $initramfs
if [ $? != 0 ]
then
echo "!!"
echo "!! Unable to load initramfs."
echo "!! Rebooting in 15s..."
echo "!!"
fi
echo "Booting..."
boot
}
menuentry "UEFI Firmware Settings" --id "uefi-firmware" {
@@ -87,12 +180,3 @@ menuentry "System shutdown" {
echo "System shutting down..."
halt
}
{{ else }}
echo "================================================================================"
echo " Warewulf v4:"
echo " No node image defined for this node ({{.Fqdn}})."
echo " Rebooting in 30s."
echo "================================================================================"
sleep 30
reboot
{{ end }}

View File

@@ -1,94 +1,129 @@
#!ipxe
{{ if .ImageName }}
echo
echo ================================================================================
echo Warewulf v4 now booting: {{.Fqdn}} ({{.Hwaddr}})
echo
echo Image: {{.ImageName}}
{{if .KernelVersion }}
echo Kernel: {{.KernelVersion}}
{{else}}
echo Kernel: {{.ImageName}} (image default)
{{end}}
echo KernelArgs: {{.KernelArgs}}
echo
echo Warewulf v4 (iPXE)
echo
set next start
goto metadata
set uri_base http://{{.Ipaddr}}:{{.Port}}/provision/{{.Hwaddr}}?assetkey=${asset}&uuid=${uuid}
echo Warewulf Controller: {{.Ipaddr}}
echo Downloading Kernel Image:
kernel --name kernel ${uri_base}&stage=kernel || goto reboot
# imgextract causes RAM space problems on non-EFI systems (because of the 3GB barrier
# in 32-Bit mode).
# -> Use the old initrd method with a compressed image to save as much RAM as possible
# in this early boot stage.
# See <https://github.com/warewulf/warewulf/issues/222> for more details.
iseq ${platform} efi && goto efi || goto noefi
:efi
# try extracting compressed images first
# NOTE: system overlay tends to be the smallest, so failure here is the cheapest
echo Downloading Image:
imgextract --name image ${uri_base}&stage=image&compress=gz || goto nocompress
echo Downloading System Overlay:
imgextract --name system ${uri_base}&stage=system&compress=gz || goto reboot
echo Downloading Runtime Overlay:
imgextract --name runtime ${uri_base}&stage=runtime&compress=gz && set runtime_initrd initrd=runtime || echo Failed downloading runtime overlay.
goto imoktogo
:nocompress
echo
echo Image extract not supported in this iPXE, using standard initrd mode
echo Downloading Image:
initrd --name image ${uri_base}&stage=image || goto reboot
echo Downloading System Overlay:
initrd --name system ${uri_base}&stage=system || goto reboot
echo Downloading Runtime Overlay:
initrd --name runtime ${uri_base}&stage=runtime && set runtime_initrd initrd=runtime || echo Failed downloading runtime overlay.
goto imoktogo
:noefi
echo
echo Use legacy initrd mode with compressed images
echo Downloading Image:
initrd --name image ${uri_base}&stage=image&compress=gz || goto reboot
echo Downloading System Overlay:
initrd --name system ${uri_base}&stage=system&compress=gz || goto reboot
echo Downloading Runtime Overlay:
initrd --name runtime ${uri_base}&stage=runtime&compress=gz && set runtime_initrd initrd=runtime || echo Failed downloading runtime overlay.
:imoktogo
echo boot kernel initrd=image initrd=system ${runtime_initrd} wwid={{.Hwaddr}} {{.KernelArgs}}
boot kernel initrd=image initrd=system ${runtime_initrd} wwid={{.Hwaddr}} {{.KernelArgs}} || goto reboot
:reboot
echo
echo There was an error, rebooting in 15s...
echo
sleep 15
reboot
{{ else }}
echo ================================================================================
echo Warewulf v4:
echo No image defined for this node ({{.Fqdn}}).
echo Rebooting in 30s.
echo ================================================================================
:start
{{- if not .ImageName }}
echo !!
echo !! No image defined for {{.Fqdn}}.
echo !! Rebooting in 30s...
echo !!
sleep 30
reboot
{{ end }}
{{- end }}
set baseuri http://{{.Ipaddr}}:{{.Port}}/provision/{{.Hwaddr}}
set uri ${baseuri}?assetkey=${asset}&uuid=${uuid}
echo Downloading kernel image...
kernel --name kernel ${uri}&stage=kernel || goto reboot
{{- if .Tags.IPXEMenuEntry }}
set method {{ .Tags.IPXEMenuEntry }}
{{- else }}
# https://github.com/warewulf/warewulf/issues/222
iseq ${platform} efi && set method imgextract || set method initrd
{{- end }}
:menu
menu Warewulf v4 image provisioning method
item imgextract Single-stage with imgextract
item initrd Single-stage with initrd
item initrd_nocompress Single stage with initrd (no compression)
item dracut Two stage with dracut
item shell iPXE shell
choose --default ${method} --timeout 2000 method && goto ${method} || goto menu
:imgextract
set next imgextract_continue
goto metadata
:imgextract_continue
echo
echo Downloading compressed image with imgextract...
imgextract --name image ${uri}&stage=image&compress=gz || goto error_use_initrd
echo Downloading compressed system overlay image with imgextract...
imgextract --name system ${uri}&stage=system&compress=gz || goto error_reboot
echo Downloading compressed runtime overlay image with imgextract...
imgextract --name runtime ${uri}&stage=runtime&compress=gz && set runtime_initrd initrd=runtime || echo Unable to download runtime overlay. (ignored)
goto boot_single_stage
:error_use_initrd
echo Encountered an error. Now using initrd.
goto initrd_continue
:initrd
set next initrd_continue
goto metadata
:initrd_continue
echo
echo Downloading compressed image with initrd...
initrd --name image ${uri}&stage=image&compress=gz || goto error_reboot
echo Downloading compressed system overlay with initrd...
initrd --name system ${uri}&stage=system&compress=gz || goto error_reboot
echo Downloading compressed runtime overlay with initrd...
initrd --name runtime ${uri}&stage=runtime&compress=gz && set runtime_initrd initrd=runtime || echo Unable to download runtime overlay. (ignored)
goto boot_single_stage
:initrd_nocompress
set next initrd_nocompress_continue
goto metadata
:initrd_nocompress_continue
echo
echo Downloading uncompressed image with initrd...
initrd --name image ${uri}&stage=image || goto error_reboot
echo Downloading uncompressed system overlay with initrd...
initrd --name system ${uri}&stage=system || goto error_reboot
echo Downloading uncompressed runtime overlay with initrd...
initrd --name runtime ${uri}&stage=runtime && set runtime_initrd initrd=runtime || echo Unable to download runtime overlay. (ignored)
goto boot_single_stage
:dracut
set next dracut_continue
goto metadata
:dracut_continue
echo
echo Downloading dracut initramfs...
initrd --name initramfs ${uri}&stage=initramfs || goto error_reboot
set dracut_net rd.neednet=1 {{range $devname, $netdev := .NetDevs}}{{if and $netdev.Hwaddr $netdev.Device}} ifname={{$netdev.Device}}:{{$netdev.Hwaddr}} ip={{$netdev.Device}}:dhcp {{end}}{{end}}
set dracut_wwinit root=wwinit wwinit.uri=${baseuri} init=/init
goto boot_two_stage_dracut
:boot_single_stage
echo Booting (single stage)...
boot kernel initrd=image initrd=system ${runtime_initrd} wwid={{.Hwaddr}} {{.KernelArgs}} || goto error_reboot
:boot_two_stage_dracut
echo Booting dracut (first stage)...
boot kernel initrd=initramfs ${dracut_net} ${dracut_wwinit} wwid={{.Hwaddr}} {{.KernelArgs}} || error_reboot
:error_reboot
echo !!
echo !! Encountered an error.
echo !! rebooting in 15s...
echo !!
sleep 15
reboot
:shell
shell
goto menu
:metadata
echo Warewulf Server:
echo * Ipaddr: {{.Ipaddr}}
echo * Port: {{.Port}}
echo
echo This node:
echo * Fqdn: {{.Fqdn}}
echo * Hwaddr: {{.Hwaddr}}
echo * ImageName: {{.ImageName}}
{{- if .KernelVersion }}
echo * KernelVersion: {{.KernelVersion}}
{{- else }}
echo * KernelVersion: (image default)
{{- end }}
echo * KernelArgs: {{.KernelArgs}}
goto ${next}

View File

@@ -1,47 +0,0 @@
#!ipxe
{{ if .ImageName }}
echo
echo ================================================================================
echo Warewulf v4 now booting via dracut: {{.Fqdn}} ({{.Hwaddr}})
echo
echo Image: {{.ImageName}}
{{if .KernelVersion }}
echo Kernel: {{.KernelVersion}}
{{else}}
echo Kernel: {{.ImageName}} (image default)
{{end}}
echo KernelArgs: {{.KernelArgs}}
echo
set baseuri http://{{.Ipaddr}}:{{.Port}}/provision/{{.Hwaddr}}
set uri ${baseuri}?assetkey=${asset}&uuid=${uuid}
echo Warewulf Controller: {{.Ipaddr}}
echo Downloading Kernel Image:
kernel --name kernel ${uri}&stage=kernel || goto reboot
echo Downloading initramfs
initrd --name initramfs ${uri}&stage=initramfs || goto reboot
set dracut_net rd.neednet=1 {{range $devname, $netdev := .NetDevs}}{{if and $netdev.Hwaddr $netdev.Device}} ifname={{$netdev.Device}}:{{$netdev.Hwaddr}} ip={{$netdev.Device}}:dhcp {{end}}{{end}}
set dracut_wwinit root=wwinit wwinit.uri=${baseuri} init=/init
echo Booting initramfs
boot kernel initrd=initramfs ${dracut_net} ${dracut_wwinit} wwid={{.Hwaddr}} {{.KernelArgs}}
:reboot
echo
echo There was an error, rebooting in 15s...
echo
sleep 15
reboot
{{ else }}
echo ================================================================================
echo Warewulf v4:
echo No image defined for this node ({{.Fqdn}}).
echo Rebooting in 30s.
echo ================================================================================
sleep 30
reboot
{{ end }}