Skip to content

Commit

Permalink
vfkit: Switch to EFIBootLoader from LinuxBootLoader (BIOS)
Browse files Browse the repository at this point in the history
vfkit have a way to load efi bootloader and since we are now supporting
only macos>13, better to switch it and it also allow a bit code clean around
kernel update when start from stopped state.
  • Loading branch information
praveenkumar committed Aug 8, 2024
1 parent e28d25f commit 8c5e26d
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 59 deletions.
1 change: 1 addition & 0 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var (
DaemonSocketPath = filepath.Join(CrcBaseDir, "crc.sock")
KubeconfigFilePath = filepath.Join(MachineInstanceDir, DefaultName, "kubeconfig")
PasswdFilePath = filepath.Join(MachineInstanceDir, DefaultName, "passwd")
EFIVariablePath = filepath.Join(MachineInstanceDir, DefaultName, "efi-bl-crc")
)

func GetDefaultBundlePath(preset crcpreset.Preset) string {
Expand Down
4 changes: 1 addition & 3 deletions pkg/crc/machine/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ type MachineConfig struct {
SharedDirUsername string

// macOS specific configuration
KernelCmdLine string
Initramfs string
Kernel string
VariableStore string

// Experimental features
NetworkMode network.Mode
Expand Down
29 changes: 0 additions & 29 deletions pkg/crc/machine/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"

"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/crc-org/crc/v2/pkg/crc/machine/config"
"github.com/crc-org/crc/v2/pkg/crc/machine/vfkit"
machineVf "github.com/crc-org/crc/v2/pkg/drivers/vfkit"
Expand Down Expand Up @@ -37,34 +36,6 @@ func updateDriverConfig(host *host.Host, driver *machineVf.Driver) error {
return host.UpdateConfig(driverData)
}

func updateKernelArgs(vm *virtualMachine) error {
logging.Info("Updating kernel args...")
sshRunner, err := vm.SSHRunner()
if err != nil {
return err
}
defer sshRunner.Close()

stdout, stderr, err := sshRunner.RunPrivileged("Get kernel args", `-- sh -c 'rpm-ostree kargs'`)
if err != nil {
logging.Errorf("Failed to get kernel args: %v - %s", err, stderr)
return err
}
logging.Debugf("Kernel args: %s", stdout)

vfkitDriver, err := loadDriverConfig(vm.Host)
if err != nil {
return err
}
logging.Debugf("Current Kernel args: %s", vfkitDriver.Cmdline)
vfkitDriver.Cmdline = stdout

if err := updateDriverConfig(vm.Host, vfkitDriver); err != nil {
return err
}
return vm.api.Save(vm.Host)
}

func updateDriverStruct(_ *host.Host, _ *machineVf.Driver) error {
return drivers.ErrNotImplemented
}
4 changes: 0 additions & 4 deletions pkg/crc/machine/driver_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func updateDriverConfig(host *host.Host, driver *machineLibvirt.Driver) error {
return host.UpdateConfig(driverData)
}

func updateKernelArgs(_ *virtualMachine) error {
return nil
}

/*
func (r *RPCServerDriver) SetConfigRaw(data []byte, _ *struct{}) error {
return json.Unmarshal(data, &r.ActualDriver)
Expand Down
4 changes: 0 additions & 4 deletions pkg/crc/machine/driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ func updateDriverConfig(host *host.Host, driver *machineHyperv.Driver) error {
return host.UpdateConfig(driverData)
}

func updateKernelArgs(_ *virtualMachine) error {
return nil
}

func updateDriverStruct(host *host.Host, driver *machineHyperv.Driver) error {
host.Driver = driver
return nil
Expand Down
4 changes: 1 addition & 3 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig)
ImageSourcePath: crcBundleMetadata.GetDiskImagePath(),
ImageFormat: crcBundleMetadata.GetDiskImageFormat(),
SSHKeyPath: crcBundleMetadata.GetSSHKeyPath(),
KernelCmdLine: crcBundleMetadata.GetKernelCommandLine(),
Initramfs: crcBundleMetadata.GetInitramfsPath(),
Kernel: crcBundleMetadata.GetKernelPath(),
VariableStore: constants.EFIVariablePath,
SharedDirs: sharedDirs,
SharedDirPassword: startConfig.SharedDirPassword,
SharedDirUsername: startConfig.SharedDirUsername,
Expand Down
3 changes: 0 additions & 3 deletions pkg/crc/machine/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ func (client *client) Stop() (state.State, error) {
logging.Debugf("%v", err)
}
}
if err := updateKernelArgs(vm); err != nil {
logging.Debugf("%v", err)
}
logging.Info("Stopping the instance, this may take a few minutes...")
if err := vm.Stop(); err != nil {
status, stateErr := vm.State()
Expand Down
4 changes: 1 addition & 3 deletions pkg/crc/machine/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ func CreateHost(machineConfig config.MachineConfig) *vfkit.Driver {

config.InitVMDriverFromMachineConfig(machineConfig, vfDriver.VMDriver)

vfDriver.Cmdline = machineConfig.KernelCmdLine
vfDriver.VmlinuzPath = machineConfig.Kernel
vfDriver.InitrdPath = machineConfig.Initramfs
vfDriver.VariableStore = machineConfig.VariableStore
vfDriver.VfkitPath = ExecutablePath()

vfDriver.VirtioNet = machineConfig.NetworkMode == network.SystemNetworkingMode
Expand Down
14 changes: 4 additions & 10 deletions pkg/drivers/vfkit/driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ import (

type Driver struct {
*drivers.VMDriver
VmlinuzPath string
Cmdline string
InitrdPath string
VfkitPath string
VirtioNet bool
VariableStore string
VfkitPath string
VirtioNet bool

VsockPath string
DaemonVsockPort uint
Expand Down Expand Up @@ -170,11 +168,7 @@ func (d *Driver) Start() error {
return err
}

bootLoader := config.NewLinuxBootloader(
d.VmlinuzPath,
"console=hvc0 "+d.Cmdline,
d.InitrdPath,
)
bootLoader := config.NewEFIBootloader(d.VariableStore, true)

vm := config.NewVirtualMachine(
uint(d.CPU),
Expand Down

0 comments on commit 8c5e26d

Please sign in to comment.