Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion grub_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down
19 changes: 16 additions & 3 deletions grub_efi.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package d2vm
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/sirupsen/logrus"
)
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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{})
}
23 changes: 20 additions & 3 deletions templates/centos.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
mv "${linux}" "/boot/vmlinuz-${kver}"; \
mv "${initrd}" "/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 && \
Expand Down
Loading