Merge pull request #164 from gmkurtzer/kernel_find
Better logic to locate kernels
This commit is contained in:
@@ -16,6 +16,16 @@ import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
var (
|
||||
kernelSearchPaths = []string{
|
||||
// This is a printf format where the %s will be the kernel version
|
||||
"/boot/vmlinuz-%s",
|
||||
"/boot/vmlinuz-%s.gz",
|
||||
"/lib/mmodules/%s/vmlinuz",
|
||||
"/lib/mmodules/%s/vmlinuz.gz",
|
||||
}
|
||||
)
|
||||
|
||||
func ParentDir() string {
|
||||
return path.Join(config.LocalStateDir, "provision/kernel")
|
||||
}
|
||||
@@ -100,12 +110,12 @@ func ListKernels() ([]string, error) {
|
||||
}
|
||||
|
||||
func Build(kernelVersion string, kernelName string, root string) (string, error) {
|
||||
kernelImage := path.Join(root, "/boot/vmlinuz-"+kernelVersion)
|
||||
kernelDrivers := path.Join(root, "/lib/modules/"+kernelVersion)
|
||||
kernelDriversRelative := path.Join("/lib/modules/"+kernelVersion)
|
||||
kernelDestination := KernelImage(kernelName)
|
||||
driversDestination := KmodsImage(kernelName)
|
||||
versionDestination := KernelVersion(kernelName)
|
||||
var kernelSource string
|
||||
|
||||
// Create the destination paths just in case it doesn't exist
|
||||
err := os.MkdirAll(path.Dir(kernelDestination), 0755)
|
||||
@@ -123,21 +133,29 @@ func Build(kernelVersion string, kernelName string, root string) (string, error)
|
||||
return "", fmt.Errorf("failed to create version dest: %s", err)
|
||||
}
|
||||
|
||||
if !util.IsFile(kernelImage) {
|
||||
if !util.IsFile(kernelImage + ".gz") {
|
||||
return "", errors.New("Could not locate kernel image")
|
||||
} else {
|
||||
kernelImage = kernelImage + ".gz"
|
||||
for _, path := range kernelSearchPaths {
|
||||
testPath := fmt.Sprintf(path, kernelVersion)
|
||||
wwlog.Printf(wwlog.VERBOSE, "Looking for kernel at: %s\n", testPath)
|
||||
if util.IsFile(testPath) {
|
||||
kernelSource = testPath
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if kernelSource == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not locate kernel image\n")
|
||||
return "", errors.New("could not locate kernel image")
|
||||
} else {
|
||||
wwlog.Printf(wwlog.INFO, "Found kernel at: %s\n", kernelSource)
|
||||
}
|
||||
|
||||
if !util.IsDir(kernelDrivers) {
|
||||
return "", errors.New("Could not locate kernel drivers")
|
||||
}
|
||||
|
||||
wwlog.Printf(wwlog.VERBOSE, "Setting up Kernel\n")
|
||||
if _, err := os.Stat(kernelImage); err == nil {
|
||||
kernel, err := os.Open(kernelImage)
|
||||
if _, err := os.Stat(kernelSource); err == nil {
|
||||
kernel, err := os.Open(kernelSource)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not open kernel")
|
||||
}
|
||||
@@ -160,7 +178,7 @@ func Build(kernelVersion string, kernelName string, root string) (string, error)
|
||||
|
||||
} else {
|
||||
|
||||
err := util.CopyFile(kernelImage, kernelDestination)
|
||||
err := util.CopyFile(kernelSource, kernelDestination)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not copy kernel")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user