Skip to content

Commit

Permalink
Merge pull request #328 from kairos-io/2511-call-udev
Browse files Browse the repository at this point in the history
Trigger udev to populate disk info
  • Loading branch information
jimmykarily authored May 23, 2024
2 parents 74a54e6 + a6ec42e commit 3943784
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/lib/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ 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"
"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 {
Expand Down Expand Up @@ -57,6 +58,13 @@ 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
out, err := SH("udevadm trigger --settle -v --type=all")
if err != nil {
return "", fmt.Errorf("udevadm trigger failed: %w, out: %s", err, out)
}
SH("sync") //nolint:errcheck

part, b, err := FindPartition(label)
if err != nil {
return "", err
Expand Down Expand Up @@ -110,7 +118,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)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/lib/unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func UnlockAllWithLogger(tpm bool, logger zerolog.Logger) error {
return nil
}

logger.Info().Msgf("triggering udev to populate disk info")
_, err = utils.SH("udevadm trigger -v --type=all")
if err != nil {
return err
}

for _, disk := range blk.Disks {
for _, p := range disk.Partitions {
if p.Type == "crypto_LUKS" {
Expand Down

0 comments on commit 3943784

Please sign in to comment.