From 51f73a6d8ff4dca5fd45dd7458128071e28a6bb4 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 8 Sep 2023 17:53:31 +0200 Subject: [PATCH] distro: add a kickstart file to /root for minimal-raw images Currently initial-setup requires a kickstart file in the /root directory to work. Adding a temporary file node to the image config for minimal-raw images so that initial-setup runs and a user can be created if necessary. The minimal-raw image has no other mechanism for creating a user if one wasn't specified at build time, so we need to be sure that initial-setup runs. --- pkg/distro/fedora/distro.go | 4 ++++ pkg/distro/fedora/images.go | 11 +++++++++++ pkg/distro/rhel8/edge.go | 4 ++++ pkg/distro/rhel8/images.go | 11 +++++++++++ pkg/distro/rhel9/edge.go | 4 ++++ pkg/distro/rhel9/images.go | 11 +++++++++++ 6 files changed, 45 insertions(+) diff --git a/pkg/distro/fedora/distro.go b/pkg/distro/fedora/distro.go index f9a19b9e04..645637f7be 100644 --- a/pkg/distro/fedora/distro.go +++ b/pkg/distro/fedora/distro.go @@ -8,6 +8,7 @@ import ( "github.com/osbuild/images/internal/common" "github.com/osbuild/images/internal/environment" + "github.com/osbuild/images/internal/fsnode" "github.com/osbuild/images/internal/oscap" "github.com/osbuild/images/pkg/distro" "github.com/osbuild/images/pkg/osbuild" @@ -387,6 +388,9 @@ var ( }, defaultImageConfig: &distro.ImageConfig{ EnabledServices: minimalRawServices, + // NOTE: temporary workaround for a bug in initial-setup that + // requires a kickstart file in the root directory. + Files: []*fsnode.File{initialSetupKickstart()}, }, rpmOstree: false, kernelOptions: defaultKernelOptions, diff --git a/pkg/distro/fedora/images.go b/pkg/distro/fedora/images.go index 19b64a00a8..7f9040633e 100644 --- a/pkg/distro/fedora/images.go +++ b/pkg/distro/fedora/images.go @@ -6,6 +6,7 @@ import ( "github.com/osbuild/images/internal/common" "github.com/osbuild/images/internal/fdo" + "github.com/osbuild/images/internal/fsnode" "github.com/osbuild/images/internal/ignition" "github.com/osbuild/images/internal/oscap" "github.com/osbuild/images/internal/users" @@ -687,3 +688,13 @@ func makeOSTreePayloadCommit(options *ostree.ImageOptions, defaultRef string) (o RHSM: options.RHSM, }, nil } + +// initialSetupKickstart returns the File configuration for a kickstart file +// that's required to enable initial-setup to run on first boot. +func initialSetupKickstart() *fsnode.File { + file, err := fsnode.NewFile("/root/anaconda-ks.cfg", nil, "root", "root", []byte("# Run initial-setup on first boot\n# Created by osbuild\nfirstboot --reconfig\n")) + if err != nil { + panic(err) + } + return file +} diff --git a/pkg/distro/rhel8/edge.go b/pkg/distro/rhel8/edge.go index 0be5e6d57b..f19ffd2fce 100644 --- a/pkg/distro/rhel8/edge.go +++ b/pkg/distro/rhel8/edge.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/osbuild/images/internal/common" + "github.com/osbuild/images/internal/fsnode" "github.com/osbuild/images/pkg/distro" "github.com/osbuild/images/pkg/platform" "github.com/osbuild/images/pkg/rpmmd" @@ -150,6 +151,9 @@ func minimalRawImgType(rd distribution) imageType { }, defaultImageConfig: &distro.ImageConfig{ EnabledServices: minimalrawServices(rd), + // NOTE: temporary workaround for a bug in initial-setup that + // requires a kickstart file in the root directory. + Files: []*fsnode.File{initialSetupKickstart()}, }, rpmOstree: false, kernelOptions: "ro", diff --git a/pkg/distro/rhel8/images.go b/pkg/distro/rhel8/images.go index 7a454f6788..cb7ca63bc7 100644 --- a/pkg/distro/rhel8/images.go +++ b/pkg/distro/rhel8/images.go @@ -5,6 +5,7 @@ import ( "math/rand" "github.com/osbuild/images/internal/fdo" + "github.com/osbuild/images/internal/fsnode" "github.com/osbuild/images/internal/ignition" "github.com/osbuild/images/internal/oscap" "github.com/osbuild/images/internal/users" @@ -602,3 +603,13 @@ func makeOSTreePayloadCommit(options *ostree.ImageOptions, defaultRef string) (o RHSM: options.RHSM, }, nil } + +// initialSetupKickstart returns the File configuration for a kickstart file +// that's required to enable initial-setup to run on first boot. +func initialSetupKickstart() *fsnode.File { + file, err := fsnode.NewFile("/root/anaconda-ks.cfg", nil, "root", "root", []byte("# Run initial-setup on first boot\n# Created by osbuild\nfirstboot --reconfig\nlang en_US.UTF-8\n")) + if err != nil { + panic(err) + } + return file +} diff --git a/pkg/distro/rhel9/edge.go b/pkg/distro/rhel9/edge.go index 29067a6c6c..bea68f8bdc 100644 --- a/pkg/distro/rhel9/edge.go +++ b/pkg/distro/rhel9/edge.go @@ -5,6 +5,7 @@ import ( "github.com/osbuild/images/internal/common" "github.com/osbuild/images/internal/environment" + "github.com/osbuild/images/internal/fsnode" "github.com/osbuild/images/pkg/disk" "github.com/osbuild/images/pkg/distro" "github.com/osbuild/images/pkg/osbuild" @@ -186,6 +187,9 @@ var ( defaultImageConfig: &distro.ImageConfig{ EnabledServices: minimalrawServices, SystemdUnit: systemdUnits, + // NOTE: temporary workaround for a bug in initial-setup that + // requires a kickstart file in the root directory. + Files: []*fsnode.File{initialSetupKickstart()}, }, rpmOstree: false, kernelOptions: "ro", diff --git a/pkg/distro/rhel9/images.go b/pkg/distro/rhel9/images.go index e5d56f15c3..4cbcd85299 100644 --- a/pkg/distro/rhel9/images.go +++ b/pkg/distro/rhel9/images.go @@ -6,6 +6,7 @@ import ( "github.com/osbuild/images/internal/common" "github.com/osbuild/images/internal/fdo" + "github.com/osbuild/images/internal/fsnode" "github.com/osbuild/images/internal/ignition" "github.com/osbuild/images/internal/oscap" "github.com/osbuild/images/internal/users" @@ -650,3 +651,13 @@ func makeOSTreePayloadCommit(options *ostree.ImageOptions, defaultRef string) (o RHSM: options.RHSM, }, nil } + +// initialSetupKickstart returns the File configuration for a kickstart file +// that's required to enable initial-setup to run on first boot. +func initialSetupKickstart() *fsnode.File { + file, err := fsnode.NewFile("/root/anaconda-ks.cfg", nil, "root", "root", []byte("# Run initial-setup on first boot\n# Created by osbuild\nfirstboot --reconfig\nlang en_US.UTF-8\n")) + if err != nil { + panic(err) + } + return file +}