diff --git a/internal/agent/install.go b/internal/agent/install.go index 55a4bdf..b3b965c 100644 --- a/internal/agent/install.go +++ b/internal/agent/install.go @@ -197,6 +197,10 @@ func RunInstall(options map[string]string) error { os.Exit(1) } + if device == "auto" { + device = detectDevice() + } + cloudInit, ok := options["cc"] if !ok { fmt.Println("cloudInit must be specified among options") diff --git a/internal/agent/interactive_install.go b/internal/agent/interactive_install.go index f03c494..e1488f2 100644 --- a/internal/agent/interactive_install.go +++ b/internal/agent/interactive_install.go @@ -110,6 +110,23 @@ func promptToUnstructured(p events.YAMLPrompt, unstructuredYAML map[string]inter return unstructuredYAML, nil } +func detectDevice() string { + preferedDevice := "/dev/sda" + maxSize := float64(0) + + block, err := ghw.Block() + if err == nil { + for _, disk := range block.Disks { + size := float64(disk.SizeBytes) / float64(GiB) + if size > maxSize { + maxSize = size + preferedDevice = "/dev/" + disk.Name + } + } + } + return preferedDevice +} + func InteractiveInstall(spawnShell bool) error { bus.Manager.Initialize()