1
0

Handling discrepancies between /lib/modules and /boot

This commit is contained in:
dump_stack() 2023-04-07 10:27:59 +00:00
parent 8029ad2185
commit 4570e9adbe
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
2 changed files with 49 additions and 19 deletions

View File

@ -513,32 +513,34 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
return
}
func genKernelPath(files []os.FileInfo, kname string) string {
func findKernelFile(files []os.FileInfo, kname string) (name string, err error) {
for _, file := range files {
if strings.HasPrefix(file.Name(), "vmlinuz") {
if strings.Contains(file.Name(), kname) {
return file.Name()
name = file.Name()
return
}
}
}
log.Fatal().Msgf("cannot find kernel %s", kname)
return ""
err = errors.New("cannot find kernel")
return
}
func genInitrdPath(files []os.FileInfo, kname string) string {
func findInitrdFile(files []os.FileInfo, kname string) (name string, err error) {
for _, file := range files {
if strings.HasPrefix(file.Name(), "initrd") ||
strings.HasPrefix(file.Name(), "initramfs") {
if strings.Contains(file.Name(), kname) {
return file.Name()
name = file.Name()
return
}
}
}
log.Fatal().Msgf("cannot find initrd %s", kname)
return ""
err = errors.New("cannot find kernel")
return
}
func genRootfsImage(d containerImageInfo, download bool) (rootfs string, err error) {
@ -640,16 +642,29 @@ func listContainersKernels(dii containerImageInfo, newkcfg *config.KernelConfig,
}
for _, krel := range moddirs {
log.Debug().Msgf("generate config entry for %s", krel.Name())
var kernelFile, initrdFile string
kernelFile, err = findKernelFile(bootfiles, krel.Name())
if err != nil {
log.Warn().Msgf("cannot find kernel %s", krel.Name())
continue
}
initrdFile, err = findInitrdFile(bootfiles, krel.Name())
if err != nil {
log.Warn().Msgf("cannot find initrd %s", krel.Name())
continue
}
ki := config.KernelInfo{
DistroType: dii.DistroType,
DistroRelease: dii.DistroRelease,
KernelRelease: krel.Name(),
ContainerName: dii.Name,
KernelPath: c.Volumes.Boot + "/" +
genKernelPath(bootfiles, krel.Name()),
InitrdPath: c.Volumes.Boot + "/" +
genInitrdPath(bootfiles, krel.Name()),
KernelPath: c.Volumes.Boot + "/" + kernelFile,
InitrdPath: c.Volumes.Boot + "/" + initrdFile,
ModulesPath: c.Volumes.LibModules + "/" + krel.Name(),
RootFS: rootfs,

View File

@ -37,7 +37,7 @@ func genHostKernels(download bool) (kcfg config.KernelConfig, err error) {
}
kernelsBase := "/boot/"
files, err := ioutil.ReadDir(kernelsBase)
bootfiles, err := ioutil.ReadDir(kernelsBase)
if err != nil {
return
}
@ -55,20 +55,35 @@ func genHostKernels(download bool) (kcfg config.KernelConfig, err error) {
return
}
for _, k := range strings.Fields(string(rawOutput)) {
for _, krel := range strings.Fields(string(rawOutput)) {
log.Debug().Msgf("generate config entry for %s", krel)
var kernelFile, initrdFile string
kernelFile, err = findKernelFile(bootfiles, krel)
if err != nil {
log.Warn().Msgf("cannot find kernel %s", krel)
continue
}
initrdFile, err = findInitrdFile(bootfiles, krel)
if err != nil {
log.Warn().Msgf("cannot find initrd %s", krel)
continue
}
ki := config.KernelInfo{
DistroType: distroType,
DistroRelease: si.OS.Version,
KernelRelease: k,
KernelRelease: krel,
KernelSource: "/lib/modules/" + k + "/build",
KernelSource: "/lib/modules/" + krel + "/build",
KernelPath: kernelsBase + genKernelPath(files, k),
InitrdPath: kernelsBase + genInitrdPath(files, k),
KernelPath: kernelsBase + kernelFile,
InitrdPath: kernelsBase + initrdFile,
RootFS: rootfs,
}
vmlinux := "/usr/lib/debug/boot/vmlinux-" + k
vmlinux := "/usr/lib/debug/boot/vmlinux-" + krel
log.Print("vmlinux", vmlinux)
if exists(vmlinux) {
ki.VmlinuxPath = vmlinux