diff --git a/config.yaml b/config.yaml index 48ac73c2..f98d72d5 100644 --- a/config.yaml +++ b/config.yaml @@ -21,15 +21,13 @@ stages: commands: - | parted --script --machine -- "/dev/vdb" mklabel gpt + sgdisk --new=1:2048:+1M --change-name=1:'bios' --typecode=1:EF02 /dev/vdb # for grub #parted --script "/dev/vdb" mkpart primary fat32 0 1MB #mkfs.fat32 -L COS_GRUB /dev/vdb1 layout: device: path: "/dev/vdb" add_partitions: - - fsLabel: COS_GRUB - size: 1 - pLabel: grub - fsLabel: COS_OEM size: 64 pLabel: oem diff --git a/pkg/action/install.go b/pkg/action/install.go index be4fe008..ea0bbe45 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -149,9 +149,19 @@ func (i InstallAction) Run() (err error) { fmt.Println("!!!!!!!!!!!! won't format") // Check force flag against current device labels := []string{i.spec.Active.Label, i.spec.Recovery.Label} + fmt.Printf("!!!! check active deployment = %+v\n", e.CheckActiveDeployment(labels)) if e.CheckActiveDeployment(labels) && !i.spec.Force { return fmt.Errorf("use `force` flag to run an installation over the current running deployment") } + + if i.spec.Target == "" { + device, err := config.DetectPreConfiguredDevice(i.cfg.Logger) + if err != nil { + return fmt.Errorf("no target device specified and no device found: %s", err) + } + fmt.Printf("!!! device = %+v\n", device) + i.spec.Target = device + } } else { // Deactivate any active volume on target err = e.DeactivateDevices() diff --git a/pkg/config/spec.go b/pkg/config/spec.go index ed0560f0..bdc3072e 100644 --- a/pkg/config/spec.go +++ b/pkg/config/spec.go @@ -18,13 +18,14 @@ package config import ( "fmt" - sdkTypes "github.com/kairos-io/kairos-sdk/types" "io/fs" "os" "path/filepath" "reflect" "strings" + sdkTypes "github.com/kairos-io/kairos-sdk/types" + "github.com/google/go-containerregistry/pkg/crane" "github.com/jaypipes/ghw" "golang.org/x/sys/unix" @@ -580,6 +581,7 @@ func ReadInstallSpecFromConfig(c *Config) (*v1.InstallSpec, error) { fmt.Printf("installSpec after = %+v\n", installSpec) fmt.Printf("!!!!!()()()()()!!!! installSPec.Target = %+v\n", installSpec.Target) + fmt.Printf("!!!!!()()()()()!!!! c.Install.Device = %+v\n", c.Install.Device) // Workaround! // If we set the "auto" for the device in the cloudconfig the value will be proper in the Config.Install.Device @@ -588,11 +590,22 @@ func ReadInstallSpecFromConfig(c *Config) (*v1.InstallSpec, error) { // What device was choosen, and re-choosing again could lead to different results // So instead we do the check here and override the installSpec.Target with the Config.Install.Device // as its the soonest we have access to both - // if installSpec.Target == "auto" { - // fmt.Printf("!!!!!!! installSpec.Target = %+v\n", installSpec.Target) - // fmt.Printf("!!!!!!! c.Install.Device = %+v\n", c.Install.Device) - // installSpec.Target = c.Install.Device + if installSpec.Target == "auto" { + // fmt.Printf("!!!!!!! installSpec.Target = %+v\n", installSpec.Target) + // fmt.Printf("!!!!!!! c.Install.Device = %+v\n", c.Install.Device) + installSpec.Target = c.Install.Device + } + + // if installSpec.Target == "" { + // device, err := DetectPreConfiguredDevice(c.Logger) + // if err != nil { + // return installSpec, err + // } + // installSpec.Target = device // } + + // fmt.Printf("!!!!!(after)()()()()!!!! installSPec.Target = %+v\n", installSpec.Target) + // fmt.Printf("!!!!!(after)()()()()!!!! c.Install.Device = %+v\n", c.Install.Device) return installSpec, nil } @@ -1017,27 +1030,22 @@ func detectLargestDevice() string { return preferedDevice } -// detectPreConfiguredDevice returns a disk that has partitions labeled with +// DetectPreConfiguredDevice returns a disk that has partitions labeled with // Kairos labels. It can be used to detect a pre-configured device. -func detectPreConfiguredDevice(logger v1.Logger) string { +func DetectPreConfiguredDevice(logger sdkTypes.KairosLogger) (string, error) { block, err := ghw.Block() if err != nil { logger.Errorf("failed getting block devices: %w", err) - return "" + return "", err } - fmt.Println("!!!!!***!!!! detecting preconfigured") for _, disk := range block.Disks { - fmt.Printf("!!!!!!!!!!!!!!! disk = %+v\n", disk) for _, p := range disk.Partitions { - fmt.Printf("!!!!!!!!!!!!!!!! p = %+v\n", p) - fmt.Printf("p.FilesystemLabel = %+v\n", p.FilesystemLabel) - fmt.Printf("p.Label = %+v\n", p.Label) if p.FilesystemLabel == "COS_STATE" { - return disk.Name + return filepath.Join("/", "dev", disk.Name), nil } } } - return "" + return "", nil }