From 5504179ba91b13b90735741fabbbb74f01e22fd4 Mon Sep 17 00:00:00 2001 From: David Cassany Date: Mon, 17 Jun 2024 12:54:03 +0200 Subject: [PATCH 1/5] Make EFI partition size configurable at install time Signed-off-by: David Cassany --- config.yaml.example | 2 +- pkg/config/config.go | 22 +++++++++++++++++++--- pkg/types/config.go | 13 ++++--------- pkg/types/config_test.go | 3 +-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/config.yaml.example b/config.yaml.example index e0e682ce430..b082598fff2 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -19,7 +19,7 @@ install: # size: 300 # default partitions - # only 'oem', 'recovery', 'state' and 'persistent' objects allowed + # only 'efi', 'oem', 'recovery', 'state' and 'persistent' objects allowed # size in MiB partitions: oem: diff --git a/pkg/config/config.go b/pkg/config/config.go index 3402aebf482..8ce76b67125 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -261,6 +261,16 @@ func NewMountSpec(cfg types.Config) *types.MountSpec { func NewInstallElementalPartitions() types.ElementalPartitions { partitions := types.ElementalPartitions{} + + partitions.EFI = &types.Partition{ + FilesystemLabel: constants.EfiLabel, + Size: constants.EfiSize, + Name: constants.EfiPartName, + FS: constants.EfiFs, + MountPoint: constants.EfiDir, + Flags: []string{types.ESP}, + } + partitions.OEM = &types.Partition{ FilesystemLabel: constants.OEMLabel, Size: constants.OEMSize, @@ -476,9 +486,15 @@ func NewResetSpec(cfg types.Config) (*types.ResetSpec, error) { func NewDiskElementalPartitions(workdir string) types.ElementalPartitions { partitions := types.ElementalPartitions{} - // does not return error on types.EFI use case - _ = partitions.SetFirmwarePartitions(types.EFI, types.GPT) - partitions.EFI.Path = filepath.Join(workdir, constants.EfiPartName+partSuffix) + partitions.EFI = &types.Partition{ + FilesystemLabel: constants.EfiLabel, + Size: constants.EfiSize, + Name: constants.EfiPartName, + FS: constants.EfiFs, + MountPoint: constants.EfiDir, + Path: filepath.Join(workdir, constants.EfiPartName+partSuffix), + Flags: []string{types.ESP}, + } partitions.OEM = &types.Partition{ FilesystemLabel: constants.OEMLabel, diff --git a/pkg/types/config.go b/pkg/types/config.go index 395fb939a04..cd5900dbb8d 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -35,7 +35,7 @@ const ( BIOS = "bios" MSDOS = "msdos" EFI = "efi" - esp = "esp" + ESP = "esp" bios = "bios_grub" boot = "boot" ) @@ -502,7 +502,7 @@ func (pl PartitionList) GetByNameOrLabel(name, label string) *Partition { type ElementalPartitions struct { BIOS *Partition - EFI *Partition + EFI *Partition `yaml:"efi,omitempty" mapstructure:"efi"` OEM *Partition `yaml:"oem,omitempty" mapstructure:"oem"` Recovery *Partition `yaml:"recovery,omitempty" mapstructure:"recovery"` State *Partition `yaml:"state,omitempty" mapstructure:"state"` @@ -520,13 +520,8 @@ func (ep ElementalPartitions) GetConfigStorage() string { // SetFirmwarePartitions sets firmware partitions for a given firmware and partition table type func (ep *ElementalPartitions) SetFirmwarePartitions(firmware string, partTable string) error { if firmware == EFI && partTable == GPT { - ep.EFI = &Partition{ - FilesystemLabel: constants.EfiLabel, - Size: constants.EfiSize, - Name: constants.EfiPartName, - FS: constants.EfiFs, - MountPoint: constants.EfiDir, - Flags: []string{esp}, + if ep.EFI == nil { + return fmt.Errorf("nil efi partition") } ep.BIOS = nil } else if firmware == BIOS && partTable == GPT { diff --git a/pkg/types/config_test.go b/pkg/types/config_test.go index 09e72424a14..5b1575c526e 100644 --- a/pkg/types/config_test.go +++ b/pkg/types/config_test.go @@ -191,8 +191,7 @@ var _ = Describe("Types", Label("types", "config"), func() { It("sets firmware partitions on efi", func() { Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) err := ep.SetFirmwarePartitions(types.EFI, types.GPT) - Expect(err).ShouldNot(HaveOccurred()) - Expect(ep.EFI != nil && ep.BIOS == nil).To(BeTrue()) + Expect(err).Should(HaveOccurred()) }) It("sets firmware partitions on bios", func() { Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) From 7b3f0ac8ca8aa110362c4e81d792fd4c47dbce8a Mon Sep 17 00:00:00 2001 From: David Cassany Date: Mon, 17 Jun 2024 13:22:17 +0200 Subject: [PATCH 2/5] Add a custom EFI size test Signed-off-by: David Cassany --- cmd/config/config_test.go | 1 + cmd/config/fixtures/config/config.yaml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/cmd/config/config_test.go b/cmd/config/config_test.go index 40aee0ae93d..f30a75741d9 100644 --- a/cmd/config/config_test.go +++ b/cmd/config/config_test.go @@ -348,6 +348,7 @@ var _ = Describe("Config", Label("config"), func() { spec, err := ReadInstallSpec(cfg, flags) Expect(err).ShouldNot(HaveOccurred()) + Expect(spec.Partitions.EFI.Size).To(Equal(uint(512))) // Overwrites target and recovery-system from environment variables Expect(spec.Target == "/env/disk") Expect(spec.RecoverySystem.Source.Value() == "recovery/image:from_env_vars") diff --git a/cmd/config/fixtures/config/config.yaml b/cmd/config/fixtures/config/config.yaml index 87186ca5894..4bfbcb168bc 100644 --- a/cmd/config/fixtures/config/config.yaml +++ b/cmd/config/fixtures/config/config.yaml @@ -4,6 +4,9 @@ cloud-init-paths: - "some/alternate/path" install: + partitions: + efi: + size: 512 target: "someDisk" no-format: true From 48e7e54e16246066149b4014108aceb07508ef0e Mon Sep 17 00:00:00 2001 From: David Cassany Date: Mon, 17 Jun 2024 17:54:17 +0200 Subject: [PATCH 3/5] Rename efi to bootloader partition in config.yaml Signed-off-by: David Cassany --- cmd/config/fixtures/config/config.yaml | 2 +- config.yaml.example | 2 +- pkg/types/config.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/config/fixtures/config/config.yaml b/cmd/config/fixtures/config/config.yaml index 4bfbcb168bc..b6f3e157fe8 100644 --- a/cmd/config/fixtures/config/config.yaml +++ b/cmd/config/fixtures/config/config.yaml @@ -5,7 +5,7 @@ cloud-init-paths: install: partitions: - efi: + bootloader: size: 512 target: "someDisk" diff --git a/config.yaml.example b/config.yaml.example index b082598fff2..ad317fa8320 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -19,7 +19,7 @@ install: # size: 300 # default partitions - # only 'efi', 'oem', 'recovery', 'state' and 'persistent' objects allowed + # only 'bootloader', 'oem', 'recovery', 'state' and 'persistent' objects allowed # size in MiB partitions: oem: diff --git a/pkg/types/config.go b/pkg/types/config.go index cd5900dbb8d..c1e16289563 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -502,7 +502,7 @@ func (pl PartitionList) GetByNameOrLabel(name, label string) *Partition { type ElementalPartitions struct { BIOS *Partition - EFI *Partition `yaml:"efi,omitempty" mapstructure:"efi"` + EFI *Partition `yaml:"bootloader,omitempty" mapstructure:"bootloader"` OEM *Partition `yaml:"oem,omitempty" mapstructure:"oem"` Recovery *Partition `yaml:"recovery,omitempty" mapstructure:"recovery"` State *Partition `yaml:"state,omitempty" mapstructure:"state"` From be377aaa7f3a7a7166b5b3d962e28802be4c0cba Mon Sep 17 00:00:00 2001 From: David Cassany Date: Tue, 18 Jun 2024 11:40:45 +0200 Subject: [PATCH 4/5] Rename EFI variable to Boot Signed-off-by: David Cassany --- cmd/config/config_test.go | 2 +- pkg/action/build-disk.go | 6 +++--- pkg/action/install.go | 14 +++++++------- pkg/action/reset.go | 10 +++++----- pkg/action/upgrade.go | 14 +++++++------- pkg/action/upgrade_test.go | 2 +- pkg/config/config.go | 20 ++++++++++---------- pkg/config/config_test.go | 6 +++--- pkg/elemental/elemental_test.go | 8 ++++---- pkg/error/exit-codes.go | 2 +- pkg/types/config.go | 18 +++++++++--------- pkg/types/config_test.go | 20 ++++++++++---------- pkg/types/grub.go | 2 +- 13 files changed, 62 insertions(+), 62 deletions(-) diff --git a/cmd/config/config_test.go b/cmd/config/config_test.go index f30a75741d9..a51f7dd41a0 100644 --- a/cmd/config/config_test.go +++ b/cmd/config/config_test.go @@ -348,7 +348,7 @@ var _ = Describe("Config", Label("config"), func() { spec, err := ReadInstallSpec(cfg, flags) Expect(err).ShouldNot(HaveOccurred()) - Expect(spec.Partitions.EFI.Size).To(Equal(uint(512))) + Expect(spec.Partitions.Boot.Size).To(Equal(uint(512))) // Overwrites target and recovery-system from environment variables Expect(spec.Target == "/env/disk") Expect(spec.RecoverySystem.Source.Value() == "recovery/image:from_env_vars") diff --git a/pkg/action/build-disk.go b/pkg/action/build-disk.go index 5bc6ff13deb..248a354319a 100644 --- a/pkg/action/build-disk.go +++ b/pkg/action/build-disk.go @@ -453,7 +453,7 @@ func (b *BuildDiskAction) createStatePartitionImage() (*types.Image, error) { // createEFIPartitionImage creates the EFI partition image func (b *BuildDiskAction) createEFIPartitionImage() (*types.Image, error) { - img := b.spec.Partitions.EFI.ToImage() + img := b.spec.Partitions.Boot.ToImage() err := elemental.CreateFileSystemImage(b.cfg.Config, img, "", false) if err != nil { b.cfg.Logger.Errorf("failed creating EFI image: %s", err.Error()) @@ -741,9 +741,9 @@ func (b *BuildDiskAction) createBuildDiskStateYaml(stateRoot, recoveryRoot strin FSLabel: b.spec.Partitions.Persistent.FilesystemLabel, } } - if b.spec.Partitions.EFI != nil { + if b.spec.Partitions.Boot != nil { installState.Partitions[constants.EfiPartName] = &types.PartitionState{ - FSLabel: b.spec.Partitions.EFI.FilesystemLabel, + FSLabel: b.spec.Partitions.Boot.FilesystemLabel, } } diff --git a/pkg/action/install.go b/pkg/action/install.go index 42da7e74ee3..ea3e245b4d3 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -95,7 +95,7 @@ func (i *InstallAction) installChrootHook(hook string, root string) error { if oem != nil && oem.MountPoint != "" { extraMounts[oem.MountPoint] = cnst.OEMPath } - efi := i.spec.Partitions.EFI + efi := i.spec.Partitions.Boot if efi != nil && efi.MountPoint != "" { extraMounts[efi.MountPoint] = cnst.EfiDir } @@ -147,9 +147,9 @@ func (i *InstallAction) createInstallStateYaml() error { FSLabel: i.spec.Partitions.Persistent.FilesystemLabel, } } - if i.spec.Partitions.EFI != nil { + if i.spec.Partitions.Boot != nil { installState.Partitions[cnst.EfiPartName] = &types.PartitionState{ - FSLabel: i.spec.Partitions.EFI.FilesystemLabel, + FSLabel: i.spec.Partitions.Boot.FilesystemLabel, } } @@ -190,7 +190,7 @@ func (i InstallAction) Run() (err error) { return elemental.UnmountPartitions(i.cfg.Config, i.spec.Partitions.PartitionsByMountPoint(true)) }) - err = i.snapshotter.InitSnapshotter(i.spec.Partitions.State, i.spec.Partitions.EFI.MountPoint) + err = i.snapshotter.InitSnapshotter(i.spec.Partitions.State, i.spec.Partitions.Boot.MountPoint) if err != nil { i.cfg.Logger.Errorf("failed initializing snapshotter") return elementalError.NewFromError(err, elementalError.SnapshotterInit) @@ -317,7 +317,7 @@ func (i *InstallAction) refineDeployment() error { //nolint:dupl // Install grub err = i.bootloader.Install( i.snapshot.WorkDir, - i.spec.Partitions.EFI.MountPoint, + i.spec.Partitions.Boot.MountPoint, ) if err != nil { i.cfg.Logger.Errorf("failed installing grub: %v", err) @@ -337,7 +337,7 @@ func (i *InstallAction) refineDeployment() error { //nolint:dupl grubVars := i.spec.GetGrubLabels() err = i.bootloader.SetPersistentVariables( - filepath.Join(i.spec.Partitions.EFI.MountPoint, cnst.GrubOEMEnv), + filepath.Join(i.spec.Partitions.Boot.MountPoint, cnst.GrubOEMEnv), grubVars, ) if err != nil { @@ -347,7 +347,7 @@ func (i *InstallAction) refineDeployment() error { //nolint:dupl // Installation rebrand (only grub for now) err = i.bootloader.SetDefaultEntry( - i.spec.Partitions.EFI.MountPoint, + i.spec.Partitions.Boot.MountPoint, cnst.WorkingImgDir, i.spec.GrubDefEntry, ) diff --git a/pkg/action/reset.go b/pkg/action/reset.go index 55ddbd4b534..2fffd517783 100644 --- a/pkg/action/reset.go +++ b/pkg/action/reset.go @@ -45,7 +45,7 @@ func (r *ResetAction) resetChrootHook(hook string, root string) error { if oem != nil && oem.MountPoint != "" { extraMounts[oem.MountPoint] = constants.OEMPath } - efi := r.spec.Partitions.EFI + efi := r.spec.Partitions.Boot if efi != nil && efi.MountPoint != "" { extraMounts[efi.MountPoint] = constants.EfiDir } @@ -219,7 +219,7 @@ func (r ResetAction) Run() (err error) { }) // Init snapshotter - err = r.snapshotter.InitSnapshotter(r.spec.Partitions.State, r.spec.Partitions.EFI.MountPoint) + err = r.snapshotter.InitSnapshotter(r.spec.Partitions.State, r.spec.Partitions.Boot.MountPoint) if err != nil { return elementalError.NewFromError(err, elementalError.SnapshotterInit) } @@ -290,7 +290,7 @@ func (r *ResetAction) refineDeployment() error { //nolint:dupl // Install grub err = r.bootloader.Install( r.snapshot.WorkDir, - r.spec.Partitions.EFI.MountPoint, + r.spec.Partitions.Boot.MountPoint, ) if err != nil { r.cfg.Logger.Errorf("failed installing grub: %v", err) @@ -310,7 +310,7 @@ func (r *ResetAction) refineDeployment() error { //nolint:dupl grubVars := r.spec.GetGrubLabels() err = r.bootloader.SetPersistentVariables( - filepath.Join(r.spec.Partitions.EFI.MountPoint, constants.GrubOEMEnv), + filepath.Join(r.spec.Partitions.Boot.MountPoint, constants.GrubOEMEnv), grubVars, ) if err != nil { @@ -320,7 +320,7 @@ func (r *ResetAction) refineDeployment() error { //nolint:dupl // Installation rebrand (only grub for now) err = r.bootloader.SetDefaultEntry( - r.spec.Partitions.EFI.MountPoint, + r.spec.Partitions.Boot.MountPoint, constants.WorkingImgDir, r.spec.GrubDefEntry, ) diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 1fbbe63507f..a41682bece9 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -119,7 +119,7 @@ func (u UpgradeAction) upgradeChrootHook(hook string, root string) error { mountPoints[persistentDevice.MountPoint] = constants.PersistentPath } - efiDevice := u.spec.Partitions.EFI + efiDevice := u.spec.Partitions.Boot if efiDevice != nil && efiDevice.MountPoint != "" { mountPoints[efiDevice.MountPoint] = constants.EfiDir } @@ -210,9 +210,9 @@ func (u *UpgradeAction) upgradeInstallStateYaml() error { } func (u *UpgradeAction) mountRWPartitions(cleanup *utils.CleanStack) error { - umount, err := elemental.MountRWPartition(u.cfg.Config, u.spec.Partitions.EFI) + umount, err := elemental.MountRWPartition(u.cfg.Config, u.spec.Partitions.Boot) if err != nil { - return elementalError.NewFromError(err, elementalError.MountEFIPartition) + return elementalError.NewFromError(err, elementalError.MountBootPartition) } cleanup.Push(umount) @@ -254,7 +254,7 @@ func (u *UpgradeAction) Run() (err error) { } // Init snapshotter - err = u.snapshotter.InitSnapshotter(u.spec.Partitions.State, u.spec.Partitions.EFI.MountPoint) + err = u.snapshotter.InitSnapshotter(u.spec.Partitions.State, u.spec.Partitions.Boot.MountPoint) if err != nil { u.cfg.Logger.Errorf("failed initializing snapshotter") return elementalError.NewFromError(err, elementalError.SnapshotterInit) @@ -353,7 +353,7 @@ func (u *UpgradeAction) refineDeployment() error { //nolint:dupl if u.spec.BootloaderUpgrade { err = u.bootloader.Install( u.snapshot.WorkDir, - u.spec.Partitions.EFI.MountPoint, + u.spec.Partitions.Boot.MountPoint, ) if err != nil { u.cfg.Logger.Errorf("failed installing grub: %v", err) @@ -374,7 +374,7 @@ func (u *UpgradeAction) refineDeployment() error { //nolint:dupl grubVars := u.spec.GetGrubLabels() err = u.bootloader.SetPersistentVariables( - filepath.Join(u.spec.Partitions.EFI.MountPoint, constants.GrubOEMEnv), + filepath.Join(u.spec.Partitions.Boot.MountPoint, constants.GrubOEMEnv), grubVars, ) if err != nil { @@ -382,7 +382,7 @@ func (u *UpgradeAction) refineDeployment() error { //nolint:dupl return elementalError.NewFromError(err, elementalError.SetGrubVariables) } - err = u.bootloader.SetDefaultEntry(u.spec.Partitions.EFI.MountPoint, constants.WorkingImgDir, u.spec.GrubDefEntry) + err = u.bootloader.SetDefaultEntry(u.spec.Partitions.Boot.MountPoint, constants.WorkingImgDir, u.spec.GrubDefEntry) if err != nil { u.Error("failed setting default entry") return elementalError.NewFromError(err, elementalError.SetDefaultGrubEntry) diff --git a/pkg/action/upgrade_test.go b/pkg/action/upgrade_test.go index 892eb1ceba8..3d10fb21f30 100644 --- a/pkg/action/upgrade_test.go +++ b/pkg/action/upgrade_test.go @@ -225,7 +225,7 @@ var _ = Describe("Runtime Actions", func() { Expect(memLog).To(ContainSubstring("default_menu_entry=TESTOS")) // Writes filesystem labels to GRUB oem env file - grubOEMEnv := filepath.Join(spec.Partitions.EFI.MountPoint, constants.GrubOEMEnv) + grubOEMEnv := filepath.Join(spec.Partitions.Boot.MountPoint, constants.GrubOEMEnv) Expect(runner.IncludesCmds( [][]string{{"grub2-editenv", grubOEMEnv, "set", "passive_snaps=2"}}, )).To(Succeed()) diff --git a/pkg/config/config.go b/pkg/config/config.go index 8ce76b67125..8d1dff6f5e2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -262,7 +262,7 @@ func NewMountSpec(cfg types.Config) *types.MountSpec { func NewInstallElementalPartitions() types.ElementalPartitions { partitions := types.ElementalPartitions{} - partitions.EFI = &types.Partition{ + partitions.Boot = &types.Partition{ FilesystemLabel: constants.EfiLabel, Size: constants.EfiSize, Name: constants.EfiPartName, @@ -371,9 +371,9 @@ func NewUpgradeSpec(cfg types.Config) (*types.UpgradeSpec, error) { } } - if ep.EFI != nil { - if ep.EFI.MountPoint == "" { - ep.EFI.MountPoint = constants.EfiDir + if ep.Boot != nil { + if ep.Boot.MountPoint == "" { + ep.Boot.MountPoint = constants.EfiDir } } @@ -416,13 +416,13 @@ func NewResetSpec(cfg types.Config) (*types.ResetSpec, error) { ep := types.NewElementalPartitionsFromList(parts, installState) if efiExists { - if ep.EFI == nil { - return nil, fmt.Errorf("EFI partition not found") + if ep.Boot == nil { + return nil, fmt.Errorf("Bootloader partition not found") } - if ep.EFI.MountPoint == "" { - ep.EFI.MountPoint = constants.EfiDir + if ep.Boot.MountPoint == "" { + ep.Boot.MountPoint = constants.EfiDir } - ep.EFI.Name = constants.EfiPartName + ep.Boot.Name = constants.EfiPartName } if ep.State == nil { @@ -486,7 +486,7 @@ func NewResetSpec(cfg types.Config) (*types.ResetSpec, error) { func NewDiskElementalPartitions(workdir string) types.ElementalPartitions { partitions := types.ElementalPartitions{} - partitions.EFI = &types.Partition{ + partitions.Boot = &types.Partition{ FilesystemLabel: constants.EfiLabel, Size: constants.EfiSize, Name: constants.EfiPartName, diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 9baea998eea..76670b43cfa 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -134,7 +134,7 @@ var _ = Describe("Types", Label("types", "config"), func() { Expect(spec.RecoverySystem.Source.Value()).To(Equal(spec.System.Value())) Expect(spec.PartTable).To(Equal(types.GPT)) - Expect(spec.Partitions.EFI).NotTo(BeNil()) + Expect(spec.Partitions.Boot).NotTo(BeNil()) }) It("sets installation defaults without being on installation media", Label("install"), func() { spec := config.NewInstallSpec(*c) @@ -209,7 +209,7 @@ var _ = Describe("Types", Label("types", "config"), func() { spec, err := config.NewResetSpec(*c) Expect(err).ShouldNot(HaveOccurred()) - Expect(spec.Partitions.EFI.MountPoint).To(Equal(constants.EfiDir)) + Expect(spec.Partitions.Boot.MountPoint).To(Equal(constants.EfiDir)) }) It("sets reset defaults to recovery image", func() { // Set non-squashfs recovery image detection @@ -297,7 +297,7 @@ var _ = Describe("Types", Label("types", "config"), func() { bootedFrom = constants.RecoveryImgFile _, err := config.NewResetSpec(*c) Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("EFI partition not found")) + Expect(err.Error()).To(ContainSubstring("Bootloader partition not found")) }) }) }) diff --git a/pkg/elemental/elemental_test.go b/pkg/elemental/elemental_test.go index a9f31d0cade..e42644c4d0c 100644 --- a/pkg/elemental/elemental_test.go +++ b/pkg/elemental/elemental_test.go @@ -177,7 +177,7 @@ var _ = Describe("Elemental", Label("elemental"), func() { _, err = fs.Create("/some/device") Expect(err).ToNot(HaveOccurred()) - parts.EFI.Path = "/dev/device1" + parts.Boot.Path = "/dev/device1" parts.OEM.Path = "/dev/device2" parts.Recovery.Path = "/dev/device3" parts.State.Path = "/dev/device4" @@ -197,7 +197,7 @@ var _ = Describe("Elemental", Label("elemental"), func() { }) It("Ignores partitions with undefiend mountpoints", func() { - parts.EFI.MountPoint = "" + parts.Boot.MountPoint = "" err := elemental.MountPartitions(*config, parts.PartitionsByMountPoint(false)) Expect(err).To(BeNil()) @@ -251,7 +251,7 @@ var _ = Describe("Elemental", Label("elemental"), func() { _, err = fs.Create("/some/device") Expect(err).ToNot(HaveOccurred()) - parts.EFI.Path = "/dev/device1" + parts.Boot.Path = "/dev/device1" parts.OEM.Path = "/dev/device2" parts.Recovery.Path = "/dev/device3" parts.State.Path = "/dev/device4" @@ -275,7 +275,7 @@ var _ = Describe("Elemental", Label("elemental"), func() { }) It("Ignores partitions with undefiend mountpoints", func() { - parts.EFI.MountPoint = "" + parts.Boot.MountPoint = "" err := elemental.UnmountPartitions(*config, parts.PartitionsByMountPoint(true)) Expect(err).To(BeNil()) diff --git a/pkg/error/exit-codes.go b/pkg/error/exit-codes.go index 6dcae2cda6a..c408712026d 100644 --- a/pkg/error/exit-codes.go +++ b/pkg/error/exit-codes.go @@ -254,7 +254,7 @@ const SnapshotterInit = 84 const SnapshotterStart = 85 // Error mounting EFI partition -const MountEFIPartition = 86 +const MountBootPartition = 86 // Error mounting Persistent partition const MountPersistentPartition = 87 diff --git a/pkg/types/config.go b/pkg/types/config.go index c1e16289563..eeb7370d8a2 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -396,8 +396,8 @@ func (u *UpgradeSpec) Sanitize() error { } if u.BootloaderUpgrade { - if u.Partitions.EFI == nil || u.Partitions.EFI.MountPoint == "" { - return fmt.Errorf("undefined EFI partition") + if u.Partitions.Boot == nil || u.Partitions.Boot.MountPoint == "" { + return fmt.Errorf("undefined Bootloader partition") } } @@ -502,7 +502,7 @@ func (pl PartitionList) GetByNameOrLabel(name, label string) *Partition { type ElementalPartitions struct { BIOS *Partition - EFI *Partition `yaml:"bootloader,omitempty" mapstructure:"bootloader"` + Boot *Partition `yaml:"bootloader,omitempty" mapstructure:"bootloader"` OEM *Partition `yaml:"oem,omitempty" mapstructure:"oem"` Recovery *Partition `yaml:"recovery,omitempty" mapstructure:"recovery"` State *Partition `yaml:"state,omitempty" mapstructure:"state"` @@ -520,7 +520,7 @@ func (ep ElementalPartitions) GetConfigStorage() string { // SetFirmwarePartitions sets firmware partitions for a given firmware and partition table type func (ep *ElementalPartitions) SetFirmwarePartitions(firmware string, partTable string) error { if firmware == EFI && partTable == GPT { - if ep.EFI == nil { + if ep.Boot == nil { return fmt.Errorf("nil efi partition") } ep.BIOS = nil @@ -533,13 +533,13 @@ func (ep *ElementalPartitions) SetFirmwarePartitions(firmware string, partTable MountPoint: "", Flags: []string{bios}, } - ep.EFI = nil + ep.Boot = nil } else { if ep.State == nil { return fmt.Errorf("nil state partition") } ep.State.Flags = []string{boot} - ep.EFI = nil + ep.Boot = nil ep.BIOS = nil } return nil @@ -567,7 +567,7 @@ func NewElementalPartitionsFromList(pl PartitionList, state *InstallState) Eleme } ep.BIOS = pl.GetByName(constants.BiosPartName) - ep.EFI = pl.GetByNameOrLabel(constants.EfiPartName, lm[constants.EfiPartName]) + ep.Boot = pl.GetByNameOrLabel(constants.EfiPartName, lm[constants.EfiPartName]) ep.OEM = pl.GetByNameOrLabel(constants.OEMPartName, lm[constants.OEMPartName]) ep.Recovery = pl.GetByNameOrLabel(constants.RecoveryPartName, lm[constants.RecoveryPartName]) ep.State = pl.GetByNameOrLabel(constants.StatePartName, lm[constants.StatePartName]) @@ -595,8 +595,8 @@ func (ep ElementalPartitions) PartitionsByInstallOrder(extraPartitions Partition if ep.BIOS != nil && !inExcludes(ep.BIOS, excludes...) { partitions = append(partitions, ep.BIOS) } - if ep.EFI != nil && !inExcludes(ep.EFI, excludes...) { - partitions = append(partitions, ep.EFI) + if ep.Boot != nil && !inExcludes(ep.Boot, excludes...) { + partitions = append(partitions, ep.Boot) } if ep.OEM != nil && !inExcludes(ep.OEM, excludes...) { partitions = append(partitions, ep.OEM) diff --git a/pkg/types/config_test.go b/pkg/types/config_test.go index 5b1575c526e..1770f155d4d 100644 --- a/pkg/types/config_test.go +++ b/pkg/types/config_test.go @@ -188,27 +188,27 @@ var _ = Describe("Types", Label("types", "config"), func() { }, } }) - It("sets firmware partitions on efi", func() { - Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) + It("sets firmware partitions on Boot", func() { + Expect(ep.Boot == nil && ep.BIOS == nil).To(BeTrue()) err := ep.SetFirmwarePartitions(types.EFI, types.GPT) Expect(err).Should(HaveOccurred()) }) It("sets firmware partitions on bios", func() { - Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) + Expect(ep.Boot == nil && ep.BIOS == nil).To(BeTrue()) err := ep.SetFirmwarePartitions(types.BIOS, types.GPT) Expect(err).ShouldNot(HaveOccurred()) - Expect(ep.EFI == nil && ep.BIOS != nil).To(BeTrue()) + Expect(ep.Boot == nil && ep.BIOS != nil).To(BeTrue()) }) It("sets firmware partitions on msdos", func() { ep.State = &types.Partition{} - Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) + Expect(ep.Boot == nil && ep.BIOS == nil).To(BeTrue()) err := ep.SetFirmwarePartitions(types.BIOS, types.MSDOS) Expect(err).ShouldNot(HaveOccurred()) - Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) + Expect(ep.Boot == nil && ep.BIOS == nil).To(BeTrue()) Expect(ep.State.Flags != nil && ep.State.Flags[0] == "boot").To(BeTrue()) }) It("fails to set firmware partitions of state is not defined on msdos", func() { - Expect(ep.EFI == nil && ep.BIOS == nil).To(BeTrue()) + Expect(ep.Boot == nil && ep.BIOS == nil).To(BeTrue()) err := ep.SetFirmwarePartitions(types.BIOS, types.MSDOS) Expect(err).Should(HaveOccurred()) }) @@ -224,7 +224,7 @@ var _ = Describe("Types", Label("types", "config"), func() { Expect(ep.Persistent != nil).To(BeTrue()) Expect(ep.OEM != nil).To(BeTrue()) Expect(ep.BIOS == nil).To(BeTrue()) - Expect(ep.EFI == nil).To(BeTrue()) + Expect(ep.Boot == nil).To(BeTrue()) Expect(ep.State == nil).To(BeTrue()) Expect(ep.Recovery != nil).To(BeTrue()) }) @@ -373,7 +373,7 @@ var _ = Describe("Types", Label("types", "config"), func() { }) Describe("sanitize", func() { It("runs method", func() { - Expect(spec.Partitions.EFI).ToNot(BeNil()) + Expect(spec.Partitions.Boot).ToNot(BeNil()) Expect(spec.System.IsEmpty()).To(BeTrue()) // Creates firmware partitions @@ -381,7 +381,7 @@ var _ = Describe("Types", Label("types", "config"), func() { spec.Firmware = types.EFI err := spec.Sanitize() Expect(err).ShouldNot(HaveOccurred()) - Expect(spec.Partitions.EFI).NotTo(BeNil()) + Expect(spec.Partitions.Boot).NotTo(BeNil()) // Sets image labels to empty string on squashfs spec.RecoverySystem.FS = constants.SquashFs diff --git a/pkg/types/grub.go b/pkg/types/grub.go index 92a720e9858..99f58f1bb9e 100644 --- a/pkg/types/grub.go +++ b/pkg/types/grub.go @@ -71,7 +71,7 @@ func (r ResetSpec) GetGrubLabels() map[string]string { func (d DiskSpec) GetGrubLabels() map[string]string { return map[string]string{ - "efi_label": d.Partitions.EFI.FilesystemLabel, + "efi_label": d.Partitions.Boot.FilesystemLabel, "oem_label": d.Partitions.OEM.FilesystemLabel, "recovery_label": d.Partitions.Recovery.FilesystemLabel, "state_label": d.Partitions.State.FilesystemLabel, From 4f6e8c1489c18ae4154aa0b14a7e87e5ea8abc65 Mon Sep 17 00:00:00 2001 From: David Cassany Date: Tue, 18 Jun 2024 12:02:56 +0200 Subject: [PATCH 5/5] Rename constants Signed-off-by: David Cassany --- pkg/action/build-disk.go | 18 ++++++------- pkg/action/build-iso.go | 4 +-- pkg/action/install.go | 4 +-- pkg/action/install_test.go | 2 +- pkg/action/reset.go | 2 +- pkg/action/upgrade-recovery.go | 6 ++--- pkg/action/upgrade-recovery_test.go | 6 ++--- pkg/action/upgrade.go | 2 +- pkg/action/upgrade_test.go | 4 +-- pkg/bootloader/grub.go | 2 +- pkg/config/config.go | 40 ++++++++++++++--------------- pkg/config/config_test.go | 6 ++--- pkg/constants/constants.go | 24 ++++++++--------- pkg/elemental/elemental_test.go | 2 +- pkg/snapshotter/btrfs_test.go | 2 +- pkg/snapshotter/loopdevice_test.go | 2 +- pkg/types/config.go | 8 +++--- 17 files changed, 67 insertions(+), 67 deletions(-) diff --git a/pkg/action/build-disk.go b/pkg/action/build-disk.go index 248a354319a..011e58ae70c 100644 --- a/pkg/action/build-disk.go +++ b/pkg/action/build-disk.go @@ -175,7 +175,7 @@ func (b *BuildDiskAction) BuildDiskRun() (err error) { //nolint:gocyclo } // Install grub - err = b.bootloader.InstallConfig(recRoot, b.roots[constants.EfiPartName]) + err = b.bootloader.InstallConfig(recRoot, b.roots[constants.BootPartName]) if err != nil { b.cfg.Logger.Errorf("failed installing grub configuration: %s", err.Error()) return err @@ -196,7 +196,7 @@ func (b *BuildDiskAction) BuildDiskRun() (err error) { //nolint:gocyclo grubVars := b.spec.GetGrubLabels() err = b.bootloader.SetPersistentVariables( - filepath.Join(b.roots[constants.EfiPartName], constants.GrubOEMEnv), + filepath.Join(b.roots[constants.BootPartName], constants.GrubOEMEnv), grubVars, ) if err != nil { @@ -205,7 +205,7 @@ func (b *BuildDiskAction) BuildDiskRun() (err error) { //nolint:gocyclo } err = b.bootloader.InstallEFI( - recRoot, b.roots[constants.EfiPartName], + recRoot, b.roots[constants.BootPartName], ) if err != nil { b.cfg.Logger.Errorf("failed installing grub efi binaries: %s", err.Error()) @@ -213,7 +213,7 @@ func (b *BuildDiskAction) BuildDiskRun() (err error) { //nolint:gocyclo } // Rebrand - err = b.bootloader.SetDefaultEntry(b.roots[constants.EfiPartName], recRoot, b.spec.GrubDefEntry) + err = b.bootloader.SetDefaultEntry(b.roots[constants.BootPartName], recRoot, b.spec.GrubDefEntry) if err != nil { return elementalError.NewFromError(err, elementalError.SetDefaultGrubEntry) } @@ -404,7 +404,7 @@ func (b *BuildDiskAction) createStatePartitionImage() (*types.Image, error) { }() // Run a snapshotter transaction for System source in state partition - err = b.snapshotter.InitSnapshotter(b.spec.Partitions.State, b.roots[constants.EfiPartName]) + err = b.snapshotter.InitSnapshotter(b.spec.Partitions.State, b.roots[constants.BootPartName]) if err != nil { b.cfg.Logger.Errorf("failed initializing snapshotter") return nil, elementalError.NewFromError(err, elementalError.SnapshotterInit) @@ -460,13 +460,13 @@ func (b *BuildDiskAction) createEFIPartitionImage() (*types.Image, error) { return nil, err } - err = utils.WalkDirFs(b.cfg.Fs, b.roots[constants.EfiPartName], func(path string, _ fs.DirEntry, err error) error { + err = utils.WalkDirFs(b.cfg.Fs, b.roots[constants.BootPartName], func(path string, _ fs.DirEntry, err error) error { if err != nil { return err } - if path != b.roots[constants.EfiPartName] { - rel, err := filepath.Rel(b.roots[constants.EfiPartName], path) + if path != b.roots[constants.BootPartName] { + rel, err := filepath.Rel(b.roots[constants.BootPartName], path) if err != nil { return err } @@ -742,7 +742,7 @@ func (b *BuildDiskAction) createBuildDiskStateYaml(stateRoot, recoveryRoot strin } } if b.spec.Partitions.Boot != nil { - installState.Partitions[constants.EfiPartName] = &types.PartitionState{ + installState.Partitions[constants.BootPartName] = &types.PartitionState{ FSLabel: b.spec.Partitions.Boot.FilesystemLabel, } } diff --git a/pkg/action/build-iso.go b/pkg/action/build-iso.go index a70e99abef1..e67b74faac2 100644 --- a/pkg/action/build-iso.go +++ b/pkg/action/build-iso.go @@ -240,8 +240,8 @@ func (b BuildISOAction) createEFI(root string, img string) error { err = elemental.CreateFileSystemImage(b.cfg.Config, &types.Image{ File: img, Size: uint(efiSizeMB), - FS: constants.EfiFs, - Label: constants.EfiLabel, + FS: constants.BootFs, + Label: constants.BootLabel, }, "", false) if err != nil { return err diff --git a/pkg/action/install.go b/pkg/action/install.go index ea3e245b4d3..e0440e2b5f9 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -97,7 +97,7 @@ func (i *InstallAction) installChrootHook(hook string, root string) error { } efi := i.spec.Partitions.Boot if efi != nil && efi.MountPoint != "" { - extraMounts[efi.MountPoint] = cnst.EfiDir + extraMounts[efi.MountPoint] = cnst.BootDir } return ChrootHook(&i.cfg.Config, hook, i.cfg.Strict, root, extraMounts, i.cfg.CloudInitPaths...) } @@ -148,7 +148,7 @@ func (i *InstallAction) createInstallStateYaml() error { } } if i.spec.Partitions.Boot != nil { - installState.Partitions[cnst.EfiPartName] = &types.PartitionState{ + installState.Partitions[cnst.BootPartName] = &types.PartitionState{ FSLabel: i.spec.Partitions.Boot.FilesystemLabel, } } diff --git a/pkg/action/install_test.go b/pkg/action/install_test.go index e5b660a401a..f4cc0936c3f 100644 --- a/pkg/action/install_test.go +++ b/pkg/action/install_test.go @@ -397,7 +397,7 @@ var _ = Describe("Install action tests", func() { bootloader.ErrorSetDefaultEntry = true err = installer.Run() Expect(err).NotTo(BeNil()) - Expect(runner.MatchMilestones([][]string{{"grub2-editenv", filepath.Join(constants.EfiDir, constants.GrubOEMEnv)}})) + Expect(runner.MatchMilestones([][]string{{"grub2-editenv", filepath.Join(constants.BootDir, constants.GrubOEMEnv)}})) }) // Start transaction diff --git a/pkg/action/reset.go b/pkg/action/reset.go index 2fffd517783..62a3f8fe514 100644 --- a/pkg/action/reset.go +++ b/pkg/action/reset.go @@ -47,7 +47,7 @@ func (r *ResetAction) resetChrootHook(hook string, root string) error { } efi := r.spec.Partitions.Boot if efi != nil && efi.MountPoint != "" { - extraMounts[efi.MountPoint] = constants.EfiDir + extraMounts[efi.MountPoint] = constants.BootDir } return ChrootHook(&r.cfg.Config, hook, r.cfg.Strict, root, extraMounts, r.cfg.CloudInitPaths...) } diff --git a/pkg/action/upgrade-recovery.go b/pkg/action/upgrade-recovery.go index a603f16bb81..d78b464e816 100644 --- a/pkg/action/upgrade-recovery.go +++ b/pkg/action/upgrade-recovery.go @@ -151,7 +151,7 @@ func (u *UpgradeRecoveryAction) Run() (err error) { } // Remove any traces of previously errored upgrades - transitionDir := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.BootTransitionDir) + transitionDir := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.BootTransitionPath) u.Debugf("removing any orphaned recovery system %s", transitionDir) err = utils.RemoveAll(u.cfg.Fs, transitionDir) if err != nil { @@ -167,8 +167,8 @@ func (u *UpgradeRecoveryAction) Run() (err error) { } // Switch places on /boot and transition-dir - bootDir := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.BootDir) - oldBootDir := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.OldBootDir) + bootDir := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.BootPath) + oldBootDir := filepath.Join(u.spec.Partitions.Recovery.MountPoint, constants.OldBootPath) // If a previous upgrade failed, remove old boot-dir err = utils.RemoveAll(u.cfg.Fs, oldBootDir) diff --git a/pkg/action/upgrade-recovery_test.go b/pkg/action/upgrade-recovery_test.go index a04aaab115d..d520f1fdff8 100644 --- a/pkg/action/upgrade-recovery_test.go +++ b/pkg/action/upgrade-recovery_test.go @@ -101,7 +101,7 @@ var _ = Describe("Upgrade Recovery Actions", func() { Name: "device1", FilesystemLabel: "COS_GRUB", Type: "vfat", - MountPoint: constants.EfiDir, + MountPoint: constants.BootDir, }, { Name: "device2", @@ -175,7 +175,7 @@ var _ = Describe("Upgrade Recovery Actions", func() { Expect(err).To(HaveOccurred()) }) It("Successfully upgrades recovery from docker image", Label("docker"), func() { - recoveryImgPath := filepath.Join(constants.LiveDir, constants.BootDir, constants.RecoveryImgFile) + recoveryImgPath := filepath.Join(constants.LiveDir, constants.BootPath, constants.RecoveryImgFile) spec := PrepareTestRecoveryImage(config, constants.LiveDir, fs, runner) // This should be the old image @@ -212,7 +212,7 @@ var _ = Describe("Upgrade Recovery Actions", func() { Expect(spec.State.Date).ToNot(BeEmpty(), "post-upgrade state should contain a date") }) It("Successfully skips updateInstallState", Label("docker"), func() { - recoveryImgPath := filepath.Join(constants.LiveDir, constants.BootDir, constants.RecoveryImgFile) + recoveryImgPath := filepath.Join(constants.LiveDir, constants.BootPath, constants.RecoveryImgFile) spec := PrepareTestRecoveryImage(config, constants.LiveDir, fs, runner) // This should be the old image diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index a41682bece9..96ff08ede94 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -121,7 +121,7 @@ func (u UpgradeAction) upgradeChrootHook(hook string, root string) error { efiDevice := u.spec.Partitions.Boot if efiDevice != nil && efiDevice.MountPoint != "" { - mountPoints[efiDevice.MountPoint] = constants.EfiDir + mountPoints[efiDevice.MountPoint] = constants.BootDir } return ChrootHook(&u.cfg.Config, hook, u.cfg.Strict, root, mountPoints, u.cfg.CloudInitPaths...) diff --git a/pkg/action/upgrade_test.go b/pkg/action/upgrade_test.go index 3d10fb21f30..86da2215666 100644 --- a/pkg/action/upgrade_test.go +++ b/pkg/action/upgrade_test.go @@ -103,7 +103,7 @@ var _ = Describe("Runtime Actions", func() { Name: "device1", FilesystemLabel: "COS_GRUB", Type: "vfat", - MountPoint: constants.EfiDir, + MountPoint: constants.BootDir, }, { Name: "device2", @@ -294,7 +294,7 @@ var _ = Describe("Runtime Actions", func() { Expect(runner.IncludesCmds([][]string{{"poweroff", "-f"}})).To(BeNil()) }) It("Successfully upgrades recovery from docker image", Label("docker"), func() { - recoveryImgPath := filepath.Join(constants.LiveDir, constants.BootDir, constants.RecoveryImgFile) + recoveryImgPath := filepath.Join(constants.LiveDir, constants.BootPath, constants.RecoveryImgFile) spec := PrepareTestRecoveryImage(config, constants.LiveDir, fs, runner) // This should be the old image diff --git a/pkg/bootloader/grub.go b/pkg/bootloader/grub.go index 1725026e3df..a788cbff065 100644 --- a/pkg/bootloader/grub.go +++ b/pkg/bootloader/grub.go @@ -423,7 +423,7 @@ func (g *Grub) Install(rootDir, bootDir string) (err error) { if g.secureBoot { image = g.shimImg } - err = g.DoEFIEntries(filepath.Base(image), constants.EfiDir) + err = g.DoEFIEntries(filepath.Base(image), constants.BootDir) if err != nil { return err } diff --git a/pkg/config/config.go b/pkg/config/config.go index 8d1dff6f5e2..4d510480c3e 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -195,7 +195,7 @@ func NewInstallSpec(cfg types.Config) *types.InstallSpec { recoverySystem.Source = system recoverySystem.FS = constants.SquashFs - recoverySystem.File = filepath.Join(constants.RecoveryDir, constants.BootDir, constants.RecoveryImgFile) + recoverySystem.File = filepath.Join(constants.RecoveryDir, constants.BootPath, constants.RecoveryImgFile) recoverySystem.MountPoint = constants.TransitionDir return &types.InstallSpec{ @@ -237,8 +237,8 @@ func NewMountSpec(cfg types.Config) *types.MountSpec { Device: fmt.Sprintf("PARTLABEL=%s", constants.OEMPartName), Options: []string{"rw", "defaults"}, }, { - Mountpoint: constants.EfiDir, - Device: fmt.Sprintf("PARTLABEL=%s", constants.EfiPartName), + Mountpoint: constants.BootDir, + Device: fmt.Sprintf("PARTLABEL=%s", constants.BootPartName), Options: []string{"ro", "defaults"}, }, }, @@ -263,11 +263,11 @@ func NewInstallElementalPartitions() types.ElementalPartitions { partitions := types.ElementalPartitions{} partitions.Boot = &types.Partition{ - FilesystemLabel: constants.EfiLabel, - Size: constants.EfiSize, - Name: constants.EfiPartName, - FS: constants.EfiFs, - MountPoint: constants.EfiDir, + FilesystemLabel: constants.BootLabel, + Size: constants.BootSize, + Name: constants.BootPartName, + FS: constants.BootFs, + MountPoint: constants.BootDir, Flags: []string{types.ESP}, } @@ -356,7 +356,7 @@ func NewUpgradeSpec(cfg types.Config) (*types.UpgradeSpec, error) { } recovery = types.Image{ - File: filepath.Join(ep.Recovery.MountPoint, constants.BootTransitionDir, constants.RecoveryImgFile), + File: filepath.Join(ep.Recovery.MountPoint, constants.BootTransitionPath, constants.RecoveryImgFile), Size: constants.ImgSize, Label: rState.Label, FS: rState.FS, @@ -373,7 +373,7 @@ func NewUpgradeSpec(cfg types.Config) (*types.UpgradeSpec, error) { if ep.Boot != nil { if ep.Boot.MountPoint == "" { - ep.Boot.MountPoint = constants.EfiDir + ep.Boot.MountPoint = constants.BootDir } } @@ -420,9 +420,9 @@ func NewResetSpec(cfg types.Config) (*types.ResetSpec, error) { return nil, fmt.Errorf("Bootloader partition not found") } if ep.Boot.MountPoint == "" { - ep.Boot.MountPoint = constants.EfiDir + ep.Boot.MountPoint = constants.BootDir } - ep.Boot.Name = constants.EfiPartName + ep.Boot.Name = constants.BootPartName } if ep.State == nil { @@ -462,7 +462,7 @@ func NewResetSpec(cfg types.Config) (*types.ResetSpec, error) { cfg.Logger.Warnf("no Persistent partition found") } - recoveryImg := filepath.Join(constants.RunningStateDir, constants.BootDir, constants.RecoveryImgFile) + recoveryImg := filepath.Join(constants.RunningStateDir, constants.BootPath, constants.RecoveryImgFile) oldRecoveryImg := filepath.Join(constants.RunningStateDir, constants.RecoveryImgFile) if exists, _ := utils.Exists(cfg.Fs, recoveryImg); exists { @@ -487,12 +487,12 @@ func NewDiskElementalPartitions(workdir string) types.ElementalPartitions { partitions := types.ElementalPartitions{} partitions.Boot = &types.Partition{ - FilesystemLabel: constants.EfiLabel, - Size: constants.EfiSize, - Name: constants.EfiPartName, - FS: constants.EfiFs, - MountPoint: constants.EfiDir, - Path: filepath.Join(workdir, constants.EfiPartName+partSuffix), + FilesystemLabel: constants.BootLabel, + Size: constants.BootSize, + Name: constants.BootPartName, + FS: constants.BootFs, + MountPoint: constants.BootDir, + Path: filepath.Join(workdir, constants.BootPartName+partSuffix), Flags: []string{types.ESP}, } @@ -545,7 +545,7 @@ func NewDisk(cfg *types.BuildConfig) *types.DiskSpec { workdir = filepath.Join(cfg.OutDir, constants.DiskWorkDir) recoveryImg.Size = constants.ImgSize - recoveryImg.File = filepath.Join(workdir, constants.RecoveryPartName, constants.BootDir, constants.RecoveryImgFile) + recoveryImg.File = filepath.Join(workdir, constants.RecoveryPartName, constants.BootPath, constants.RecoveryImgFile) recoveryImg.FS = constants.SquashFs recoveryImg.Source = types.NewEmptySrc() recoveryImg.MountPoint = filepath.Join( diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 76670b43cfa..636c56611aa 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -153,7 +153,7 @@ var _ = Describe("Types", Label("types", "config"), func() { Partitions: []*block.Partition{ { Name: "device1", - FilesystemLabel: constants.EfiLabel, + FilesystemLabel: constants.BootLabel, Type: "vfat", }, { @@ -209,7 +209,7 @@ var _ = Describe("Types", Label("types", "config"), func() { spec, err := config.NewResetSpec(*c) Expect(err).ShouldNot(HaveOccurred()) - Expect(spec.Partitions.Boot.MountPoint).To(Equal(constants.EfiDir)) + Expect(spec.Partitions.Boot.MountPoint).To(Equal(constants.BootDir)) }) It("sets reset defaults to recovery image", func() { // Set non-squashfs recovery image detection @@ -310,7 +310,7 @@ var _ = Describe("Types", Label("types", "config"), func() { Partitions: []*block.Partition{ { Name: "device1", - FilesystemLabel: constants.EfiLabel, + FilesystemLabel: constants.BootLabel, Type: "vfat", }, { diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index b5ab162644c..62248de9646 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -23,8 +23,8 @@ import ( const ( BiosPartName = "bios" - EfiLabel = "COS_GRUB" - EfiPartName = "efi" + BootLabel = "COS_GRUB" + BootPartName = "efi" SystemLabel = "COS_SYSTEM" RecoveryLabel = "COS_RECOVERY" RecoveryPartName = "recovery" @@ -40,11 +40,11 @@ const ( LinuxFs = "ext4" LinuxImgFs = "ext2" SquashFs = "squashfs" - EfiFs = "vfat" + BootFs = "vfat" Btrfs = "btrfs" BiosFs = "" MinPartSize = uint(64) - EfiSize = MinPartSize + BootSize = MinPartSize OEMSize = MinPartSize StateSize = uint(8192) RecoverySize = uint(4096) @@ -98,7 +98,7 @@ const ( OEMDir = "/run/elemental/oem" PersistentDir = "/run/elemental/persistent" TransitionDir = "/run/elemental/transition" - EfiDir = "/run/elemental/efi" + BootDir = "/run/elemental/efi" ImgSrcDir = "/run/elemental/imgsrc" WorkingImgDir = "/run/elemental/workingtree" OverlayDir = "/run/elemental/overlay" @@ -115,13 +115,13 @@ const ( LiveDir = "/run/initramfs/live" // Image constants - ActiveImgName = "active" - PassiveImgName = "passive" - RecoveryImgName = "recovery" - RecoveryImgFile = "recovery.img" - BootTransitionDir = "boot-transition" - BootDir = "boot" - OldBootDir = "boot-old" + ActiveImgName = "active" + PassiveImgName = "passive" + RecoveryImgName = "recovery" + RecoveryImgFile = "recovery.img" + BootTransitionPath = "boot-transition" + BootPath = "boot" + OldBootPath = "boot-old" // Yip stages evaluated on reset/upgrade/install/build-disk actions AfterInstallChrootHook = "after-install-chroot" diff --git a/pkg/elemental/elemental_test.go b/pkg/elemental/elemental_test.go index e42644c4d0c..d7f8f1cd6fe 100644 --- a/pkg/elemental/elemental_test.go +++ b/pkg/elemental/elemental_test.go @@ -963,7 +963,7 @@ var _ = Describe("Elemental", Label("elemental"), func() { Expect(fs.Mkdir("/recovery/boot", constants.DirPerm)).To(Succeed()) img := &types.Image{ - File: filepath.Join("/recovery", constants.BootDir, constants.RecoveryImgFile), + File: filepath.Join("/recovery", constants.BootPath, constants.RecoveryImgFile), Source: types.NewDockerSrc("elemental:latest"), FS: constants.SquashFs, } diff --git a/pkg/snapshotter/btrfs_test.go b/pkg/snapshotter/btrfs_test.go index 12eae5703d2..2e69416de0b 100644 --- a/pkg/snapshotter/btrfs_test.go +++ b/pkg/snapshotter/btrfs_test.go @@ -55,7 +55,7 @@ var _ = Describe("Btrfs", Label("snapshotter", " btrfs"), func() { Path: "/dev/state-device", MountPoint: rootDir, } - efiDir = constants.EfiDir + efiDir = constants.BootDir runner = mocks.NewFakeRunner() mounter = mocks.NewFakeMounter() syscall = &mocks.FakeSyscall{} diff --git a/pkg/snapshotter/loopdevice_test.go b/pkg/snapshotter/loopdevice_test.go index 7620958126b..f48367119eb 100644 --- a/pkg/snapshotter/loopdevice_test.go +++ b/pkg/snapshotter/loopdevice_test.go @@ -53,7 +53,7 @@ var _ = Describe("LoopDevice", Label("snapshotter", "loopdevice"), func() { Path: "/dev/state-device", MountPoint: rootDir, } - efiDir = constants.EfiDir + efiDir = constants.BootDir runner = mocks.NewFakeRunner() mounter = mocks.NewFakeMounter() syscall = &mocks.FakeSyscall{} diff --git a/pkg/types/config.go b/pkg/types/config.go index eeb7370d8a2..31619e2556f 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -114,8 +114,8 @@ func (c Config) LoadInstallState() (*InstallState, error) { } // Set default filesystem labels if missing, see rancher/elemental-toolkit#1827 - if installState.Partitions[constants.EfiPartName] != nil && installState.Partitions[constants.EfiPartName].FSLabel == "" { - installState.Partitions[constants.EfiPartName].FSLabel = constants.EfiLabel + if installState.Partitions[constants.BootPartName] != nil && installState.Partitions[constants.BootPartName].FSLabel == "" { + installState.Partitions[constants.BootPartName].FSLabel = constants.BootLabel } if installState.Partitions[constants.OEMPartName] != nil && installState.Partitions[constants.OEMPartName].FSLabel == "" { installState.Partitions[constants.OEMPartName].FSLabel = constants.OEMLabel @@ -552,7 +552,7 @@ func NewElementalPartitionsFromList(pl PartitionList, state *InstallState) Eleme ep := ElementalPartitions{} lm := map[string]string{ - constants.EfiPartName: constants.EfiLabel, + constants.BootPartName: constants.BootLabel, constants.OEMPartName: constants.OEMLabel, constants.RecoveryPartName: constants.RecoveryLabel, constants.StatePartName: constants.StateLabel, @@ -567,7 +567,7 @@ func NewElementalPartitionsFromList(pl PartitionList, state *InstallState) Eleme } ep.BIOS = pl.GetByName(constants.BiosPartName) - ep.Boot = pl.GetByNameOrLabel(constants.EfiPartName, lm[constants.EfiPartName]) + ep.Boot = pl.GetByNameOrLabel(constants.BootPartName, lm[constants.BootPartName]) ep.OEM = pl.GetByNameOrLabel(constants.OEMPartName, lm[constants.OEMPartName]) ep.Recovery = pl.GetByNameOrLabel(constants.RecoveryPartName, lm[constants.RecoveryPartName]) ep.State = pl.GetByNameOrLabel(constants.StatePartName, lm[constants.StatePartName])