mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 01:06:27 +00:00
Merge pull request #116 from justincormack/kernel-options
Allow specifying the kernel and tarball names, or omitting tarball
This commit is contained in:
commit
a824287800
@ -44,6 +44,9 @@ which should contain a `kernel` file that will be booted (eg a `bzImage` for `am
|
||||
called `kernel.tar` which is a tarball that is unpacked into the root, which should usually
|
||||
contain a kernel modules directory. `cmdline` specifies the kernel command line options if required.
|
||||
|
||||
To override the names, you can specify the kernel image name with `binary: bzImage` and the tar image
|
||||
with `tar: kernel.tar` or the empty string or `none` if you do not want to use a tarball at all.
|
||||
|
||||
## `init`
|
||||
|
||||
The `init` section is a list of images that are used for the `init` system and are unpacked directly
|
||||
|
@ -140,7 +140,7 @@ func Build(m Moby, w io.Writer, pull bool, tp string) error {
|
||||
if m.Kernel.Image != "" {
|
||||
// get kernel and initrd tarball from container
|
||||
log.Infof("Extract kernel image: %s", m.Kernel.Image)
|
||||
kf := newKernelFilter(iw, m.Kernel.Cmdline)
|
||||
kf := newKernelFilter(iw, m.Kernel.Cmdline, m.Kernel.Binary, m.Kernel.Tar)
|
||||
err := ImageTar(m.Kernel.Image, "", kf, enforceContentTrust(m.Kernel.Image, &m.Trust), pull)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to extract kernel image and tarball: %v", err)
|
||||
@ -225,13 +225,25 @@ type kernelFilter struct {
|
||||
tw *tar.Writer
|
||||
buffer *bytes.Buffer
|
||||
cmdline string
|
||||
kernel string
|
||||
tar string
|
||||
discard bool
|
||||
foundKernel bool
|
||||
foundKTar bool
|
||||
}
|
||||
|
||||
func newKernelFilter(tw *tar.Writer, cmdline string) *kernelFilter {
|
||||
return &kernelFilter{tw: tw, cmdline: cmdline}
|
||||
func newKernelFilter(tw *tar.Writer, cmdline string, kernel string, tar *string) *kernelFilter {
|
||||
tarName, kernelName := "kernel.tar", "kernel"
|
||||
if tar != nil {
|
||||
tarName = *tar
|
||||
if tarName == "none" {
|
||||
tarName = ""
|
||||
}
|
||||
}
|
||||
if kernel != "" {
|
||||
kernelName = kernel
|
||||
}
|
||||
return &kernelFilter{tw: tw, cmdline: cmdline, kernel: kernelName, tar: tarName}
|
||||
}
|
||||
|
||||
func (k *kernelFilter) finishTar() error {
|
||||
@ -248,8 +260,8 @@ func (k *kernelFilter) Close() error {
|
||||
if !k.foundKernel {
|
||||
return errors.New("did not find kernel in kernel image")
|
||||
}
|
||||
if !k.foundKTar {
|
||||
return errors.New("did not find kernel.tar in kernel image")
|
||||
if !k.foundKTar && k.tar != "" {
|
||||
return errors.New("did not find kernel tar in kernel image")
|
||||
}
|
||||
return k.finishTar()
|
||||
}
|
||||
@ -279,7 +291,7 @@ func (k *kernelFilter) WriteHeader(hdr *tar.Header) error {
|
||||
}
|
||||
tw := k.tw
|
||||
switch hdr.Name {
|
||||
case "kernel":
|
||||
case k.kernel:
|
||||
if k.foundKernel {
|
||||
return errors.New("found more than one possible kernel image")
|
||||
}
|
||||
@ -315,7 +327,7 @@ func (k *kernelFilter) WriteHeader(hdr *tar.Header) error {
|
||||
if err := tw.WriteHeader(whdr); err != nil {
|
||||
return err
|
||||
}
|
||||
case "kernel.tar":
|
||||
case k.tar:
|
||||
k.foundKTar = true
|
||||
k.discard = false
|
||||
k.buffer = new(bytes.Buffer)
|
||||
|
@ -19,10 +19,7 @@ import (
|
||||
|
||||
// Moby is the type of a Moby config file
|
||||
type Moby struct {
|
||||
Kernel struct {
|
||||
Image string
|
||||
Cmdline string
|
||||
}
|
||||
Kernel KernelConfig
|
||||
Init []string
|
||||
Onboot []Image
|
||||
Services []Image
|
||||
@ -30,6 +27,14 @@ type Moby struct {
|
||||
Files []File
|
||||
}
|
||||
|
||||
// KernelConfig is the type of the config for a kernel
|
||||
type KernelConfig struct {
|
||||
Image string
|
||||
Cmdline string
|
||||
Binary string
|
||||
Tar *string
|
||||
}
|
||||
|
||||
// TrustConfig is the type of a content trust config
|
||||
type TrustConfig struct {
|
||||
Image []string
|
||||
@ -168,6 +173,12 @@ func AppendConfig(m0, m1 Moby) (Moby, error) {
|
||||
if m1.Kernel.Cmdline != "" {
|
||||
moby.Kernel.Cmdline = m1.Kernel.Cmdline
|
||||
}
|
||||
if m1.Kernel.Binary != "" {
|
||||
moby.Kernel.Binary = m1.Kernel.Binary
|
||||
}
|
||||
if m1.Kernel.Tar != nil {
|
||||
moby.Kernel.Tar = m1.Kernel.Tar
|
||||
}
|
||||
moby.Init = append(moby.Init, m1.Init...)
|
||||
moby.Onboot = append(moby.Onboot, m1.Onboot...)
|
||||
moby.Services = append(moby.Services, m1.Services...)
|
||||
|
@ -11,7 +11,9 @@ var schema = string(`
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"image": {"type": "string"},
|
||||
"cmdline": { "type": "string"}
|
||||
"cmdline": {"type": "string"},
|
||||
"binary": {"type": "string"},
|
||||
"tar": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"file": {
|
||||
|
Loading…
Reference in New Issue
Block a user