From 6f800f0cb13a67f909b0c6ab4c4eece776e0ad64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 22 Aug 2025 12:02:06 +0200 Subject: [PATCH] Add two fields for images exported from containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The original container image has some optional metadata in the ENTRYPOINT and STOPSIGNAL fields, that could be needed later... But these are not exported in the generic rootfs, by default. Make it possible to pass these at runtime, for instance to select between OpenRC and systemd - or SIGTERM and systemd. Some drivers include their config in the rootfs, like wsl.conf. Signed-off-by: Anders F Björklund --- pkg/instance/start.go | 14 ++++++++++++++ pkg/limatype/filenames/filenames.go | 2 ++ pkg/limatype/lima_yaml.go | 8 +++++--- website/content/en/docs/dev/internals.md | 4 ++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/instance/start.go b/pkg/instance/start.go index 3114ec1b361..418fafaa958 100644 --- a/pkg/instance/start.go +++ b/pkg/instance/start.go @@ -74,6 +74,8 @@ func Prepare(ctx context.Context, inst *limatype.Instance) (*Prepared, error) { kernel := filepath.Join(inst.Dir, filenames.Kernel) kernelCmdline := filepath.Join(inst.Dir, filenames.KernelCmdline) initrd := filepath.Join(inst.Dir, filenames.Initrd) + entrypoint := filepath.Join(inst.Dir, filenames.Entrypoint) + stopsignal := filepath.Join(inst.Dir, filenames.StopSignal) if _, err := os.Stat(baseDisk); errors.Is(err, os.ErrNotExist) { var ensuredBaseDisk bool errs := make([]error, len(inst.Config.Images)) @@ -102,6 +104,18 @@ func Prepare(ctx context.Context, inst *limatype.Instance) (*Prepared, error) { continue } } + if f.Entrypoint != nil { + if err := os.WriteFile(entrypoint, []byte(*f.Entrypoint), 0o644); err != nil { + errs[i] = err + continue + } + } + if f.Stopsignal != nil { + if err := os.WriteFile(stopsignal, []byte(*f.Stopsignal), 0o644); err != nil { + errs[i] = err + continue + } + } ensuredBaseDisk = true break } diff --git a/pkg/limatype/filenames/filenames.go b/pkg/limatype/filenames/filenames.go index a8459d77888..43ca391cfae 100644 --- a/pkg/limatype/filenames/filenames.go +++ b/pkg/limatype/filenames/filenames.go @@ -41,6 +41,8 @@ const ( Kernel = "kernel" KernelCmdline = "kernel.cmdline" Initrd = "initrd" + Entrypoint = "entrypoint" + StopSignal = "stopsignal" QMPSock = "qmp.sock" SerialLog = "serial.log" // default serial (ttyS0, but ttyAMA0 on qemu-system-{arm,aarch64}) SerialSock = "serial.sock" diff --git a/pkg/limatype/lima_yaml.go b/pkg/limatype/lima_yaml.go index 367f5bc9887..1840b56f5fe 100644 --- a/pkg/limatype/lima_yaml.go +++ b/pkg/limatype/lima_yaml.go @@ -146,9 +146,11 @@ type Kernel struct { } type Image struct { - File `yaml:",inline"` - Kernel *Kernel `yaml:"kernel,omitempty" json:"kernel,omitempty"` - Initrd *File `yaml:"initrd,omitempty" json:"initrd,omitempty"` + File `yaml:",inline"` + Kernel *Kernel `yaml:"kernel,omitempty" json:"kernel,omitempty"` + Initrd *File `yaml:"initrd,omitempty" json:"initrd,omitempty"` + Entrypoint *string `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty"` + Stopsignal *string `yaml:"stopsignal,omitempty" json:"stopsignal,omitempty"` } type Disk struct { diff --git a/website/content/en/docs/dev/internals.md b/website/content/en/docs/dev/internals.md index 559f9ed75bd..445a0bad34e 100644 --- a/website/content/en/docs/dev/internals.md +++ b/website/content/en/docs/dev/internals.md @@ -52,6 +52,10 @@ kernel: - `kernel.cmdline`: the kernel cmdline - `initrd`: the initrd +container: +- `entrypoint`: the entrypoint to use (optional) +- `stopsignal`: the stopsignal to use (optional) + QEMU: - `qemu.pid`: QEMU PID - `qmp.sock`: QMP socket