Skip to content

Commit

Permalink
Support cosa run --kargs
Browse files Browse the repository at this point in the history
For the use case of enabling systemd debugging, etc.
#1263 (comment)
  • Loading branch information
cgwalters authored and openshift-merge-robot committed Mar 23, 2020
1 parent 332c6ab commit e8d2825
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
3 changes: 3 additions & 0 deletions mantle/cmd/kola/qemuexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (

hostname string
ignition string
kargs string
knetargs string

forceConfigInjection bool
Expand All @@ -47,6 +48,7 @@ var (
func init() {
root.AddCommand(cmdQemuExec)
cmdQemuExec.Flags().StringVarP(&knetargs, "knetargs", "", "", "Arguments for Ignition networking on kernel commandline")
cmdQemuExec.Flags().StringVarP(&kargs, "kargs", "", "", "Additional kernel arguments applied")
cmdQemuExec.Flags().BoolVarP(&usernet, "usernet", "U", false, "Enable usermode networking")
cmdQemuExec.Flags().StringVarP(&hostname, "hostname", "", "", "Set hostname via DHCP")
cmdQemuExec.Flags().IntVarP(&memory, "memory", "m", 0, "Memory in MB")
Expand All @@ -61,6 +63,7 @@ func runQemuExec(cmd *cobra.Command, args []string) error {
if len(knetargs) > 0 {
builder.IgnitionNetworkKargs = knetargs
}
builder.AppendKernelArguments = kargs
defer builder.Close()
builder.Firmware = kola.QEMUOptions.Firmware
if kola.QEMUOptions.DiskImage != "" {
Expand Down
41 changes: 36 additions & 5 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ type QemuBuilder struct {
Pdeathsig bool
Argv []string

// AppendKernelArguments are appended to the bootloader config
AppendKernelArguments string

// IgnitionNetworkKargs are written to /boot/ignition
IgnitionNetworkKargs string

Expand Down Expand Up @@ -353,9 +356,8 @@ func (gf *coreosGuestfish) destroy() {
}
}

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

if kargs != "" {
confpathout, err := exec.Command("guestfish", gf.remote, "glob-expand", "/loader/entries/ostree*conf").Output()
if err != nil {
return errors.Wrapf(err, "finding bootloader config path")
}
confs := strings.Split(strings.TrimSpace(string(confpathout)), "\n")
if len(confs) != 1 {
return fmt.Errorf("Multiple values for bootloader config: %v", confpathout)
}
confpath := confs[0]

origconf, err := exec.Command("guestfish", gf.remote, "read-file", confpath).Output()
if err != nil {
return errors.Wrapf(err, "reading bootloader config")
}
var buf strings.Builder
for _, line := range strings.Split(string(origconf), "\n") {
if strings.HasPrefix(line, "options ") {
line += " " + kargs
}
buf.Write([]byte(line))
buf.Write([]byte("\n"))
}
if err := exec.Command("guestfish", gf.remote, "write", confpath, buf.String()).Run(); err != nil {
return errors.Wrapf(err, "writing bootloader config")
}
}

if err := exec.Command("guestfish", gf.remote, "umount-all").Run(); err != nil {
return errors.Wrapf(err, "guestfish umount failed")
}
Expand Down Expand Up @@ -440,8 +470,9 @@ func (builder *QemuBuilder) addDiskImpl(disk *Disk, primary bool) error {
// If the board doesn't support -fw_cfg or we were explicitly
// requested, inject via libguestfs on the primary disk.
requiresInjection := builder.Config != "" && (builder.ForceConfigInjection || !builder.supportsFwCfg())
if requiresInjection || builder.IgnitionNetworkKargs != "" {
if err = setupIgnition(builder.Config, builder.IgnitionNetworkKargs, dstFileName, disk.SectorSize); err != nil {
if requiresInjection || builder.IgnitionNetworkKargs != "" || builder.AppendKernelArguments != "" {
if err = setupPreboot(builder.Config, builder.IgnitionNetworkKargs, builder.AppendKernelArguments,
dstFileName, disk.SectorSize); err != nil {
return errors.Wrapf(err, "ignition injection with guestfs failed")
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/cmd-run
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ BUILDID=latest
IMAGE_TYPE=qemu
HOSTNAME=
VM_DISK=
KARGS=
DISK_CHANNEL=virtio
VM_MEMORY=2048
VM_NCPUS="${VM_NCPUS:-${QEMU_PROCS}}"
Expand All @@ -36,6 +37,7 @@ Options:
--size GB Disk size in GB (matches base by default)
--user USERNAME Create user USERNAME via Ignition (if not already extant) and log in as that user
-h this ;-)
--kargs Append kernel arguments
--uefi Boot using uefi (x86_64 only, implied on arm)
--uefi-secure Boot using uefi with secure boot enabled (x86_64/arm only)
Expand Down Expand Up @@ -91,6 +93,9 @@ while [ $# -ge 1 ]; do
--uefi-secure)
FIRMWARE=uefi-secure
shift ;;
--kargs)
KARGS="$2"
shift 2;;
-h|--help)
echo "$USAGE"
exit ;;
Expand Down Expand Up @@ -271,6 +276,9 @@ esac
if [ -n "${HOSTNAME}" ]; then
kola_args+=("--hostname=${HOSTNAME}")
fi
if [ -n "${KARGS}" ]; then
kola_args+=("--kargs=${KARGS}")
fi

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

0 comments on commit e8d2825

Please sign in to comment.