Skip to content

Commit 63a2e56

Browse files
committed
Adding better handling for kernel cmdline arguments
1 parent 6a5d7a4 commit 63a2e56

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## General
66

7+
* Adds better handling for user-supplied kernel cmdline arguments:
8+
* Removes duplicates found between default and user-supplied arguments in all scenarios (RAW cmdline, ISO cmdline, and `kexec` config.bootoptions).
9+
* Removes the reliance on `rd.kiwi.install.pass.bootparam` to pull user-supplied arguments post-`kexec` (with SelfInstall ISO).
10+
711
## API
812

913
### Image Definition Changes
@@ -14,6 +18,7 @@
1418

1519
* [#593](https://github.com/suse-edge/edge-image-builder/issues/593) - OS files script should mount /var
1620
* [#594](https://github.com/suse-edge/edge-image-builder/issues/594) - Package install breaks package resolution if packages is already installed on root OS
21+
* [#604](https://github.com/suse-edge/edge-image-builder/issues/604) - Handle kernel arguments better, especially when duplicated
1722

1823
---
1924

pkg/build/grub.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ func (b *Builder) generateGRUBGuestfishCommands() (string, error) {
2727

2828
argLine := strings.Join(b.context.ImageDefinition.OperatingSystem.KernelArgs, " ")
2929
values := struct {
30-
KernelArgs string
30+
KernelArgs string
31+
KernelArgsList []string
3132
}{
32-
KernelArgs: argLine,
33+
KernelArgs: argLine,
34+
KernelArgsList: b.context.ImageDefinition.OperatingSystem.KernelArgs,
3335
}
3436

3537
snippet, err := template.Parse("guestfish-snippet", guestfishSnippet, values)

pkg/build/iso.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func (b *Builder) writeIsoScript(templateContents, outputFilename string) error
110110
ArtefactsDir string
111111
InstallDevice string
112112
KernelArgs string
113+
KernelArgsList []string
114+
Arch string
113115
}{
114116
IsoExtractDir: isoExtractPath,
115117
RawExtractDir: rawExtractPath,
@@ -119,6 +121,8 @@ func (b *Builder) writeIsoScript(templateContents, outputFilename string) error
119121
ArtefactsDir: b.context.ArtefactsDir,
120122
InstallDevice: b.context.ImageDefinition.OperatingSystem.IsoConfiguration.InstallDevice,
121123
KernelArgs: argLine,
124+
KernelArgsList: b.context.ImageDefinition.OperatingSystem.KernelArgs,
125+
Arch: string(b.context.ImageDefinition.Image.Arch),
122126
}
123127

124128
contents, err := template.Parse("iso-script", templateContents, arguments)

pkg/build/templates/grub/guestfish-snippet.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Configure GRUB defaults
22
# - So that the update below, and later`transactional-update grub.cfg` will persist the changes
33
download /etc/default/grub /tmp/grub
4+
# Remove original kernel arguments that match desired kernelArgs that have values
5+
{{ range .KernelArgsList -}}
6+
! sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT/ s/$(echo {{ . }} | cut -f1 -d"=")=[^=]//" /tmp/grub
7+
{{ end -}}
8+
# Add in the new ones
49
! sed -i '/^GRUB_CMDLINE_LINUX_DEFAULT="/ s/"$/ {{.KernelArgs}} "/' /tmp/grub
510
upload /tmp/grub /etc/default/grub
611

pkg/build/templates/rebuild-iso.sh.tpl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,33 @@ echo -e "set timeout=3\nset timeout_style=menu\n$(cat ${ISO_EXTRACT_DIR}/boot/gr
3535
sed -i '/root=install:CDLABEL=INSTALL/ s|$| rd.kiwi.oem.installdevice={{.InstallDevice}} |' ${ISO_EXTRACT_DIR}/boot/grub2/grub.cfg
3636
{{ end -}}
3737

38-
# Ensure that kernel arguments are appended to ISO grub.cfg so they are applied to firstboot via kexec
3938
{{ if (gt (len .KernelArgs) 0) -}}
40-
sed -i '/root=install:CDLABEL=INSTALL/ s|$| rd.kiwi.install.pass.bootparam {{.KernelArgs}} |' ${ISO_EXTRACT_DIR}/boot/grub2/grub.cfg
39+
# Remove all original kernel arguments from ISO command line that match input kernelArgs *and* have values
40+
{{ range .KernelArgsList -}}
41+
value=$(echo {{ . }} | cut -f1 -d"=")
42+
sed -i "s/$value=[^=]//" ${ISO_EXTRACT_DIR}/boot/grub2/grub.cfg
43+
{{ end -}}
44+
45+
# Unpack the initrd from the SelfInstall ISO and copy the early microcode into new initrd
46+
mkdir -p ${ISO_EXTRACT_DIR}/temp-initram/early/ ${ISO_EXTRACT_DIR}/temp-initram/main/
47+
cp ${ISO_EXTRACT_DIR}/boot/{{ .Arch }}/loader/initrd ${ISO_EXTRACT_DIR}/temp-initram/
48+
cd ${ISO_EXTRACT_DIR}/temp-initram/early && lsinitrd --unpackearly ${ISO_EXTRACT_DIR}/temp-initram/initrd
49+
find . -print0 | cpio --null --create --format=newc > ${ISO_EXTRACT_DIR}/temp-initram/new-initrd
50+
# NOTE: We pipe the following command to true to avoid issues with mknod failing when unprivileged
51+
cd ${ISO_EXTRACT_DIR}/temp-initram/main && lsinitrd --unpack ${ISO_EXTRACT_DIR}/temp-initram/initrd || true
52+
53+
# Remove the original kernel arguments from initrd config that match input kernelArgs and add desired ones
54+
{{ range .KernelArgsList -}}
55+
value=$(echo {{ . }} | cut -f1 -d"=")
56+
sed -i "s/$value=[^=]//" config.bootoptions
57+
{{ end -}}
58+
sed -i '1s|$| {{ .KernelArgs }}|' config.bootoptions
59+
60+
# Repack the contents of the initrd into the new file, including the new kernel cmdline arguments
61+
find . | cpio --create --format=newc >> ${ISO_EXTRACT_DIR}/temp-initram/new-initrd
62+
63+
# Add the desired kernel cmdline arguments to the ISO kernel cmdline so they're available during deployment
64+
sed -i '/root=install:CDLABEL=INSTALL/ s|$| {{.KernelArgs}} |' ${ISO_EXTRACT_DIR}/boot/grub2/grub.cfg
4165
{{ end -}}
4266

4367
cd ${RAW_EXTRACT_DIR}
@@ -51,5 +75,8 @@ xorriso -indev ${ISO_SOURCE} \
5175
-map ${ARTEFACTS_DIR} /artefacts \
5276
{{- if .InstallDevice }}
5377
-map ${ISO_EXTRACT_DIR}/boot/grub2/grub.cfg /boot/grub2/grub.cfg \
78+
{{- end }}
79+
{{- if (gt (len .KernelArgs) 0) }}
80+
-map ${ISO_EXTRACT_DIR}/temp-initram/new-initrd /boot/{{ .Arch }}/loader/initrd \
5481
{{- end }}
5582
-boot_image any replay -changes_pending yes

0 commit comments

Comments
 (0)