Skip to content

Commit

Permalink
fix: use a mount prefix when installing a bootloader
Browse files Browse the repository at this point in the history
This is not a problem in general, but when running multiple image
generation procedures using the same mount point is a problem.

This is a no-op if `MountPrefix` is not set (when installing/upgrading
vs. creating an image).

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed Aug 31, 2023
1 parent 44f59a8 commit b8fb55d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
18 changes: 10 additions & 8 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Options struct {
Version string
BootAssets bootloaderoptions.BootAssets
Printf func(string, ...any)
MountPrefix string
}

// Mode is the install mode.
Expand Down Expand Up @@ -234,7 +235,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {

var mountpoint *mount.Point

mountpoint, err = mount.SystemMountPointForLabel(ctx, bd, label)
mountpoint, err = mount.SystemMountPointForLabel(ctx, bd, label, mount.WithPrefix(i.options.MountPrefix))
if err != nil {
return err
}
Expand Down Expand Up @@ -262,13 +263,14 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {

// Install the bootloader.
if err = i.bootloader.Install(bootloaderoptions.InstallOptions{
BootDisk: i.options.Disk,
Arch: i.options.Arch,
Cmdline: i.cmdline.String(),
Version: i.options.Version,
ImageMode: mode.IsImage(),
BootAssets: i.options.BootAssets,
Printf: i.options.Printf,
BootDisk: i.options.Disk,
Arch: i.options.Arch,
Cmdline: i.cmdline.String(),
Version: i.options.Version,
ImageMode: mode.IsImage(),
MountPrefix: i.options.MountPrefix,
BootAssets: i.options.BootAssets,
Printf: i.options.Printf,
}); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ func (c *Config) Install(options options.InstallOptions) error {

if err := utils.CopyFiles(
options.Printf,
utils.SourceDestination(options.BootAssets.KernelPath, filepath.Join(constants.BootMountPoint, string(c.Default), constants.KernelAsset)),
utils.SourceDestination(options.BootAssets.InitramfsPath, filepath.Join(constants.BootMountPoint, string(c.Default), constants.InitramfsAsset)),
utils.SourceDestination(
options.BootAssets.KernelPath,
filepath.Join(options.MountPrefix, constants.BootMountPoint, string(c.Default), constants.KernelAsset),
),
utils.SourceDestination(
options.BootAssets.InitramfsPath,
filepath.Join(options.MountPrefix, constants.BootMountPoint, string(c.Default), constants.InitramfsAsset),
),
); err != nil {
return err
}
Expand All @@ -45,7 +51,7 @@ func (c *Config) Install(options options.InstallOptions) error {
return err
}

if err := c.Write(ConfigPath, options.Printf); err != nil {
if err := c.Write(filepath.Join(options.MountPrefix, ConfigPath), options.Printf); err != nil {
return err
}

Expand All @@ -69,8 +75,11 @@ func (c *Config) Install(options options.InstallOptions) error {
}

for _, platform := range platforms {
args := []string{"--boot-directory=" + constants.BootMountPoint, "--efi-directory=" +
constants.EFIMountPoint, "--removable"}
args := []string{
"--boot-directory=" + filepath.Join(options.MountPrefix, constants.BootMountPoint),
"--efi-directory=" + filepath.Join(options.MountPrefix, constants.EFIMountPoint),
"--removable",
}

if options.ImageMode {
args = append(args, "--no-nvram")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type InstallOptions struct {
// Are we running in image mode?
ImageMode bool

// Mount prefix for /boot-like partitions.
MountPrefix string

// Boot assets to install.
BootAssets BootAssets

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *Config) Install(options options.InstallOptions) error {
}

// list existing UKIs, and clean up all but the current one (used to boot)
files, err := filepath.Glob(filepath.Join(constants.EFIMountPoint, "EFI", "Linux", "Talos-*.efi"))
files, err := filepath.Glob(filepath.Join(options.MountPrefix, constants.EFIMountPoint, "EFI", "Linux", "Talos-*.efi"))
if err != nil {
return err
}
Expand Down Expand Up @@ -169,8 +169,14 @@ func (c *Config) Install(options options.InstallOptions) error {

if err := utils.CopyFiles(
options.Printf,
utils.SourceDestination(options.BootAssets.UKIPath, filepath.Join(constants.EFIMountPoint, "EFI", "Linux", ukiPath)),
utils.SourceDestination(options.BootAssets.SDBootPath, filepath.Join(constants.EFIMountPoint, "EFI", "boot", sdbootFilename)),
utils.SourceDestination(
options.BootAssets.UKIPath,
filepath.Join(options.MountPrefix, constants.EFIMountPoint, "EFI", "Linux", ukiPath),
),
utils.SourceDestination(
options.BootAssets.SDBootPath,
filepath.Join(options.MountPrefix, constants.EFIMountPoint, "EFI", "boot", sdbootFilename),
),
); err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/imager/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (i *Imager) buildImage(ctx context.Context, path string, printf func(string

cmdline := procfs.NewCmdline(i.cmdline)

scratchSpace := filepath.Join(i.tempDir, "image")

opts := &install.Options{
Disk: loDevice,
Platform: i.prof.Platform,
Expand All @@ -190,7 +192,8 @@ func (i *Imager) buildImage(ctx context.Context, path string, printf func(string
UKIPath: i.ukiPath,
SDBootPath: i.sdBootPath,
},
Printf: printf,
MountPrefix: scratchSpace,
Printf: printf,
}

if opts.Board == "" {
Expand Down

0 comments on commit b8fb55d

Please sign in to comment.