1
0
mirror of https://github.com/kairos-io/kairos-agent.git synced 2025-05-12 10:24:23 +00:00

sparkles: Auto-detect device with 'auto'

This commit is contained in:
Ettore Di Giacinto 2022-09-10 13:01:24 +00:00 committed by Itxaka
parent d7e6e9efa4
commit 0763c820f2
2 changed files with 21 additions and 0 deletions

View File

@ -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")

View File

@ -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()