Compare commits

...

6 Commits

Author SHA1 Message Date
Itxaka
70dfc0c14b Drop settle for all
Signed-off-by: Itxaka <itxaka@kairos.io>
2024-05-28 20:56:56 +02:00
Itxaka
2f3a99f421 Remove -v flag on udev unlock
it can cause locks

Signed-off-by: Itxaka <itxaka@kairos.io>
2024-05-28 19:24:59 +02:00
Itxaka
4495239b5f Avoid calling udevadm with -v flag
seems like it can block and has no timeout

Signed-off-by: Itxaka <itxaka@kairos.io>
2024-05-28 14:46:57 +02:00
Dimitris Karakasilis
f6ed18cd18 Try a simpler version of "udevadm trigger"
in case the other options are not supported

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
2024-05-28 11:24:49 +02:00
Dimitris Karakasilis
c936f74913 Trigger udev events also on lock
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
2024-05-28 11:24:36 +02:00
Dimitris Karakasilis
7de640988f Trigger udev to populate disk info
because otherwise, sometimes the encrypted partition doesn't show up as
type: crypto_LUKS but as type: unknown making kcrypt skip it completely

Part of https://github.com/kairos-io/kairos/issues/2511

(an additional seems to be needed in kairos-agent when locking the
partitions to fully fix the issue)

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
2024-05-28 11:24:28 +02:00
2 changed files with 23 additions and 5 deletions

View File

@ -2,15 +2,17 @@ package lib
import (
"fmt"
"github.com/gofrs/uuid"
"github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/block"
configpkg "github.com/kairos-io/kcrypt/pkg/config"
"math/rand"
"os"
"os/exec"
"strings"
"syscall"
"time"
"github.com/gofrs/uuid"
"github.com/jaypipes/ghw"
"github.com/jaypipes/ghw/pkg/block"
configpkg "github.com/kairos-io/kcrypt/pkg/config"
)
func CreateLuks(dev, password, version string, cryptsetupArgs ...string) error {
@ -57,6 +59,14 @@ func Luksify(label, version string, tpm bool) (string, error) {
return "", fmt.Errorf("version must be luks1 or luks2")
}
// Make sure ghw will see all partitions correctly.
// older versions don't have --type=all. Try the simpler version then.
out, err := SH("udevadm trigger --type=all || udevadm trigger")
if err != nil {
return "", fmt.Errorf("udevadm trigger failed: %w, out: %s", err, out)
}
syscall.Sync()
part, b, err := FindPartition(label)
if err != nil {
return "", err
@ -109,7 +119,7 @@ func Luksify(label, version string, tpm bool) (string, error) {
}
cmd := fmt.Sprintf("mkfs.ext4 -L %s %s", label, devMapper)
out, err := SH(cmd)
out, err = SH(cmd)
if err != nil {
return "", fmt.Errorf("mkfs err: %w, out: %s", err, out)
}

View File

@ -38,6 +38,14 @@ func UnlockAllWithLogger(tpm bool, logger zerolog.Logger) error {
return nil
}
// Some versions of udevadm don't support --settle (e.g. alpine)
// and older versions don't have --type=all. Try the simpler version then.
logger.Info().Msgf("triggering udev to populate disk info")
_, err = utils.SH("udevadm trigger --type=all || udevadm trigger")
if err != nil {
return err
}
for _, disk := range blk.Disks {
for _, p := range disk.Partitions {
if p.Type == "crypto_LUKS" {