diff --git a/.drone.jsonnet b/.drone.jsonnet index b1c59bf5b..dd47b2ceb 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -367,6 +367,7 @@ local integration_disk_image = Step("e2e-disk-image", target="e2e-qemu", privile "SHORT_INTEGRATION_TEST": "yes", "USE_DISK_IMAGE": "true", "IMAGE_REGISTRY": local_registry, + "WITH_DISK_ENCRYPTION": "true", }); local integration_canal_reset = Step("e2e-canal-reset", target="e2e-qemu", privileged=true, depends_on=[integration_disk_image], environment={ "INTEGRATION_TEST_RUN": "TestIntegration/api.ResetSuite/TestResetWithSpec", diff --git a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go index a3546b4db..57067f93f 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go @@ -184,6 +184,10 @@ func (*Sequencer) Boot(r runtime.Runtime) []runtime.Phase { phases := PhaseList{} phases = phases.AppendWhen( + r.State().Platform().Mode() != runtime.ModeContainer, + "saveStateEncryptionConfig", + SaveStateEncryptionConfig, + ).AppendWhen( r.State().Platform().Mode() != runtime.ModeContainer, "mountState", MountStatePartition, diff --git a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go index 853ee822c..f9ef14424 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go @@ -1485,7 +1485,13 @@ func MountStatePartition(seq runtime.Sequence, data interface{}) (runtime.TaskEx //nolint:errcheck defer meta.Close() - opts := []mount.Option{mount.WithFlags(mount.SkipIfMounted)} + flags := mount.SkipIfMounted + + if seq == runtime.SequenceInitialize { + flags |= mount.SkipIfNoFilesystem + } + + opts := []mount.Option{mount.WithFlags(flags)} var encryption config.Encryption // first try reading encryption from the config diff --git a/internal/pkg/mount/mount.go b/internal/pkg/mount/mount.go index 2867c15ef..d0d597511 100644 --- a/internal/pkg/mount/mount.go +++ b/internal/pkg/mount/mount.go @@ -14,6 +14,7 @@ import ( "time" "github.com/talos-systems/go-blockdevice/blockdevice" + "github.com/talos-systems/go-blockdevice/blockdevice/filesystem" "github.com/talos-systems/go-blockdevice/blockdevice/util" "github.com/talos-systems/go-retry/retry" "golang.org/x/sys/unix" @@ -44,6 +45,7 @@ func Mount(mountpoints *Points) (err error) { return nil } +//nolint:gocyclo func mountMountpoint(mountpoint *Point) (err error) { var skipMount bool @@ -61,6 +63,10 @@ func mountMountpoint(mountpoint *Point) (err error) { } } + if mountpoint.MountFlags.Check(SkipIfNoFilesystem) && mountpoint.Fstype() == filesystem.Unknown { + skipMount = true + } + if !skipMount { if err = mountpoint.Mount(); err != nil { return fmt.Errorf("error mounting: %w", err) diff --git a/internal/pkg/mount/options.go b/internal/pkg/mount/options.go index 38a237e16..3eb36b5e5 100644 --- a/internal/pkg/mount/options.go +++ b/internal/pkg/mount/options.go @@ -19,6 +19,8 @@ const ( Overlay // SkipIfMounted is a flag for skipping mount if the mountpoint is already mounted. SkipIfMounted + // SkipIfNoFilesystem is a flag for skipping formatting and mounting if the mountpoint has not filesystem. + SkipIfNoFilesystem ) // Flags is the mount flags. diff --git a/internal/pkg/mount/system.go b/internal/pkg/mount/system.go index a1e32e36a..8ad6275a0 100644 --- a/internal/pkg/mount/system.go +++ b/internal/pkg/mount/system.go @@ -157,9 +157,13 @@ func SystemMountPointForLabel(device *blockdevice.BlockDevice, label string, opt return fmt.Errorf("failed to determine format options for partition label %s", part.Name) } - p.fstype = opts.FileSystemType + if !o.MountFlags.Check(SkipIfNoFilesystem) { + p.fstype = opts.FileSystemType - return partition.Format(p.source, opts) + return partition.Format(p.source, opts) + } + + return nil }) opts = append(opts, WithPreMountHooks(preMountHooks...))