kernel: the initramfs script takes over a default-config preset and checks each image (issue 1977, L7-L9)
mesh/delivery merged: source.main moved to novox/mesh-catalog@b9abfde492b2
mesh/check checking f7616c6a9bd4 on b9abfde492b2

Before mkinitcpio -P, a preset naming ALL_config="/etc/mkinitcpio.conf" is copied to the state's
taken-over/ and loses that line (another ALL_config is left and named); after it, an image without
kernel/x86/microcode/ in its first 64 KiB fails the unit and records nothing. The unit may write
/etc/mkinitcpio.d. The README names no node. Tests: 1977/AC7, 1977/AC8; AC3/AC4 fixtures write images.

Builds: L7, L8, L9 (issue 1977 note 4)
This commit is contained in:
2026-11-12 21:31:05 +01:00
parent 62c0eb90cb
commit f7616c6a9b
4 changed files with 89 additions and 14 deletions
@@ -58,30 +58,35 @@ func TestAC2TheDropInAddsMicrocodeToHooksOnce(t *testing.T) {
}
}
type initBed struct{ script, dropin, state, runs, bin string }
type initBed struct{ script, dropin, state, runs, bin, presets, boot string }
func newInitBed(t *testing.T, mkinitcpioExit string) initBed {
t.Helper()
dir := t.TempDir()
b := initBed{script: filepath.Join(dir, "initramfs"), dropin: filepath.Join(dir, "mesh-microcode.conf"), state: filepath.Join(dir, "state"),
runs: filepath.Join(dir, "runs"), bin: filepath.Join(dir, "bin")}
for _, d := range []string{b.state, b.bin} {
runs: filepath.Join(dir, "runs"), bin: filepath.Join(dir, "bin"), presets: filepath.Join(dir, "presets"), boot: filepath.Join(dir, "boot")}
for _, d := range []string{b.state, b.bin, b.presets, b.boot} {
if err := os.MkdirAll(d, 0o755); err != nil {
t.Fatal(err)
}
}
content := strings.ReplaceAll(manifest(t).resource(t, "initramfs").text(t), "${dir:state}", b.state)
if strings.Contains(content, "${dir") {
if strings.Contains(content, "${") {
t.Fatal("a substitution is left in the script")
}
write(t, b.script, content, 0o755)
write(t, b.dropin, "HOOKS+=(microcode)\n", 0o644)
write(t, filepath.Join(b.bin, "mkinitcpio"), "#!/bin/sh\necho \"$@\" >>"+b.runs+"\nexit "+mkinitcpioExit+"\n", 0o755)
// the stand-in mkinitcpio writes an image whose early archive holds microcode.
b.mkinitcpio(t, "kernel/x86/microcode/AuthenticAMD.bin", mkinitcpioExit)
return b
}
func (b initBed) mkinitcpio(t *testing.T, early, exit string) {
write(t, filepath.Join(b.bin, "mkinitcpio"), "#!/bin/sh\necho \"$@\" >>"+b.runs+"\nprintf '070701%s\\0' "+early+" >"+b.boot+"/initramfs-linux.img\nexit "+exit+"\n", 0o755)
}
func (b initBed) run(t *testing.T) (string, error) {
cmd := exec.Command("sh", b.script, "apply", b.dropin, b.state)
cmd := exec.Command("sh", b.script, "apply", b.dropin, b.state, b.presets, b.boot)
cmd.Env = append(os.Environ(), "PATH="+b.bin+string(os.PathListSeparator)+os.Getenv("PATH"))
out, err := cmd.CombinedOutput()
return string(out), err
@@ -148,3 +153,38 @@ func TestAC5KernelBootNamesTheRunningMicrocodeAndWhichImagesCarryIt(t *testing.T
t.Fatalf("unreadable: %+v", got)
}
}
// 1977/AC7
func TestAC7ADefaultConfigPresetIsTakenOverAndAnotherIsLeftAndNamed(t *testing.T) {
b := newInitBed(t, "0")
preset := "ALL_kver=\"/boot/vmlinuz-linux\"\nALL_config=\"/etc/mkinitcpio.conf\"\nPRESETS=('default')\n"
write(t, filepath.Join(b.presets, "linux.preset"), preset, 0o644)
other := "ALL_config=\"/etc/other.conf\"\nPRESETS=('default')\n"
write(t, filepath.Join(b.presets, "linux-lts.preset"), other, 0o644)
out, err := b.run(t)
if err != nil {
t.Fatalf("%v %s", err, out)
}
if got, _ := os.ReadFile(filepath.Join(b.presets, "linux.preset")); string(got) != "ALL_kver=\"/boot/vmlinuz-linux\"\nPRESETS=('default')\n" {
t.Fatalf("preset: %q", got)
}
if got, _ := os.ReadFile(filepath.Join(b.state, "taken-over", "linux.preset")); string(got) != preset {
t.Fatalf("copy: %q", got)
}
if got, _ := os.ReadFile(filepath.Join(b.presets, "linux-lts.preset")); string(got) != other || !strings.Contains(out, "linux-lts.preset sets ALL_config=\"/etc/other.conf\"") {
t.Fatalf("other: %q %s", got, out)
}
}
// 1977/AC8
func TestAC8AnImageWithoutMicrocodeFailsTheUnitNamesItAndRecordsNothing(t *testing.T) {
b := newInitBed(t, "0")
b.mkinitcpio(t, "early/other.bin", "0")
out, err := b.run(t)
if err == nil || !strings.Contains(out, "initramfs-linux.img") {
t.Fatalf("%v %s", err, out)
}
if _, err := os.Stat(filepath.Join(b.state, "initramfs-built")); !os.IsNotExist(err) {
t.Fatalf("recorded: %v", err)
}
}