From 4caffd383c8509bd14bdcff028f09d418c2c250a Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 15 Dec 2023 19:03:08 +0400 Subject: [PATCH] fix: use correct prefix when installing SBC files When creating an image under non-default mount prefix, it should be used explicitly when copying SBC files. See https://github.com/siderolabs/image-factory/issues/65 Signed-off-by: Andrey Smirnov (cherry picked from commit 760f793d55f3965792f58fa3194977aea4f90e03) --- cmd/installer/pkg/install/install.go | 1 + internal/app/machined/pkg/runtime/board.go | 1 + .../pkg/runtime/v1alpha1/board/bananapi_m64/bananapi_m64.go | 2 +- .../pkg/runtime/v1alpha1/board/jetson_nano/jetson_nano.go | 2 +- .../board/libretech_all_h3_cc_h5/libretech_all_h3_cc_h5.go | 2 +- .../pkg/runtime/v1alpha1/board/nanopi_r4s/nanopi_r4s.go | 2 +- .../machined/pkg/runtime/v1alpha1/board/pine64/pine64.go | 2 +- .../machined/pkg/runtime/v1alpha1/board/rock64/rock64.go | 2 +- .../machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go | 2 +- .../pkg/runtime/v1alpha1/board/rockpi4c/rockpi4c.go | 2 +- .../pkg/runtime/v1alpha1/board/rpi_generic/rpi_generic.go | 6 +++--- 11 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cmd/installer/pkg/install/install.go b/cmd/installer/pkg/install/install.go index c949ce1a1d..1615ddfa71 100644 --- a/cmd/installer/pkg/install/install.go +++ b/cmd/installer/pkg/install/install.go @@ -290,6 +290,7 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) { if err = b.Install(runtime.BoardInstallOptions{ InstallDisk: i.options.Disk, + MountPrefix: i.options.MountPrefix, UBootPath: i.options.BootAssets.UBootPath, DTBPath: i.options.BootAssets.DTBPath, RPiFirmwarePath: i.options.BootAssets.RPiFirmwarePath, diff --git a/internal/app/machined/pkg/runtime/board.go b/internal/app/machined/pkg/runtime/board.go index b40c82e4a2..0c957af400 100644 --- a/internal/app/machined/pkg/runtime/board.go +++ b/internal/app/machined/pkg/runtime/board.go @@ -15,6 +15,7 @@ type PartitionOptions struct { // BoardInstallOptions are the board specific options for installation of various boot assets. type BoardInstallOptions struct { InstallDisk string + MountPrefix string DTBPath string UBootPath string RPiFirmwarePath string diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/bananapi_m64/bananapi_m64.go b/internal/app/machined/pkg/runtime/v1alpha1/board/bananapi_m64/bananapi_m64.go index a10f5260b7..dabc111abb 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/bananapi_m64/bananapi_m64.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/bananapi_m64/bananapi_m64.go @@ -73,7 +73,7 @@ func (b *BananaPiM64) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/jetson_nano/jetson_nano.go b/internal/app/machined/pkg/runtime/v1alpha1/board/jetson_nano/jetson_nano.go index 2b3585a602..af0c756b98 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/jetson_nano/jetson_nano.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/jetson_nano/jetson_nano.go @@ -53,7 +53,7 @@ func (b JetsonNano) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/libretech_all_h3_cc_h5/libretech_all_h3_cc_h5.go b/internal/app/machined/pkg/runtime/v1alpha1/board/libretech_all_h3_cc_h5/libretech_all_h3_cc_h5.go index 70c1ab225e..fb0f1a4a22 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/libretech_all_h3_cc_h5/libretech_all_h3_cc_h5.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/libretech_all_h3_cc_h5/libretech_all_h3_cc_h5.go @@ -70,7 +70,7 @@ func (l *LibretechAllH3CCH5) Install(options runtime.BoardInstallOptions) (err e } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/nanopi_r4s/nanopi_r4s.go b/internal/app/machined/pkg/runtime/v1alpha1/board/nanopi_r4s/nanopi_r4s.go index 06d2fb87bf..4d4e9ad7e7 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/nanopi_r4s/nanopi_r4s.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/nanopi_r4s/nanopi_r4s.go @@ -64,7 +64,7 @@ func (n *NanoPiR4S) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) if err := os.MkdirAll(filepath.Dir(dst), 0o600); err != nil { return err diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/pine64/pine64.go b/internal/app/machined/pkg/runtime/v1alpha1/board/pine64/pine64.go index 4f680a9b3b..234bfe26c4 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/pine64/pine64.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/pine64/pine64.go @@ -71,7 +71,7 @@ func (b Pine64) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/rock64/rock64.go b/internal/app/machined/pkg/runtime/v1alpha1/board/rock64/rock64.go index 578f052770..b87acef188 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/rock64/rock64.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/rock64/rock64.go @@ -70,7 +70,7 @@ func (r *Rock64) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go b/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go index 47e374c2cc..de9b0a32c7 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4/rockpi4.go @@ -70,7 +70,7 @@ func (r *Rockpi4) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4c/rockpi4c.go b/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4c/rockpi4c.go index 7ade79e6fa..8813a8e2f1 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4c/rockpi4c.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/rockpi4c/rockpi4c.go @@ -69,7 +69,7 @@ func (r *Rockpi4c) Install(options runtime.BoardInstallOptions) (err error) { } src := filepath.Join(options.DTBPath, dtb) - dst := filepath.Join("/boot/EFI/dtb", dtb) + dst := filepath.Join(options.MountPrefix, "/boot/EFI/dtb", dtb) err = os.MkdirAll(filepath.Dir(dst), 0o600) if err != nil { diff --git a/internal/app/machined/pkg/runtime/v1alpha1/board/rpi_generic/rpi_generic.go b/internal/app/machined/pkg/runtime/v1alpha1/board/rpi_generic/rpi_generic.go index 4fba673649..a7ade887f3 100644 --- a/internal/app/machined/pkg/runtime/v1alpha1/board/rpi_generic/rpi_generic.go +++ b/internal/app/machined/pkg/runtime/v1alpha1/board/rpi_generic/rpi_generic.go @@ -32,17 +32,17 @@ func (r *RPiGeneric) Name() string { // Install implements the runtime.Board. func (r *RPiGeneric) Install(options runtime.BoardInstallOptions) (err error) { - err = copy.Dir(filepath.Join(options.RPiFirmwarePath, "boot"), "/boot/EFI") + err = copy.Dir(filepath.Join(options.RPiFirmwarePath, "boot"), filepath.Join(options.MountPrefix, "/boot/EFI")) if err != nil { return err } - err = copy.File(filepath.Join(options.UBootPath, "rpi_generic/u-boot.bin"), "/boot/EFI/u-boot.bin") + err = copy.File(filepath.Join(options.UBootPath, "rpi_generic/u-boot.bin"), filepath.Join(options.MountPrefix, "/boot/EFI/u-boot.bin")) if err != nil { return err } - return os.WriteFile("/boot/EFI/config.txt", configTxt, 0o600) + return os.WriteFile(filepath.Join(options.MountPrefix, "/boot/EFI/config.txt"), configTxt, 0o600) } // KernelArgs implements the runtime.Board.