2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2026-06-09 13:35:45 +00:00

fix: remove unused parameters from grub cmdline

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2026-05-07 09:19:15 +02:00
parent 58739c9f1b
commit ece3ff4745
9 changed files with 38 additions and 20 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
FROM golang:1.25 as builder FROM golang:1.25 AS builder
WORKDIR /d2vm WORKDIR /d2vm
+1
View File
@@ -40,4 +40,5 @@ type BootloaderProvider interface {
type Bootloader interface { type Bootloader interface {
Validate(fs BootFS) error Validate(fs BootFS) error
Setup(ctx context.Context, dev, root, cmdline string) error Setup(ctx context.Context, dev, root, cmdline string) error
Static() bool
} }
+5
View File
@@ -165,6 +165,11 @@ func NewBuilder(ctx context.Context, workdir, imgTag, disk string, size uint64,
return nil, err return nil, err
} }
if !bl.Static() {
config.Kernel = ""
config.Initrd = ""
}
if size == 0 { if size == 0 {
size = 10 * uint64(datasize.GB) size = 10 * uint64(datasize.GB)
} }
+14 -4
View File
@@ -60,11 +60,21 @@ type Config struct {
} }
func (c Config) Cmdline(root Root, args ...string) string { func (c Config) Cmdline(root Root, args ...string) string {
var r string cmdline := "net.ifnames=0 rootfstype=ext4 console=tty0 console=ttyS0,115200n8"
if root != nil { if c.Kernel == "" && c.Initrd == "" {
r = fmt.Sprintf("root=%s", root.String()) return cmdline
} }
return fmt.Sprintf("ro initrd=%s %s net.ifnames=0 rootfstype=ext4 console=tty0 console=ttyS0,115200n8 %s", c.Initrd, r, strings.Join(args, " ")) parts := []string{"ro"}
if root != nil {
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 strings.Join(append(parts, cmdline), " ")
} }
func (r OSRelease) Config() (Config, error) { func (r OSRelease) Config() (Config, error) {
+2 -2
View File
@@ -57,14 +57,14 @@ type grubProvider struct {
config Config 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" { if arch != "x86_64" {
return nil, fmt.Errorf("grub is only supported for amd64") return nil, fmt.Errorf("grub is only supported for amd64")
} }
if err := checkGrubEFISupport(r); err != nil { if err := checkGrubEFISupport(r); err != nil {
return nil, err return nil, err
} }
return grub{grubCommon: newGrubCommon(c, r)}, nil return grub{grubCommon: newGrubCommon(r)}, nil
} }
func (g grubProvider) Name() string { func (g grubProvider) Name() string {
+3 -5
View File
@@ -45,15 +45,13 @@ func (g grubBios) Setup(ctx context.Context, dev, root string, cmdline string) e
return nil return nil
} }
type grubBiosProvider struct { type grubBiosProvider struct{}
config Config
}
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" { if arch != "x86_64" {
return nil, fmt.Errorf("grub-bios is only supported for amd64") 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 { func (g grubBiosProvider) Name() string {
+5 -3
View File
@@ -38,20 +38,18 @@ GRUB_ENABLE_BLSCFG=false
type grubCommon struct { type grubCommon struct {
name string name string
c Config
r OSRelease r OSRelease
root string root string
dev string dev string
} }
func newGrubCommon(c Config, r OSRelease) *grubCommon { func newGrubCommon(r OSRelease) *grubCommon {
name := "grub" name := "grub"
if r.ID == ReleaseCentOS || r.ID == ReleaseAlmaLinux || r.ID == ReleaseRocky { if r.ID == ReleaseCentOS || r.ID == ReleaseAlmaLinux || r.ID == ReleaseRocky {
name = "grub2" name = "grub2"
} }
return &grubCommon{ return &grubCommon{
name: name, name: name,
c: c,
r: r, r: r,
} }
} }
@@ -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") return exec.Run(ctx, "chroot", g.root, g.name+"-mkconfig", "-o", "/boot/"+g.name+"/grub.cfg")
} }
func (g *grubCommon) Static() bool {
return false
}
+3 -5
View File
@@ -53,15 +53,13 @@ func (g grubEFI) Setup(ctx context.Context, dev, root string, cmdline string) er
return nil return nil
} }
type grubEFIProvider struct { type grubEFIProvider struct{}
config Config
}
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 { if err := checkGrubEFISupport(r); err != nil {
return nil, err 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 { func (g grubEFIProvider) Name() string {
+4
View File
@@ -91,6 +91,10 @@ func (s syslinuxProvider) New(c Config, _ OSRelease, arch string) (Bootloader, e
}, nil }, nil
} }
func (s syslinux) Static() bool {
return true
}
func (s syslinuxProvider) Name() string { func (s syslinuxProvider) Name() string {
return "syslinux" return "syslinux"
} }