From fab78c11d350ae9537c9879930f010210c399103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnegren?= Date: Wed, 8 May 2024 15:50:58 +0200 Subject: [PATCH 1/2] Add extra-cmdline flag to build-iso command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The extra-cmdline can be used to customize the kernel commandline used for the ISO. Some arbitrary flags were moved to the extra-cmdline in order to support overriding security and consoles. Signed-off-by: Fredrik Lönnegren --- cmd/build-iso.go | 2 ++ pkg/action/build-iso.go | 6 +++--- pkg/config/config.go | 11 ++++++----- pkg/constants/constants.go | 9 +++++---- pkg/types/config.go | 1 + 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/build-iso.go b/cmd/build-iso.go index 94166715674..be5a1700704 100644 --- a/cmd/build-iso.go +++ b/cmd/build-iso.go @@ -25,6 +25,7 @@ import ( "github.com/rancher/elemental-toolkit/v2/cmd/config" "github.com/rancher/elemental-toolkit/v2/pkg/action" + "github.com/rancher/elemental-toolkit/v2/pkg/constants" elementalError "github.com/rancher/elemental-toolkit/v2/pkg/error" "github.com/rancher/elemental-toolkit/v2/pkg/types" "github.com/rancher/elemental-toolkit/v2/pkg/utils" @@ -139,6 +140,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command { c.Flags().String("overlay-uefi", "", "Path of the overlayed uefi data") c.Flags().String("overlay-iso", "", "Path of the overlayed iso data") c.Flags().String("label", "", "Label of the ISO volume") + c.Flags().String("extra-cmdline", constants.ISODefaultExtraCmdline, "Extra kernel cmdline") c.Flags().Bool("bootloader-in-rootfs", false, "Fetch ISO bootloader binaries from the rootfs") c.Flags().Var(firmType, "firmware", "Firmware to install, only 'efi' is currently supported") _ = c.Flags().MarkDeprecated("firmware", "'firmware' is deprecated. only efi firmware is supported.") diff --git a/pkg/action/build-iso.go b/pkg/action/build-iso.go index 56fe0acd66a..a70e99abef1 100644 --- a/pkg/action/build-iso.go +++ b/pkg/action/build-iso.go @@ -33,7 +33,7 @@ const ( isoBootCatalog = "/boot/boot.catalog" ) -func grubCfgTemplate(arch string) string { +func grubCfgTemplate(arch, cmdline string) string { return `search --no-floppy --file --set=root ` + constants.ISOKernelPath(arch) + ` set default=0 set timeout=5 @@ -42,7 +42,7 @@ func grubCfgTemplate(arch string) string { menuentry "%s" --class os --unrestricted { echo Loading kernel... linux ($root)` + constants.ISOKernelPath(arch) + ` cdroot root=live:CDLABEL=%s rd.live.dir=` + constants.ISOLoaderPath(arch) + - ` rd.live.squashimg=rootfs.squashfs security=selinux enforcing=0 console=tty1 console=ttyS0 elemental.disable elemental.setup=` + + ` rd.live.squashimg=rootfs.squashfs ` + cmdline + ` elemental.disable elemental.setup=` + constants.ISOCloudInitPath + ` echo Loading initrd... initrd ($root)` + constants.ISOInitrdPath(arch) + ` @@ -222,7 +222,7 @@ func (b *BuildISOAction) renderGrubTemplate(rootDir string) error { // Write grub.cfg file return b.cfg.Fs.WriteFile( filepath.Join(rootDir, constants.FallbackEFIPath, constants.GrubCfg), - []byte(fmt.Sprintf(grubCfgTemplate(b.cfg.Platform.Arch), b.spec.GrubEntry, b.spec.Label)), + []byte(fmt.Sprintf(grubCfgTemplate(b.cfg.Platform.Arch, b.spec.ExtraCmdline), b.spec.GrubEntry, b.spec.Label)), constants.FilePerm, ) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 6e26012199c..cc2170f43e6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -538,11 +538,12 @@ func NewDisk(cfg *types.BuildConfig) *types.DiskSpec { func NewISO() *types.LiveISO { return &types.LiveISO{ - Label: constants.ISOLabel, - GrubEntry: constants.GrubDefEntry, - UEFI: []*types.ImageSource{}, - Image: []*types.ImageSource{}, - Firmware: types.EFI, + Label: constants.ISOLabel, + GrubEntry: constants.GrubDefEntry, + UEFI: []*types.ImageSource{}, + Image: []*types.ImageSource{}, + Firmware: types.EFI, + ExtraCmdline: constants.ISODefaultExtraCmdline, } } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index b80f9a6d2f1..5686df1db16 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -148,10 +148,11 @@ const ( SELinuxRelabelDir = "/run/systemd/relabel-extra.d" SELinuxRelabelFile = "elemental.relabel" - ISORootFile = "rootfs.squashfs" - ISOEFIImg = "uefi.img" - ISOLabel = "COS_LIVE" - ISOCloudInitPath = LiveDir + "/iso-config" + ISORootFile = "rootfs.squashfs" + ISOEFIImg = "uefi.img" + ISOLabel = "COS_LIVE" + ISOCloudInitPath = LiveDir + "/iso-config" + ISODefaultExtraCmdline = "security=selinux enforcing=0 console=tty1 console=ttyS0" MountLayoutPath = "/run/elemental/mount-layout.env" diff --git a/pkg/types/config.go b/pkg/types/config.go index 7367bdab0b2..395fb939a04 100644 --- a/pkg/types/config.go +++ b/pkg/types/config.go @@ -689,6 +689,7 @@ type LiveISO struct { GrubEntry string `yaml:"grub-entry-name,omitempty" mapstructure:"grub-entry-name"` BootloaderInRootFs bool `yaml:"bootloader-in-rootfs" mapstructure:"bootloader-in-rootfs"` Firmware string `yaml:"firmware,omitempty" mapstructure:"firmware"` + ExtraCmdline string `yaml:"extra-cmdline,omitempty" mapstructure:"extra-cmdline"` } // Sanitize checks the consistency of the struct, returns error From 4c4624ae78d9b541b76701bf004b4bfbf1083f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnegren?= Date: Fri, 10 May 2024 11:59:34 +0200 Subject: [PATCH 2/2] Empty default in cmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Lönnegren --- cmd/build-iso.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/build-iso.go b/cmd/build-iso.go index be5a1700704..5364040b836 100644 --- a/cmd/build-iso.go +++ b/cmd/build-iso.go @@ -140,7 +140,7 @@ func NewBuildISO(root *cobra.Command, addCheckRoot bool) *cobra.Command { c.Flags().String("overlay-uefi", "", "Path of the overlayed uefi data") c.Flags().String("overlay-iso", "", "Path of the overlayed iso data") c.Flags().String("label", "", "Label of the ISO volume") - c.Flags().String("extra-cmdline", constants.ISODefaultExtraCmdline, "Extra kernel cmdline") + c.Flags().String("extra-cmdline", "", fmt.Sprintf("Extra kernel cmdline (defaults to '%s')", constants.ISODefaultExtraCmdline)) c.Flags().Bool("bootloader-in-rootfs", false, "Fetch ISO bootloader binaries from the rootfs") c.Flags().Var(firmType, "firmware", "Firmware to install, only 'efi' is currently supported") _ = c.Flags().MarkDeprecated("firmware", "'firmware' is deprecated. only efi firmware is supported.")