From 40f0cebe642b333c39afd6b1cc8a9b477545ed1a Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Wed, 29 Oct 2025 20:41:05 -0600 Subject: [PATCH] Configure destination of grub.cfg at overlay render time Signed-off-by: Jonathon Anderson --- CHANGELOG.md | 2 ++ Makefile | 1 - internal/pkg/overlay/overlay.go | 15 ++++++++++++++- .../host/rootfs/grub.cfg.ww | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) rename etc/grub/chainload.ww => overlays/host/rootfs/grub.cfg.ww (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f221965d..af644df3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Change the DHCP server package used on openeuler 24.03 to dnsmasq - Added configurable Serial over LAN speed via IPMI `bit-rate` tag in `50-ipmi` template - Manage SELinux context of TFTP directory. #1997 +- Dynamically write `$tftpdir/warewulf/grub.cfg` to the configured value from `warewulf.conf` +- Absolute paths specified with `{{ file }}` in an overlay now write to that absolute path. ### Fixed diff --git a/Makefile b/Makefile index 89bbf4e5..01193712 100644 --- a/Makefile +++ b/Makefile @@ -204,7 +204,6 @@ install: build docs ## Install Warewulf from source for f in etc/ipxe/*.ipxe; do install -m 0644 $$f $(DESTDIR)$(WWCONFIGDIR)/ipxe/; done for f in lib/warewulf/bmc/*.tmpl; do install -m 0644 $$f $(DESTDIR)$(DATADIR)/warewulf/bmc; done install -m 0644 etc/grub/grub.cfg.ww $(DESTDIR)$(WWCONFIGDIR)/grub/grub.cfg.ww - install -m 0644 etc/grub/chainload.ww $(DESTDIR)$(DATADIR)/warewulf/overlays/host/rootfs$(TFTPDIR)/warewulf/grub.cfg.ww install -m 0644 etc/logrotate.d/warewulfd.conf $(DESTDIR)$(LOGROTATEDIR)/warewulfd.conf (cd overlays && find * -path '*/internal' -prune -o -type f -exec install -D -m 0644 {} $(DESTDIR)$(DATADIR)/warewulf/overlays/{} \;) (cd overlays && find * -path '*/internal' -prune -o -type d -exec mkdir -pv $(DESTDIR)$(DATADIR)/warewulf/overlays/{} \;) diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 0ce80557..c0c38547 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -571,7 +571,20 @@ func BuildOverlayIndir(nodeData node.Node, allNodes []node.Node, overlayNames [] } fileBuffer.Reset() } - outputPath = path.Join(path.Dir(originalOutputPath), filenameFromTemplate[0][1]) + if path.IsAbs(filenameFromTemplate[0][1]) { + outputPath = filenameFromTemplate[0][1] + // Create parent directory for absolute paths + parentDir := path.Dir(outputPath) + sourceDirInfo, err := os.Stat(path.Dir(walkPath)) + if err != nil { + return fmt.Errorf("could not stat source directory: %w", err) + } + if err := os.MkdirAll(parentDir, sourceDirInfo.Mode()); err != nil { + return fmt.Errorf("could not create parent directory for absolute path: %w", err) + } + } else { + outputPath = path.Join(path.Dir(originalOutputPath), filenameFromTemplate[0][1]) + } writingToNamedFile = true isLink = false } else { diff --git a/etc/grub/chainload.ww b/overlays/host/rootfs/grub.cfg.ww similarity index 94% rename from etc/grub/chainload.ww rename to overlays/host/rootfs/grub.cfg.ww index 3938132e..76f9ad35 100644 --- a/etc/grub/chainload.ww +++ b/overlays/host/rootfs/grub.cfg.ww @@ -1,3 +1,4 @@ +{{ file (print .Tftp.TftpRoot "/warewulf/grub.cfg") }} # This file is autogenerated by warewulf # Host: {{ .BuildHost }} # Time: {{ .BuildTime }}