Skip to content

Commit

Permalink
fix: generate of modules.dep when on the machine
Browse files Browse the repository at this point in the history
When running on the machine, the extensionTreePath is not writeable, so
create and clean up a temporary directory to host `modules.dep`
extension.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Sep 20, 2023
1 parent 5efcccb commit 5ca4d58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/pkg/extensions/kernel_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (ext *Extension) KernelModuleDirectory() string {
// GenerateKernelModuleDependencyTreeExtension generates a kernel module dependency tree extension.
//
//nolint:gocyclo
func GenerateKernelModuleDependencyTreeExtension(extensionPathsWithKernelModules []string, initramfsPath, extensionTreePath string, printFunc func(format string, v ...any)) (*Extension, error) {
func GenerateKernelModuleDependencyTreeExtension(extensionPathsWithKernelModules []string, initramfsPath, scratchPath string, printFunc func(format string, v ...any)) (*Extension, error) {
printFunc("preparing to run depmod to generate kernel modules dependency tree")

tempDir, err := os.MkdirTemp("", "ext-modules")
Expand Down Expand Up @@ -106,7 +106,7 @@ func GenerateKernelModuleDependencyTreeExtension(extensionPathsWithKernelModules
}

// we want the extension to survive this function, so not storing in a temporary directory
kernelModulesDependencyTreeStagingDir := filepath.Join(extensionTreePath, "modules.dep")
kernelModulesDependencyTreeStagingDir := filepath.Join(scratchPath, "modules.dep")

// we want to make sure the root directory has the right permissions.
if err := os.MkdirAll(kernelModulesDependencyTreeStagingDir, 0o755); err != nil {
Expand Down
14 changes: 13 additions & 1 deletion pkg/imager/extensions/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Builder struct {
}

// Build rebuilds the initramfs.xz with extensions.
//
//nolint:gocyclo
func (builder *Builder) Build() error {
extensionsList, err := extensions.List(builder.ExtensionTreePath)
if err != nil {
Expand All @@ -49,7 +51,17 @@ func (builder *Builder) Build() error {
extensionPathsWithKernelModules := findExtensionsWithKernelModules(extensionsList)

if len(extensionPathsWithKernelModules) > 0 {
kernelModuleDepExtension, genErr := extensions.GenerateKernelModuleDependencyTreeExtension(extensionPathsWithKernelModules, builder.InitramfsPath, builder.ExtensionTreePath, builder.Printf)
var scratchPath string

// create a temporary directory to store 'modules.dep' extension
scratchPath, err = os.MkdirTemp("", "ext-modules")
if err != nil {
return err
}

defer os.RemoveAll(scratchPath) //nolint:errcheck

kernelModuleDepExtension, genErr := extensions.GenerateKernelModuleDependencyTreeExtension(extensionPathsWithKernelModules, builder.InitramfsPath, scratchPath, builder.Printf)
if genErr != nil {
return genErr
}
Expand Down

0 comments on commit 5ca4d58

Please sign in to comment.