Skip to content

Commit eee9f5d

Browse files
Dmitriy Matrenichevsmira
authored andcommitted
chore: handle grub option - "wipe"
This PR ensures that we can handle third grub option - "wipe". We will use it in 1.4. For #6842 Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com> (cherry picked from commit bfba367)
1 parent 7f2d043 commit eee9f5d

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/boot_label.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,23 @@ func FlipBootLabel(e BootLabel) (BootLabel, error) {
1919
return BootB, nil
2020
case BootB:
2121
return BootA, nil
22+
case BootReset:
23+
fallthrough
2224
default:
2325
return "", fmt.Errorf("invalid entry: %s", e)
2426
}
2527
}
2628

2729
// ParseBootLabel parses the given human-readable boot label to a grub.BootLabel.
2830
func ParseBootLabel(name string) (BootLabel, error) {
29-
if strings.HasPrefix(name, string(BootA)) {
31+
switch {
32+
case strings.HasPrefix(name, string(BootA)):
3033
return BootA, nil
31-
}
32-
33-
if strings.HasPrefix(name, string(BootB)) {
34+
case strings.HasPrefix(name, string(BootB)):
3435
return BootB, nil
36+
case strings.HasPrefix(name, "Reset"):
37+
return BootReset, nil
38+
default:
39+
return "", fmt.Errorf("could not parse boot entry from name: %s", name)
3540
}
36-
37-
return "", fmt.Errorf("could not parse boot entry from name: %s", name)
3841
}

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const (
1313
// BootB is a bootloader label.
1414
BootB BootLabel = "B"
1515

16+
// BootReset is a bootloader label.
17+
BootReset BootLabel = "Reset"
18+
1619
// ConfigPath is the path to the grub config.
1720
ConfigPath = constants.BootMountPoint + "/grub/grub.cfg"
1821
)

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/decode.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ func parseEntries(conf []byte) (map[BootLabel]MenuEntry, error) {
106106
return nil, err
107107
}
108108

109+
if bootEntry == BootReset {
110+
continue
111+
}
112+
109113
entries[bootEntry] = MenuEntry{
110114
Name: name,
111115
Linux: linux,

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/grub_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ func TestParseBootLabel(t *testing.T) {
7777
assert.NoError(t, err)
7878
assert.Equal(t, grub.BootB, label)
7979

80+
label, err = grub.ParseBootLabel("Reset Talos installation and return to maintenance mode\n")
81+
assert.NoError(t, err)
82+
assert.Equal(t, grub.BootReset, label)
83+
8084
_, err = grub.ParseBootLabel("C - v3")
8185
assert.Error(t, err)
8286
}
@@ -94,7 +98,7 @@ func TestWrite(t *testing.T) {
9498

9599
tempFile, _ := os.CreateTemp("", "talos-test-grub-*.cfg")
96100

97-
defer os.Remove(tempFile.Name())
101+
t.Cleanup(func() { require.NoError(t, os.Remove(tempFile.Name())) })
98102

99103
config := grub.NewConfig("cmdline A")
100104

internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub/testdata/grub_parse_test.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ menuentry "B - v2" {
2020
linux /B/vmlinuz cmdline B
2121
initrd /B/initramfs.xz
2222
}
23+
24+
menuentry "Reset Talos installation and return to maintenance mode" {
25+
set gfxmode=auto
26+
set gfxpayload=text
27+
linux /A/vmlinuz cmdline A talos.experimental.wipe=system:EPHEMERAL,STATE
28+
initrd /A/initramfs.xz
29+
}

0 commit comments

Comments
 (0)