Skip to content
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
10 changes: 7 additions & 3 deletions internal/install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ func (*initramfsFixtureRunner) LookPath(name string) (string, error) {
}

func TestWriterCmdline(t *testing.T) {
got := writerCmdline("BOOT_IMAGE=/boot/vmlinuz root=/dev/sda1 ro quiet initrd=/boot/initrd chr.install=old")
if got != "root=/dev/sda1 ro quiet chr.install=1" {
t.Fatalf("writerCmdline() = %q", got)
for input, want := range map[string]string{
"BOOT_IMAGE=/boot/vmlinuz root=/dev/sda1 ro quiet initrd=/boot/initrd chr.install=old": "root=/dev/sda1 ro quiet kho=off chr.install=1",
"root=/dev/vda ro kho=on kho_scratch=200%": "root=/dev/vda ro kho_scratch=200% kho=off chr.install=1",
} {
if got := WriterCmdline(input); got != want {
t.Fatalf("WriterCmdline(%q) = %q, want %q", input, got, want)
}
}
}

Expand Down
20 changes: 16 additions & 4 deletions internal/install/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func PrepareStage(ctx context.Context, runner command.Runner, disk model.Disk, i
if err != nil {
return Stage{}, err
}
cmdline := writerCmdline(string(cmdlineData))
cmdline := WriterCmdline(string(cmdlineData))
stage = Stage{Method: disk.Method, KernelPath: disk.KernelPath, Cmdline: cmdline}
partialFiles := []string{}
partialDirs := []string{}
Expand Down Expand Up @@ -407,15 +407,27 @@ func kernelVersion(kernelPath string) string {
return strings.TrimPrefix(filepath.Base(kernelPath), "vmlinuz-")
}

func writerCmdline(input string) string {
// WriterCmdline derives the staged writer's kernel command line from the
// running host's command line.
//
// It always appends kho=off. Kernels built with
// CONFIG_KEXEC_HANDOVER_ENABLE_DEFAULT (Ubuntu 26.04's 7.0 kernels) reserve
// kexec-handover scratch areas at boot sized at twice the memory already in
// use, and hand them to the page allocator as CMA, which only movable pages
// may use. The staged initramfs carries the whole CHR image, so on a small
// host those areas can leave the kernel too little ordinary memory to finish
// booting, and it panics on out-of-memory before the writer starts. The
// writer boot never performs a kexec handover itself, so it does not need
// the scratch areas.
func WriterCmdline(input string) string {
var result []string
for _, field := range strings.Fields(input) {
if strings.HasPrefix(field, "BOOT_IMAGE=") || strings.HasPrefix(field, "initrd=") || strings.HasPrefix(field, "rdinit=") || strings.HasPrefix(field, "chr.install=") {
if strings.HasPrefix(field, "BOOT_IMAGE=") || strings.HasPrefix(field, "initrd=") || strings.HasPrefix(field, "rdinit=") || strings.HasPrefix(field, "chr.install=") || strings.HasPrefix(field, "kho=") {
continue
}
result = append(result, field)
}
result = append(result, "chr.install=1")
result = append(result, "kho=off", "chr.install=1")
return strings.Join(result, " ")
}

Expand Down
12 changes: 7 additions & 5 deletions internal/integration/writer_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestStagedWriterQEMU(t *testing.T) {
arguments := []string{
"-machine", "q35,accel=tcg", "-cpu", writerQEMUCPU, "-m", "768", "-nographic", "-no-reboot",
"-kernel", kernel, "-initrd", stagedInitrd,
"-append", "console=ttyS0 root=" + targetDisk.Path + " rootfstype=ext4 ro panic=-1 chr.install=1",
"-append", install.WriterCmdline("console=ttyS0 root=" + targetDisk.Path + " rootfstype=ext4 ro panic=-1"),
}
arguments = append(arguments, diskArguments...)
process := exec.CommandContext(ctx, "qemu-system-x86_64", arguments...)
Expand Down Expand Up @@ -252,10 +252,10 @@ menuentry 'Fallback Linux' --id 'fallback-linux' {
}
menuentry 'CHR Install Writer' --id 'chr-install-writer' {
search --no-floppy --fs-uuid --set=root %s
linux /boot/vmlinuz console=ttyS0 root=/dev/vda rootfstype=ext4 ro panic=-1 chr.install=1
linux /boot/vmlinuz %s
initrd /boot/initrd.img
}
`, uuid)
`, uuid, install.WriterCmdline("console=ttyS0 root=/dev/vda rootfstype=ext4 ro panic=-1"))
grubDirectory := filepath.Join(bootDirectory, "grub")
if err := os.WriteFile(filepath.Join(grubDirectory, "grub.cfg"), []byte(configuration), 0o600); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -434,7 +434,7 @@ PREREQ=""
prereqs() { echo "$PREREQ"; }
case "${1:-}" in prereqs) prereqs; exit 0 ;; esac
echo "CHR-KEXEC-LAUNCH" >/dev/console
/sbin/kexec -l /chr-kexec/vmlinuz --initrd=/chr-kexec/writer-initrd.img --append="console=ttyS0 root=/dev/vda rootfstype=ext4 ro panic=-1 chr.install=1"
/sbin/kexec -l /chr-kexec/vmlinuz --initrd=/chr-kexec/writer-initrd.img --append="` + install.WriterCmdline("console=ttyS0 root=/dev/vda rootfstype=ext4 ro panic=-1") + `"
sync
exec /sbin/kexec -e
`
Expand Down Expand Up @@ -705,7 +705,9 @@ exec /sbin/chr-disk-probe %s >/dev/console 2>&1
arguments := []string{
"-machine", "q35,accel=tcg", "-cpu", writerQEMUCPU, "-m", "512", "-nographic", "-no-reboot",
"-kernel", kernel, "-initrd", probeInitrd,
"-append", "console=ttyS0 root=" + targetPath + " rootfstype=ext4 ro panic=-1",
// kho=off for the same reason as install.WriterCmdline: this probe
// boots a large initramfs in 512 MiB.
"-append", "console=ttyS0 root=" + targetPath + " rootfstype=ext4 ro panic=-1 kho=off",
}
arguments = append(arguments, diskArguments...)
process := exec.CommandContext(ctx, "qemu-system-x86_64", arguments...)
Expand Down
Loading