Skip to content

Commit

Permalink
Make EFI partition size configurable at install time (#2105)
Browse files Browse the repository at this point in the history
* Make EFI partition size configurable at install time
* Add a custom EFI size test
* Rename efi to bootloader partition in config.yaml
* Rename EFI variable to Boot
* Rename constants

Signed-off-by: David Cassany <dcassany@suse.com>
  • Loading branch information
davidcassany authored Jun 19, 2024
1 parent 5e49bb9 commit 15a10cc
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 123 deletions.
1 change: 1 addition & 0 deletions cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ var _ = Describe("Config", Label("config"), func() {

spec, err := ReadInstallSpec(cfg, flags)
Expect(err).ShouldNot(HaveOccurred())
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")
Expand Down
3 changes: 3 additions & 0 deletions cmd/config/fixtures/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ cloud-init-paths:
- "some/alternate/path"

install:
partitions:
bootloader:
size: 512
target: "someDisk"

no-format: true
Expand Down
2 changes: 1 addition & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ install:
# size: 300

# default partitions
# only 'oem', 'recovery', 'state' and 'persistent' objects allowed
# only 'bootloader', 'oem', 'recovery', 'state' and 'persistent' objects allowed
# size in MiB
partitions:
oem:
Expand Down
24 changes: 12 additions & 12 deletions pkg/action/build-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -205,15 +205,15 @@ 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())
return err
}

// 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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -453,20 +453,20 @@ 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())
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
}
Expand Down Expand Up @@ -741,9 +741,9 @@ func (b *BuildDiskAction) createBuildDiskStateYaml(stateRoot, recoveryRoot strin
FSLabel: b.spec.Partitions.Persistent.FilesystemLabel,
}
}
if b.spec.Partitions.EFI != nil {
installState.Partitions[constants.EfiPartName] = &types.PartitionState{
FSLabel: b.spec.Partitions.EFI.FilesystemLabel,
if b.spec.Partitions.Boot != nil {
installState.Partitions[constants.BootPartName] = &types.PartitionState{
FSLabel: b.spec.Partitions.Boot.FilesystemLabel,
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/action/build-iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions pkg/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ 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
extraMounts[efi.MountPoint] = cnst.BootDir
}
return ChrootHook(&i.cfg.Config, hook, i.cfg.Strict, root, extraMounts, i.cfg.CloudInitPaths...)
}
Expand Down Expand Up @@ -147,9 +147,9 @@ func (i *InstallAction) createInstallStateYaml() error {
FSLabel: i.spec.Partitions.Persistent.FilesystemLabel,
}
}
if i.spec.Partitions.EFI != nil {
installState.Partitions[cnst.EfiPartName] = &types.PartitionState{
FSLabel: i.spec.Partitions.EFI.FilesystemLabel,
if i.spec.Partitions.Boot != nil {
installState.Partitions[cnst.BootPartName] = &types.PartitionState{
FSLabel: i.spec.Partitions.Boot.FilesystemLabel,
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/action/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ 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
extraMounts[efi.MountPoint] = constants.BootDir
}
return ChrootHook(&r.cfg.Config, hook, r.cfg.Strict, root, extraMounts, r.cfg.CloudInitPaths...)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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,
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/action/upgrade-recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/action/upgrade-recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ 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
mountPoints[efiDevice.MountPoint] = constants.BootDir
}

return ChrootHook(&u.cfg.Config, hook, u.cfg.Strict, root, mountPoints, u.cfg.CloudInitPaths...)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -374,15 +374,15 @@ 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 {
u.Error("Error setting GRUB labels: %s", err)
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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/action/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var _ = Describe("Runtime Actions", func() {
Name: "device1",
FilesystemLabel: "COS_GRUB",
Type: "vfat",
MountPoint: constants.EfiDir,
MountPoint: constants.BootDir,
},
{
Name: "device2",
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/bootloader/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 15a10cc

Please sign in to comment.