fixed ShimFind for aarch64
Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
committed by
Jonathon Anderson
parent
16f5b7408e
commit
b192e3b5d5
@@ -1,27 +1,16 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/warewulf/warewulf/internal/pkg/kernel"
|
||||
"github.com/warewulf/warewulf/internal/pkg/wwlog"
|
||||
)
|
||||
|
||||
var (
|
||||
kernelNames = []string{
|
||||
`vmlinux`,
|
||||
`vmlinuz`,
|
||||
`vmlinux-*`,
|
||||
`vmlinuz-*`,
|
||||
`vmlinuz.gz`}
|
||||
|
||||
kernelDirs = []string{
|
||||
`/lib/modules/*/`,
|
||||
`/boot/`}
|
||||
)
|
||||
|
||||
func KernelFind(container string) string {
|
||||
wwlog.Debug("Finding kernel")
|
||||
container_path := RootFsDir(container)
|
||||
@@ -29,32 +18,31 @@ func KernelFind(container string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
for _, kdir := range kernelDirs {
|
||||
wwlog.Debug("Checking kernel directory: %s", kdir)
|
||||
for _, kname := range kernelNames {
|
||||
wwlog.Debug("Checking for kernel name: %s", kname)
|
||||
kernelPaths, err := filepath.Glob(path.Join(container_path, kdir, kname))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
for _, searchPath := range kernel.KernelSearchPaths {
|
||||
testPath := fmt.Sprintf(path.Join(container_path, searchPath), "*")
|
||||
wwlog.Debug("Checking for kernel name: %s", testPath)
|
||||
|
||||
if len(kernelPaths) == 0 {
|
||||
continue
|
||||
}
|
||||
kernelPaths, err := filepath.Glob(testPath)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
sort.Slice(kernelPaths, func(i, j int) bool {
|
||||
return kernelPaths[i] > kernelPaths[j]
|
||||
})
|
||||
if len(kernelPaths) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, kernelPath := range kernelPaths {
|
||||
wwlog.Debug("Checking for kernel path: %s", kernelPath)
|
||||
// Only succeeds if kernelPath exists and, if a
|
||||
// symlink, links to a path that also exists
|
||||
kernelPath, err = filepath.EvalSymlinks(kernelPath)
|
||||
if err == nil {
|
||||
wwlog.Debug("found kernel: %s", kernelPath)
|
||||
return kernelPath
|
||||
}
|
||||
sort.Slice(kernelPaths, func(i, j int) bool {
|
||||
return kernelPaths[i] > kernelPaths[j]
|
||||
})
|
||||
|
||||
for _, kernelPath := range kernelPaths {
|
||||
wwlog.Debug("Checking for kernel path: %s", kernelPath)
|
||||
// Only succeeds if kernelPath exists and, if a
|
||||
// symlink, links to a path that also exists
|
||||
kernelPath, err = filepath.EvalSymlinks(kernelPath)
|
||||
if err == nil {
|
||||
wwlog.Debug("found kernel: %s", kernelPath)
|
||||
return kernelPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func shimDirs() []string {
|
||||
return []string{
|
||||
`/usr/share/efi/x86_64/`,
|
||||
`/usr/share/efi/*/`,
|
||||
`/usr/lib64/efi/`,
|
||||
`/boot/efi/EFI/*/`,
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
// warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
|
||||
"github.com/warewulf/warewulf/internal/pkg/testenv"
|
||||
@@ -17,10 +15,10 @@ func Test_Find_ShimX86(t *testing.T) {
|
||||
testenv.New(t)
|
||||
conf := warewulfconf.Get()
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/lib64/efi/"), 0755)
|
||||
_ = os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/lib64/efi/"), 0755)
|
||||
shimF, err := os.Create(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/lib64/efi/shim.efi"))
|
||||
assert.NoError(t, err)
|
||||
shimF.WriteString("shim.efi")
|
||||
_, _ = shimF.WriteString("shim.efi")
|
||||
assert.FileExists(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/lib64/efi/shim.efi"))
|
||||
shimPath := ShimFind("suse")
|
||||
assert.Equal(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/lib64/efi/shim.efi"), shimPath)
|
||||
@@ -29,10 +27,10 @@ func Test_Find_ShimArch64(t *testing.T) {
|
||||
testenv.New(t)
|
||||
conf := warewulfconf.Get()
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64"), 0755)
|
||||
_ = os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64"), 0755)
|
||||
shimF, err := os.Create(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/shim.efi"))
|
||||
assert.NoError(t, err)
|
||||
shimF.WriteString("shim.efi")
|
||||
_, _ = shimF.WriteString("shim.efi")
|
||||
assert.FileExists(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/shim.efi"))
|
||||
shimPath := ShimFind("suse")
|
||||
assert.Equal(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/shim.efi"), shimPath)
|
||||
@@ -41,10 +39,10 @@ func Test_Find_GrubX86(t *testing.T) {
|
||||
testenv.New(t)
|
||||
conf := warewulfconf.Get()
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/x86_64"), 0755)
|
||||
_ = os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/x86_64"), 0755)
|
||||
shimF, err := os.Create(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/x86_64/grub.efi"))
|
||||
assert.NoError(t, err)
|
||||
shimF.WriteString("grub.efi")
|
||||
_, _ = shimF.WriteString("grub.efi")
|
||||
assert.FileExists(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs//usr/share/efi/x86_64/grub.efi"))
|
||||
shimPath := GrubFind("suse")
|
||||
assert.Equal(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/x86_64/grub.efi"), shimPath)
|
||||
@@ -53,11 +51,11 @@ func Test_Find_GrubAarch64(t *testing.T) {
|
||||
testenv.New(t)
|
||||
conf := warewulfconf.Get()
|
||||
wwlog.SetLogLevel(wwlog.DEBUG)
|
||||
os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/"), 0755)
|
||||
_ = os.MkdirAll(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/"), 0755)
|
||||
shimF, err := os.Create(path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/grub.efi"))
|
||||
assert.NoError(t, err)
|
||||
shimF.WriteString("grub.efi")
|
||||
assert.FileExists(t, path.Join(conf.Paths.WWChrootdir, "suse/usr/share/efi/aarch64/grub.efi"))
|
||||
_, _ = shimF.WriteString("grub.efi")
|
||||
assert.FileExists(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/grub.efi"))
|
||||
shimPath := GrubFind("suse")
|
||||
assert.Equal(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64//grub.efi"), shimPath)
|
||||
assert.Equal(t, path.Join(conf.Paths.WWChrootdir, "suse/rootfs/usr/share/efi/aarch64/grub.efi"), shimPath)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
kernelSearchPaths = []string{
|
||||
KernelSearchPaths = []string{
|
||||
// This is a printf format where the %s will be the kernel version
|
||||
"/boot/Image-%s", // this is the aarch64 for SUSE, vmlinux which is also present won't boot
|
||||
"/boot/vmlinuz-linux%.s",
|
||||
"/boot/vmlinuz-%s",
|
||||
"/boot/vmlinuz-%s.gz",
|
||||
@@ -143,7 +144,7 @@ func Build(kernelVersion, kernelName, root string) error {
|
||||
return fmt.Errorf("failed to create version dest: %s", err)
|
||||
}
|
||||
|
||||
for _, searchPath := range kernelSearchPaths {
|
||||
for _, searchPath := range KernelSearchPaths {
|
||||
testPath := fmt.Sprintf(path.Join(root, searchPath), kernelVersion)
|
||||
wwlog.Verbose("Looking for kernel at: %s", testPath)
|
||||
if util.IsFile(testPath) {
|
||||
@@ -236,7 +237,7 @@ func DeleteKernel(name string) error {
|
||||
}
|
||||
|
||||
func FindKernelVersion(root string) (string, error) {
|
||||
for _, searchPath := range kernelSearchPaths {
|
||||
for _, searchPath := range KernelSearchPaths {
|
||||
testPattern := fmt.Sprintf(path.Join(root, searchPath), `*`)
|
||||
wwlog.Verbose("Looking for kernel version with pattern at: %s", testPattern)
|
||||
potentialKernel, _ := filepath.Glob(testPattern)
|
||||
|
||||
Reference in New Issue
Block a user