Skip to content

Commit 58739c9

Browse files
committed
feat: Add grub and grub-efi boot support for Rocky and AlmaLinux 9+
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
1 parent e77827d commit 58739c9

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ imgs:
135135
require.NoError(os.Remove(out))
136136
}
137137

138-
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...)...))
138+
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...)...))
139139

140140
inr, inw := io.Pipe()
141141
defer inr.Close()

grub.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (g grub) Setup(ctx context.Context, dev, root string, cmdline string) error
4141
return err
4242
}
4343
defer clean()
44-
if err := g.install(ctx, "--target=x86_64-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy"); err != nil {
44+
if err := g.install(ctx, "--target=x86_64-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy", "--force"); err != nil {
4545
return err
4646
}
4747
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
6161
if arch != "x86_64" {
6262
return nil, fmt.Errorf("grub is only supported for amd64")
6363
}
64-
if r.ID == ReleaseCentOS || r.ID == ReleaseRocky || r.ID == ReleaseAlmaLinux {
65-
return nil, fmt.Errorf("grub (efi) is not supported for CentOS / Rocky / AlmaLinux, use grub-bios instead")
64+
if err := checkGrubEFISupport(r); err != nil {
65+
return nil, err
6666
}
6767
return grub{grubCommon: newGrubCommon(c, r)}, nil
6868
}

grub_efi.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package d2vm
1717
import (
1818
"context"
1919
"fmt"
20+
"strconv"
21+
"strings"
2022

2123
"github.com/sirupsen/logrus"
2224
)
@@ -42,7 +44,7 @@ func (g grubEFI) Setup(ctx context.Context, dev, root string, cmdline string) er
4244
return err
4345
}
4446
defer clean()
45-
if err := g.install(ctx, "--target="+g.arch+"-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy"); err != nil {
47+
if err := g.install(ctx, "--target="+g.arch+"-efi", "--efi-directory=/boot", "--no-nvram", "--removable", "--no-floppy", "--force"); err != nil {
4648
return err
4749
}
4850
if err := g.mkconfig(ctx); err != nil {
@@ -56,8 +58,8 @@ type grubEFIProvider struct {
5658
}
5759

5860
func (g grubEFIProvider) New(c Config, r OSRelease, arch string) (Bootloader, error) {
59-
if r.ID == ReleaseCentOS || r.ID == ReleaseRocky || r.ID == ReleaseAlmaLinux {
60-
return nil, fmt.Errorf("grub-efi is not supported for CentOS, use grub-bios instead")
61+
if err := checkGrubEFISupport(r); err != nil {
62+
return nil, err
6163
}
6264
return grubEFI{grubCommon: newGrubCommon(c, r), arch: arch}, nil
6365
}
@@ -66,6 +68,17 @@ func (g grubEFIProvider) Name() string {
6668
return "grub-efi"
6769
}
6870

71+
func checkGrubEFISupport(r OSRelease) error {
72+
if r.ID == ReleaseCentOS {
73+
return fmt.Errorf("grub (efi) is not supported for CentOS, use grub-bios instead")
74+
}
75+
v, _ := strconv.Atoi(strings.Split(r.VersionID, ".")[0])
76+
if (r.ID == ReleaseAlmaLinux || r.ID == ReleaseRocky) && v < 9 {
77+
return fmt.Errorf("grub (efi) is not supported for %s (%s), use 9+ releases or grub-bios instead", r.ID, r.VersionID)
78+
}
79+
return nil
80+
}
81+
6982
func init() {
7083
RegisterBootloaderProvider(grubEFIProvider{})
7184
}

templates/centos.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ RUN set -e; \
5050
kver="$(basename "$dir")"; \
5151
initrd="${dir}/initrd"; \
5252
[ -e "$initrd" ] || continue; \
53-
ln -sf "${linux#/boot/}" "/boot/vmlinuz-${kver}"; \
54-
ln -sf "${initrd#/boot/}" "/boot/initramfs-${kver}.img"; \
53+
mv "${linux}" "/boot/vmlinuz-${kver}"; \
54+
mv "${initrd}" "/boot/initramfs-${kver}.img"; \
5555
done
5656
{{- else }}
5757
RUN cd /boot && \

0 commit comments

Comments
 (0)