From e77827df6cf6a1b4e3d16416f915f169123321f2 Mon Sep 17 00:00:00 2001 From: Adphi Date: Wed, 29 Apr 2026 16:09:31 +0200 Subject: [PATCH 1/2] fix: fix centos / rhel family 8+ grub-bios boot Signed-off-by: Adphi --- grub_common.go | 4 +++- templates/centos.Dockerfile | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/grub_common.go b/grub_common.go index 6e41095..cb25d3f 100644 --- a/grub_common.go +++ b/grub_common.go @@ -32,6 +32,8 @@ GRUB_TIMEOUT=0 GRUB_CMDLINE_LINUX_DEFAULT="%s" GRUB_CMDLINE_LINUX="" GRUB_TERMINAL=console +GRUB_DISABLE_OS_PROBER=true +GRUB_ENABLE_BLSCFG=false ` type grubCommon struct { @@ -44,7 +46,7 @@ type grubCommon struct { func newGrubCommon(c Config, r OSRelease) *grubCommon { name := "grub" - if r.ID == "centos" { + if r.ID == ReleaseCentOS || r.ID == ReleaseAlmaLinux || r.ID == ReleaseRocky { name = "grub2" } return &grubCommon{ diff --git a/templates/centos.Dockerfile b/templates/centos.Dockerfile index 561c780..e584ef8 100644 --- a/templates/centos.Dockerfile +++ b/templates/centos.Dockerfile @@ -36,10 +36,27 @@ RUN dracut --no-hostonly --regenerate-all --force {{ if .Password }}RUN echo "root:{{ .Password }}" | chpasswd {{ end }} -{{- if not .Grub }} +{{- if .Grub }} +RUN set -e; \ + for linux in /usr/lib/modules/*/vmlinuz; do \ + [ -e "$linux" ] || continue; \ + kver="$(basename "$(dirname "$linux")")"; \ + cp "/usr/lib/modules/${kver}/vmlinuz" "/boot/vmlinuz-${kver}"; \ + done +RUN set -e; \ + for linux in /boot/*/*/linux; do \ + [ -e "$linux" ] || continue; \ + dir="$(dirname "$linux")"; \ + kver="$(basename "$dir")"; \ + initrd="${dir}/initrd"; \ + [ -e "$initrd" ] || continue; \ + ln -sf "${linux#/boot/}" "/boot/vmlinuz-${kver}"; \ + ln -sf "${initrd#/boot/}" "/boot/initramfs-${kver}.img"; \ + done +{{- else }} RUN cd /boot && \ - mv $(find / -name 'vmlinuz*') /boot/vmlinuz && \ - mv $(find . -name 'initramfs-*.img' -o -name initrd) /boot/initrd.img + mv $(find / -name 'vmlinuz*') /boot/vmlinuz && \ + mv $(find . -name 'initramfs-*.img' -o -name initrd) /boot/initrd.img {{- end }} RUN yum clean all && \ From 58739c9f1b79bed4d250138157e77a73ded99af6 Mon Sep 17 00:00:00 2001 From: Adphi Date: Wed, 29 Apr 2026 17:06:10 +0200 Subject: [PATCH 2/2] feat: Add grub and grub-efi boot support for Rocky and AlmaLinux 9+ Signed-off-by: Adphi --- e2e/e2e_test.go | 2 +- grub.go | 6 +++--- grub_efi.go | 19 ++++++++++++++++--- templates/centos.Dockerfile | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index d349158..2338c66 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -135,7 +135,7 @@ imgs: require.NoError(os.Remove(out)) } - require.NoError(docker.RunD2VM(ctx, d2vm.Image, d2vm.Version, dir, dir, "convert", append([]string{"-p", "root", "-o", "/out/" + filepath.Base(out), "-v", "--keep-cache", img.name}, tt.args...)...)) + require.NoError(docker.RunD2VM(ctx, d2vm.Image, d2vm.Version, dir, dir, "convert", append([]string{"-p", "root", "-o", "/out/" + filepath.Base(out), "-v", "--keep-cache", "--boot-size=250", img.name}, tt.args...)...)) inr, inw := io.Pipe() defer inr.Close() diff --git a/grub.go b/grub.go index e853f4a..e54ae97 100644 --- a/grub.go +++ b/grub.go @@ -41,7 +41,7 @@ func (g grub) Setup(ctx context.Context, dev, root string, cmdline string) error return err } defer clean() - if err := g.install(ctx, "--target=x86_64-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy"); err != nil { + if err := g.install(ctx, "--target=x86_64-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy", "--force"); err != nil { return err } if err := g.install(ctx, "--target=i386-pc", "--boot-directory=/boot", dev); err != nil { @@ -61,8 +61,8 @@ func (g grubProvider) New(c Config, r OSRelease, arch string) (Bootloader, error if arch != "x86_64" { return nil, fmt.Errorf("grub is only supported for amd64") } - if r.ID == ReleaseCentOS || r.ID == ReleaseRocky || r.ID == ReleaseAlmaLinux { - return nil, fmt.Errorf("grub (efi) is not supported for CentOS / Rocky / AlmaLinux, use grub-bios instead") + if err := checkGrubEFISupport(r); err != nil { + return nil, err } return grub{grubCommon: newGrubCommon(c, r)}, nil } diff --git a/grub_efi.go b/grub_efi.go index 4c3a83f..c544c97 100644 --- a/grub_efi.go +++ b/grub_efi.go @@ -17,6 +17,8 @@ package d2vm import ( "context" "fmt" + "strconv" + "strings" "github.com/sirupsen/logrus" ) @@ -42,7 +44,7 @@ func (g grubEFI) Setup(ctx context.Context, dev, root string, cmdline string) er return err } defer clean() - if err := g.install(ctx, "--target="+g.arch+"-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy"); err != nil { + if err := g.install(ctx, "--target="+g.arch+"-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy", "--force"); err != nil { return err } if err := g.mkconfig(ctx); err != nil { @@ -56,8 +58,8 @@ type grubEFIProvider struct { } func (g grubEFIProvider) New(c Config, r OSRelease, arch string) (Bootloader, error) { - if r.ID == ReleaseCentOS || r.ID == ReleaseRocky || r.ID == ReleaseAlmaLinux { - return nil, fmt.Errorf("grub-efi is not supported for CentOS, use grub-bios instead") + if err := checkGrubEFISupport(r); err != nil { + return nil, err } return grubEFI{grubCommon: newGrubCommon(c, r), arch: arch}, nil } @@ -66,6 +68,17 @@ func (g grubEFIProvider) Name() string { return "grub-efi" } +func checkGrubEFISupport(r OSRelease) error { + if r.ID == ReleaseCentOS { + return fmt.Errorf("grub (efi) is not supported for CentOS, use grub-bios instead") + } + v, _ := strconv.Atoi(strings.Split(r.VersionID, ".")[0]) + if (r.ID == ReleaseAlmaLinux || r.ID == ReleaseRocky) && v < 9 { + return fmt.Errorf("grub (efi) is not supported for %s (%s), use 9+ releases or grub-bios instead", r.ID, r.VersionID) + } + return nil +} + func init() { RegisterBootloaderProvider(grubEFIProvider{}) } diff --git a/templates/centos.Dockerfile b/templates/centos.Dockerfile index e584ef8..8a1af85 100644 --- a/templates/centos.Dockerfile +++ b/templates/centos.Dockerfile @@ -50,8 +50,8 @@ RUN set -e; \ kver="$(basename "$dir")"; \ initrd="${dir}/initrd"; \ [ -e "$initrd" ] || continue; \ - ln -sf "${linux#/boot/}" "/boot/vmlinuz-${kver}"; \ - ln -sf "${initrd#/boot/}" "/boot/initramfs-${kver}.img"; \ + mv "${linux}" "/boot/vmlinuz-${kver}"; \ + mv "${initrd}" "/boot/initramfs-${kver}.img"; \ done {{- else }} RUN cd /boot && \