Skip to content

Commit 42de1f9

Browse files
committed
Support cosa run --kargs
For the use case of enabling systemd debugging, etc. coreos#1263 (comment)
1 parent 3b76b6c commit 42de1f9

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
@@ -149,6 +149,9 @@ type QemuBuilder struct {
149149
Pdeathsig bool
150150
Argv []string
151151

152+
// AppendKernelArguments are appended to the bootloader config
153+
AppendKernelArguments string
154+
152155
// IgnitionNetworkKargs are written to /boot/ignition
153156
IgnitionNetworkKargs string
154157

@@ -356,9 +359,8 @@ func (gf *coreosGuestfish) destroy() {
356359
}
357360
}
358361

359-
// setupIgnition copies the ignition file inside the disk image and/or sets
360-
// networking kernel arguments
361-
func setupIgnition(confPath string, knetargs string, diskImagePath string, diskSectorSize int) error {
362+
// setupPreboot performs changes necessary before the disk is booted
363+
func setupPreboot(confPath, knetargs, kargs string, diskImagePath string, diskSectorSize int) error {
362364
gf, err := newGuestfish(diskImagePath, diskSectorSize)
363365
if err != nil {
364366
return err
@@ -383,6 +385,34 @@ func setupIgnition(confPath string, knetargs string, diskImagePath string, diskS
383385
}
384386
}
385387

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

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 ;;
@@ -275,6 +280,9 @@ esac
275280
if [ -n "${HOSTNAME}" ]; then
276281
kola_args+=("--hostname=${HOSTNAME}")
277282
fi
283+
if [ -n "${KARGS}" ]; then
284+
kola_args+=("--kargs=${KARGS}")
285+
fi
278286

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

0 commit comments

Comments
 (0)