mirror of
https://github.com/linka-cloud/d2vm.git
synced 2026-05-12 18:38:15 +00:00
fix: remove unused parameters from grub cmdline
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -60,11 +60,21 @@ type Config struct {
|
||||
}
|
||||
|
||||
func (c Config) Cmdline(root Root, args ...string) string {
|
||||
var r string
|
||||
if root != nil {
|
||||
r = fmt.Sprintf("root=%s", root.String())
|
||||
cmdline := "net.ifnames=0 rootfstype=ext4 console=tty0 console=ttyS0,115200n8"
|
||||
if c.Kernel == "" && c.Initrd == "" {
|
||||
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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+3
-5
@@ -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 {
|
||||
|
||||
+5
-3
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+3
-5
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user