1
0

feat: introduce kernel version

This commit is contained in:
dump_stack() 2023-05-14 22:00:29 +00:00
parent de5ebd6455
commit 1b2d636410
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
4 changed files with 16 additions and 5 deletions

View File

@ -276,6 +276,8 @@ type KernelInfo struct {
DistroRelease string // 18.04/7.4.1708/9.1 DistroRelease string // 18.04/7.4.1708/9.1
// Must be *exactly* same as in `uname -r` // Must be *exactly* same as in `uname -r`
KernelVersion string
KernelRelease string KernelRelease string
// Build-time information // Build-time information

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@ -228,10 +229,10 @@ func ContainerCommands(km config.KernelMask) (commands []string) {
} }
func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error) { func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error) {
path := config.Dir("volumes", d.Name) cpath := config.Dir("volumes", d.Name)
rootfs := config.File("images", d.Name+".img") rootfs := config.File("images", d.Name+".img")
files, err := os.ReadDir(path) files, err := os.ReadDir(cpath)
if err != nil { if err != nil {
return return
} }
@ -243,7 +244,7 @@ func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error)
pkgname := file.Name() pkgname := file.Name()
kpkgdir := filepath.Join(path, pkgname) kpkgdir := filepath.Join(cpath, pkgname)
bootdir := filepath.Join(kpkgdir, "boot") bootdir := filepath.Join(kpkgdir, "boot")
@ -269,10 +270,13 @@ func ContainerKernels(d container.Image, kcfg *config.KernelConfig) (err error)
log.Debug().Msgf("%s %s %s", vmlinuz, initrd, modules) log.Debug().Msgf("%s %s %s", vmlinuz, initrd, modules)
release := strings.Replace(pkgname, "linux-image-", "", -1)
ki := config.KernelInfo{ ki := config.KernelInfo{
DistroType: d.DistroType, DistroType: d.DistroType,
DistroRelease: d.DistroRelease, DistroRelease: d.DistroRelease,
KernelRelease: pkgname, KernelVersion: path.Base(modules),
KernelRelease: release,
ContainerName: d.Name, ContainerName: d.Name,
KernelPath: vmlinuz, KernelPath: vmlinuz,

View File

@ -603,6 +603,7 @@ func listContainersKernels(dii container.Image, newkcfg *config.KernelConfig,
ki := config.KernelInfo{ ki := config.KernelInfo{
DistroType: dii.DistroType, DistroType: dii.DistroType,
DistroRelease: dii.DistroRelease, DistroRelease: dii.DistroRelease,
KernelVersion: krel.Name(),
KernelRelease: krel.Name(), KernelRelease: krel.Name(),
ContainerName: dii.Name, ContainerName: dii.Name,

6
pew.go
View File

@ -258,7 +258,11 @@ func build(flog zerolog.Logger, tmp string, ka config.Artifact,
outpath += ".ko" outpath += ".ko"
} }
kernel := "/lib/modules/" + ki.KernelRelease + "/build" if ki.KernelVersion == "" {
ki.KernelVersion = ki.KernelRelease
}
kernel := "/lib/modules/" + ki.KernelVersion + "/build"
if ki.KernelSource != "" { if ki.KernelSource != "" {
kernel = ki.KernelSource kernel = ki.KernelSource
} }