Skip to content

Commit e8d2825

Browse files
cgwaltersopenshift-merge-robot
authored andcommitted
Support cosa run --kargs
For the use case of enabling systemd debugging, etc. #1263 (comment)
1 parent 332c6ab commit e8d2825

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

mantle/cmd/kola/qemuexec.go

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939

4040
hostname string
4141
ignition string
42+
kargs string
4243
knetargs string
4344

4445
forceConfigInjection bool
@@ -47,6 +48,7 @@ var (
4748
func init() {
4849
root.AddCommand(cmdQemuExec)
4950
cmdQemuExec.Flags().StringVarP(&knetargs, "knetargs", "", "", "Arguments for Ignition networking on kernel commandline")
51+
cmdQemuExec.Flags().StringVarP(&kargs, "kargs", "", "", "Additional kernel arguments applied")
5052
cmdQemuExec.Flags().BoolVarP(&usernet, "usernet", "U", false, "Enable usermode networking")
5153
cmdQemuExec.Flags().StringVarP(&hostname, "hostname", "", "", "Set hostname via DHCP")
5254
cmdQemuExec.Flags().IntVarP(&memory, "memory", "m", 0, "Memory in MB")
@@ -61,6 +63,7 @@ func runQemuExec(cmd *cobra.Command, args []string) error {
6163
if len(knetargs) > 0 {
6264
builder.IgnitionNetworkKargs = knetargs
6365
}
66+
builder.AppendKernelArguments = kargs
6467
defer builder.Close()
6568
builder.Firmware = kola.QEMUOptions.Firmware
6669
if kola.QEMUOptions.DiskImage != "" {

mantle/platform/qemu.go

+36-5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ type QemuBuilder struct {
147147
Pdeathsig bool
148148
Argv []string
149149

150+
// AppendKernelArguments are appended to the bootloader config
151+
AppendKernelArguments string
152+
150153
// IgnitionNetworkKargs are written to /boot/ignition
151154
IgnitionNetworkKargs string
152155

@@ -353,9 +356,8 @@ func (gf *coreosGuestfish) destroy() {
353356
}
354357
}
355358

356-
// setupIgnition copies the ignition file inside the disk image and/or sets
357-
// networking kernel arguments
358-
func setupIgnition(confPath string, knetargs string, diskImagePath string, diskSectorSize int) error {
359+
// setupPreboot performs changes necessary before the disk is booted
360+
func setupPreboot(confPath, knetargs, kargs string, diskImagePath string, diskSectorSize int) error {
359361
gf, err := newGuestfish(diskImagePath, diskSectorSize)
360362
if err != nil {
361363
return err
@@ -380,6 +382,34 @@ func setupIgnition(confPath string, knetargs string, diskImagePath string, diskS
380382
}
381383
}
382384

385+
if kargs != "" {
386+
confpathout, err := exec.Command("guestfish", gf.remote, "glob-expand", "/loader/entries/ostree*conf").Output()
387+
if err != nil {
388+
return errors.Wrapf(err, "finding bootloader config path")
389+
}
390+
confs := strings.Split(strings.TrimSpace(string(confpathout)), "\n")
391+
if len(confs) != 1 {
392+
return fmt.Errorf("Multiple values for bootloader config: %v", confpathout)
393+
}
394+
confpath := confs[0]
395+
396+
origconf, err := exec.Command("guestfish", gf.remote, "read-file", confpath).Output()
397+
if err != nil {
398+
return errors.Wrapf(err, "reading bootloader config")
399+
}
400+
var buf strings.Builder
401+
for _, line := range strings.Split(string(origconf), "\n") {
402+
if strings.HasPrefix(line, "options ") {
403+
line += " " + kargs
404+
}
405+
buf.Write([]byte(line))
406+
buf.Write([]byte("\n"))
407+
}
408+
if err := exec.Command("guestfish", gf.remote, "write", confpath, buf.String()).Run(); err != nil {
409+
return errors.Wrapf(err, "writing bootloader config")
410+
}
411+
}
412+
383413
if err := exec.Command("guestfish", gf.remote, "umount-all").Run(); err != nil {
384414
return errors.Wrapf(err, "guestfish umount failed")
385415
}
@@ -440,8 +470,9 @@ func (builder *QemuBuilder) addDiskImpl(disk *Disk, primary bool) error {
440470
// If the board doesn't support -fw_cfg or we were explicitly
441471
// requested, inject via libguestfs on the primary disk.
442472
requiresInjection := builder.Config != "" && (builder.ForceConfigInjection || !builder.supportsFwCfg())
443-
if requiresInjection || builder.IgnitionNetworkKargs != "" {
444-
if err = setupIgnition(builder.Config, builder.IgnitionNetworkKargs, dstFileName, disk.SectorSize); err != nil {
473+
if requiresInjection || builder.IgnitionNetworkKargs != "" || builder.AppendKernelArguments != "" {
474+
if err = setupPreboot(builder.Config, builder.IgnitionNetworkKargs, builder.AppendKernelArguments,
475+
dstFileName, disk.SectorSize); err != nil {
445476
return errors.Wrapf(err, "ignition injection with guestfs failed")
446477
}
447478
}

src/cmd-run

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BUILDID=latest
1717
IMAGE_TYPE=qemu
1818
HOSTNAME=
1919
VM_DISK=
20+
KARGS=
2021
DISK_CHANNEL=virtio
2122
VM_MEMORY=2048
2223
VM_NCPUS="${VM_NCPUS:-${QEMU_PROCS}}"
@@ -36,6 +37,7 @@ Options:
3637
--size GB Disk size in GB (matches base by default)
3738
--user USERNAME Create user USERNAME via Ignition (if not already extant) and log in as that user
3839
-h this ;-)
40+
--kargs Append kernel arguments
3941
--uefi Boot using uefi (x86_64 only, implied on arm)
4042
--uefi-secure Boot using uefi with secure boot enabled (x86_64/arm only)
4143
@@ -91,6 +93,9 @@ while [ $# -ge 1 ]; do
9193
--uefi-secure)
9294
FIRMWARE=uefi-secure
9395
shift ;;
96+
--kargs)
97+
KARGS="$2"
98+
shift 2;;
9499
-h|--help)
95100
echo "$USAGE"
96101
exit ;;
@@ -271,6 +276,9 @@ esac
271276
if [ -n "${HOSTNAME}" ]; then
272277
kola_args+=("--hostname=${HOSTNAME}")
273278
fi
279+
if [ -n "${KARGS}" ]; then
280+
kola_args+=("--kargs=${KARGS}")
281+
fi
274282

275283
# for the metal images, there's no other way but to inject into /boot
276284
case "${IMAGE_TYPE}" in

0 commit comments

Comments
 (0)