From 5cb358311af0eb96b9cf8da8ee60525041661b7c 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/limayaml/limayaml.go | 8 +++++--- pkg/store/filenames/filenames.go | 2 ++ 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 4f08219f46e..984c92cc5b1 100644 --- a/pkg/instance/start.go +++ b/pkg/instance/start.go @@ -109,6 +109,8 @@ func Prepare(ctx context.Context, inst *store.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)) @@ -137,6 +139,18 @@ func Prepare(ctx context.Context, inst *store.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/limayaml/limayaml.go b/pkg/limayaml/limayaml.go index a21c4aa5cf0..209e8334277 100644 --- a/pkg/limayaml/limayaml.go +++ b/pkg/limayaml/limayaml.go @@ -137,9 +137,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/pkg/store/filenames/filenames.go b/pkg/store/filenames/filenames.go index a8459d77888..43ca391cfae 100644 --- a/pkg/store/filenames/filenames.go +++ b/pkg/store/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/website/content/en/docs/dev/internals.md b/website/content/en/docs/dev/internals.md index 3a65d6a4ae5..10afa2fcfb3 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