diff --git a/internal/pkg/container/kernel.go b/internal/pkg/container/kernel.go index c3f94db0..c87d644b 100644 --- a/internal/pkg/container/kernel.go +++ b/internal/pkg/container/kernel.go @@ -1,9 +1,11 @@ package container import ( + "os" "path" "path/filepath" "sort" + "strings" "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" @@ -15,11 +17,11 @@ var ( `vmlinuz`, `vmlinux-*`, `vmlinuz-*`, - `vmlinuz.gz` } + `vmlinuz.gz`} kernelDirs = []string{ `/lib/modules/*/`, - `/boot/` } + `/boot/`} ) func KernelFind(container string) string { @@ -49,6 +51,16 @@ func KernelFind(container string) string { for _, kernelPath := range kernelPaths { wwlog.Debug("Checking for kernel path: %s", kernelPath) if util.IsFile(kernelPath) { + // IsFile does not check if file is a softlink + stat, _ := os.Lstat(kernelPath) + if stat.Mode()&os.ModeSymlink == os.ModeSymlink { + wwlog.Verbose("%s is a softlink", kernelPath) + kernelPath, err = filepath.EvalSymlinks(kernelPath) + if err != nil { + wwlog.Warn("could evaluate symlink %s: %s", kernelPath, err) + } + wwlog.Debug("softlink is %s", kernelPath) + } return kernelPath } } @@ -65,5 +77,10 @@ func KernelVersion(container string) string { return "" } - return path.Base(path.Dir(kernel)) + ret := path.Base(path.Dir(kernel)) + if ret == "boot" { + ret = path.Base(kernel) + } + + return strings.TrimPrefix(ret, "vmlinuz-") }