Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cosa run --kargs #1265

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -149,6 +149,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 @@ -356,9 +359,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 @@ -383,6 +385,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 @@ -443,8 +473,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 @@ -275,6 +280,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