Skip to content
Open
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.25 as builder
FROM golang:1.25 AS builder

WORKDIR /d2vm

Expand Down
1 change: 1 addition & 0 deletions bootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ type BootloaderProvider interface {
type Bootloader interface {
Validate(fs BootFS) error
Setup(ctx context.Context, dev, root, cmdline string) error
Static() bool
}
5 changes: 5 additions & 0 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size uint64,
return nil, err
}

if !bl.Static() {
config.Kernel = ""
config.Initrd = ""
}

if size == 0 {
size = 10 * uint64(datasize.GB)
}
Expand Down
16 changes: 13 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,21 @@ type Config struct {
}

func (c Config) Cmdline(root Root, args ...string) string {
var r string
cmdline := "net.ifnames=0 rootfstype=ext4 console=tty0 console=ttyS0,115200n8"
if c.Kernel == "" && c.Initrd == "" {
return cmdline
}
parts := []string{"ro"}
if root != nil {
r = fmt.Sprintf("root=%s", root.String())
parts = append(parts, fmt.Sprintf("root=%s", root.String()))
}
if c.Initrd != "" {
parts = append(parts, fmt.Sprintf("initrd=%s", c.Initrd))
}
if len(args) != 0 {
parts = append(parts, args...)
}
return fmt.Sprintf("ro initrd=%s %s net.ifnames=0 rootfstype=ext4 console=tty0 console=ttyS0,115200n8 %s", c.Initrd, r, strings.Join(args, " "))
return strings.Join(append(parts, cmdline), " ")
}

func (r OSRelease) Config() (Config, error) {
Expand Down
4 changes: 2 additions & 2 deletions grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ type grubProvider struct {
config Config
}

func (g grubProvider) New(c Config, r OSRelease, arch string) (Bootloader, error) {
func (g grubProvider) New(_ Config, r OSRelease, arch string) (Bootloader, error) {
if arch != "x86_64" {
return nil, fmt.Errorf("grub is only supported for amd64")
}
if err := checkGrubEFISupport(r); err != nil {
return nil, err
}
return grub{grubCommon: newGrubCommon(c, r)}, nil
return grub{grubCommon: newGrubCommon(r)}, nil
}

func (g grubProvider) Name() string {
Expand Down
8 changes: 3 additions & 5 deletions grub_bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ func (g grubBios) Setup(ctx context.Context, dev, root string, cmdline string) e
return nil
}

type grubBiosProvider struct {
config Config
}
type grubBiosProvider struct{}

func (g grubBiosProvider) New(c Config, r OSRelease, arch string) (Bootloader, error) {
func (g grubBiosProvider) New(_ Config, r OSRelease, arch string) (Bootloader, error) {
if arch != "x86_64" {
return nil, fmt.Errorf("grub-bios is only supported for amd64")
}
return grubBios{grubCommon: newGrubCommon(c, r)}, nil
return grubBios{grubCommon: newGrubCommon(r)}, nil
}

func (g grubBiosProvider) Name() string {
Expand Down
8 changes: 5 additions & 3 deletions grub_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,18 @@ GRUB_ENABLE_BLSCFG=false

type grubCommon struct {
name string
c Config
r OSRelease
root string
dev string
}

func newGrubCommon(c Config, r OSRelease) *grubCommon {
func newGrubCommon(r OSRelease) *grubCommon {
name := "grub"
if r.ID == ReleaseCentOS || r.ID == ReleaseAlmaLinux || r.ID == ReleaseRocky {
name = "grub2"
}
return &grubCommon{
name: name,
c: c,
r: r,
}
}
Expand Down Expand Up @@ -102,3 +100,7 @@ func (g *grubCommon) mkconfig(ctx context.Context) error {
}
return exec.Run(ctx, "chroot", g.root, g.name+"-mkconfig", "-o", "/boot/"+g.name+"/grub.cfg")
}

func (g *grubCommon) Static() bool {
return false
}
8 changes: 3 additions & 5 deletions grub_efi.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ func (g grubEFI) Setup(ctx context.Context, dev, root string, cmdline string) er
return nil
}

type grubEFIProvider struct {
config Config
}
type grubEFIProvider struct{}

func (g grubEFIProvider) New(c Config, r OSRelease, arch string) (Bootloader, error) {
func (g grubEFIProvider) New(_ Config, r OSRelease, arch string) (Bootloader, error) {
if err := checkGrubEFISupport(r); err != nil {
return nil, err
}
return grubEFI{grubCommon: newGrubCommon(c, r), arch: arch}, nil
return grubEFI{grubCommon: newGrubCommon(r), arch: arch}, nil
}

func (g grubEFIProvider) Name() string {
Expand Down
4 changes: 4 additions & 0 deletions syslinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (s syslinuxProvider) New(c Config, _ OSRelease, arch string) (Bootloader, e
}, nil
}

func (s syslinux) Static() bool {
return true
}

func (s syslinuxProvider) Name() string {
return "syslinux"
}
Expand Down
Loading