metropolis: implement A/B updates
This implements an A/B update mechanism using two slots, A and B.
This is realized with two system partitions as well as two EFI
loaders/kernels.
The A/B system relies on two EFI loader entries. This has the advantage
that there is no preloader required, which makes the system more
reliable as well as avoiding the complexity of having an un-updatable
preloader (CoreOS has this issue where their GRUB2 crashed booting newer
kernels, sadly the issue seems lost with the migration to Fedora
CoreOS). It also means that the operator can easily override the slot
being booted via the boot loader entries. Primary disadvantage is that
it relies on EFI working somewhat to spec.
New versions are booted into only once by setting NextBoot, if the
bootup doesn't succeed, i.e. if the boot doesn't get to a cluster rejoin
the next boot will be the old slot. Once it gets to this stage the
permanent BootOrder is changed.
The EFI loaders don't know if they are slot A or B because they are
identical and relying on OptionalData in the boot entry to indicate the
slot means that if the EFI boot entries go away, recovering is very hard.
Thus the loaders look at their own file name to determine what slot they
are in. If no slot could be determined, they default to booting slot A.
It is planned to eventually use Authenticode Stamping (passing data in
fake certificates) to stamp the slot into the loader without affecting
the TPM hash logged.
Change-Id: I40de2df8ff7ff660c17d2c97f3d9eb1bd4ddf5bc
Reviewed-on: https://review.monogon.dev/c/monogon/+/1874
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/metropolis/installer/test/main.go b/metropolis/installer/test/main.go
index 3636658..ec4f736 100644
--- a/metropolis/installer/test/main.go
+++ b/metropolis/installer/test/main.go
@@ -215,10 +215,10 @@
defer ctxC()
// Prepare the block device image the installer will install to.
- // Needs enough storage for a 4096 MiB system partition, a 128 MiB ESP and
- // a 128MiB data partition. In addition at the start and end we need 1MiB
- // for GPT headers and alignment.
- storagePath, err := getStorage(4096 + 128 + 128 + 2)
+ // Needs enough storage for two 4096 MiB system partitions, a 384 MiB ESP
+ // and a 128 MiB data partition. In addition at the start and end we need
+ // 1MiB for GPT headers and alignment.
+ storagePath, err := getStorage(4096*2 + 384 + 128 + 2)
defer os.Remove(storagePath)
if err != nil {
t.Errorf(err.Error())
@@ -252,16 +252,21 @@
}
// Verify the system partition's GPT entry.
system := (pi[1]).(*gpt.Partition)
- if system.Name != osimage.SystemLabel || system.Start == 0 || system.End == 0 {
+ if system.Name != osimage.SystemALabel || system.Start == 0 || system.End == 0 {
+ t.Error("The node's system partition GPT entry looks off.")
+ }
+ // Verify the system partition's GPT entry.
+ systemB := (pi[2]).(*gpt.Partition)
+ if systemB.Name != osimage.SystemBLabel || systemB.Start == 0 || systemB.End == 0 {
t.Error("The node's system partition GPT entry looks off.")
}
// Verify the data partition's GPT entry.
- data := (pi[2]).(*gpt.Partition)
+ data := (pi[3]).(*gpt.Partition)
if data.Name != osimage.DataLabel || data.Start == 0 || data.End == 0 {
t.Errorf("The node's data partition GPT entry looks off: %+v", data)
}
// Verify that there are no more partitions.
- fourth := (pi[3]).(*gpt.Partition)
+ fourth := (pi[4]).(*gpt.Partition)
if fourth.Name != "" || fourth.Start != 0 || fourth.End != 0 {
t.Error("The resulting node image contains more partitions than expected.")
}