Add label to luks partition and dont gate on label (#471)

* Add label to luks partition and dont gate on label

Instead of gating on labels, lets just add the label to the luks
partition, the same way we do to the underlying unlocked partition, so
they share the fs label. That way, the locking and unlocking refer to
the same label always

---------

Signed-off-by: Itxaka <itxaka@kairos.io>
(cherry picked from commit b0b2518e6a)
This commit is contained in:
Itxaka
2025-03-13 10:34:23 +01:00
committed by Itxaka
parent 33ce07902b
commit 08d8a003e6
3 changed files with 12 additions and 51 deletions

View File

@@ -76,6 +76,7 @@ func Luksify(label string, logger zerolog.Logger, argsCreate ...string) (string,
device := fmt.Sprintf("/dev/%s", part)
extraArgs := []string{"--uuid", uuid.NewV5(uuid.NamespaceURL, label).String()}
extraArgs = append(extraArgs, "--label", label)
extraArgs = append(extraArgs, argsCreate...)
if err := CreateLuks(device, pass, extraArgs...); err != nil {
@@ -207,10 +208,14 @@ func formatLuks(device, name, mapper, label, pass string, logger zerolog.Logger)
return fmt.Errorf("mkfs err: %w, out: %s", err, out)
}
// Refresh needs the password as its doing actions on the device directly
l.Debug().Msg("discards")
out, err = SH(fmt.Sprintf("cryptsetup refresh --persistent --allow-discards %s", mapper))
cmd := exec.Command("cryptsetup", "refresh", "--persistent", "--allow-discards", mapper)
cmd.Stdin = strings.NewReader(pass)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("refresh err: %w, out: %s", err, out)
return fmt.Errorf("refresh err: %w, out: %s", err, string(output))
}
l.Debug().Msg("close")