Skip to content

Commit

Permalink
Update the kernel args to instance config during stop
Browse files Browse the repository at this point in the history
This PR is going to update the kernel paramater to instance config
when stop operation happen.

In mac we use kernel parameter as part of vfkit driver to start
the instance but during the reboot it changes because of MCO and
we are getting error during `start => stop => start` operation.

```
systemctl[787]: Failed to switch root: Specified switch root path '/sysroot' does not seem to be an OS tree. os-release file is missing.
```

ostree changes from (`boot.0` => `boot.1`)
```
ostree=/ostree/boot.0/rhcos/b6f1ba590ef2df8e30bd88833fd145bfbbd424eca8ad235f573f2a136f09b0d6/0
```
to
```
ostree=/ostree/boot.1/rhcos/b6f1ba590ef2df8e30bd88833fd145bfbbd424eca8ad235f573f2a136f09b0d6/0
```

As part of the MCO logs
```
Bootloader updated; bootconfig swap: yes; bootversion: boot.1.1, deployment count change: -1
```
  • Loading branch information
praveenkumar committed Aug 16, 2022
1 parent 8d4df00 commit 6af9303
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/crc/machine/driver_darwin.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package machine

import (
"context"
"encoding/json"
"errors"
"time"

"github.com/code-ready/crc/pkg/crc/constants"
"github.com/code-ready/crc/pkg/crc/logging"
"github.com/code-ready/crc/pkg/crc/machine/config"
"github.com/code-ready/crc/pkg/crc/machine/vfkit"
machineVf "github.com/code-ready/crc/pkg/drivers/vfkit"
Expand Down Expand Up @@ -35,3 +38,35 @@ 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()

if err := sshRunner.WaitForConnectivity(context.Background(), 20*time.Second); err != nil {
return err
}

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)
}
4 changes: 4 additions & 0 deletions pkg/crc/machine/driver_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func updateDriverConfig(host *host.Host, driver *machineLibvirt.Driver) error {
return host.UpdateConfig(driverData)
}

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

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

func updateKernelArgs(vm *virtualMachine) error {
return nil
}
3 changes: 3 additions & 0 deletions pkg/crc/machine/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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

0 comments on commit 6af9303

Please sign in to comment.