mirror of
https://github.com/siderolabs/talos.git
synced 2025-12-13 13:31:31 +01:00
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>
This commit is contained in:
parent
594f27d878
commit
bfba3677b0
@ -19,6 +19,8 @@ func FlipBootLabel(e BootLabel) (BootLabel, error) {
|
|||||||
return BootB, nil
|
return BootB, nil
|
||||||
case BootB:
|
case BootB:
|
||||||
return BootA, nil
|
return BootA, nil
|
||||||
|
case BootReset:
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("invalid entry: %s", e)
|
return "", fmt.Errorf("invalid entry: %s", e)
|
||||||
}
|
}
|
||||||
@ -26,13 +28,14 @@ func FlipBootLabel(e BootLabel) (BootLabel, error) {
|
|||||||
|
|
||||||
// ParseBootLabel parses the given human-readable boot label to a grub.BootLabel.
|
// ParseBootLabel parses the given human-readable boot label to a grub.BootLabel.
|
||||||
func ParseBootLabel(name string) (BootLabel, error) {
|
func ParseBootLabel(name string) (BootLabel, error) {
|
||||||
if strings.HasPrefix(name, string(BootA)) {
|
switch {
|
||||||
|
case strings.HasPrefix(name, string(BootA)):
|
||||||
return BootA, nil
|
return BootA, nil
|
||||||
}
|
case strings.HasPrefix(name, string(BootB)):
|
||||||
|
|
||||||
if strings.HasPrefix(name, string(BootB)) {
|
|
||||||
return BootB, nil
|
return BootB, nil
|
||||||
}
|
case strings.HasPrefix(name, "Reset"):
|
||||||
|
return BootReset, nil
|
||||||
|
default:
|
||||||
return "", fmt.Errorf("could not parse boot entry from name: %s", name)
|
return "", fmt.Errorf("could not parse boot entry from name: %s", name)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -13,6 +13,9 @@ const (
|
|||||||
// BootB is a bootloader label.
|
// BootB is a bootloader label.
|
||||||
BootB BootLabel = "B"
|
BootB BootLabel = "B"
|
||||||
|
|
||||||
|
// BootReset is a bootloader label.
|
||||||
|
BootReset BootLabel = "Reset"
|
||||||
|
|
||||||
// ConfigPath is the path to the grub config.
|
// ConfigPath is the path to the grub config.
|
||||||
ConfigPath = constants.BootMountPoint + "/grub/grub.cfg"
|
ConfigPath = constants.BootMountPoint + "/grub/grub.cfg"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -106,6 +106,10 @@ func parseEntries(conf []byte) (map[BootLabel]MenuEntry, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bootEntry == BootReset {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
entries[bootEntry] = MenuEntry{
|
entries[bootEntry] = MenuEntry{
|
||||||
Name: name,
|
Name: name,
|
||||||
Linux: linux,
|
Linux: linux,
|
||||||
|
|||||||
@ -77,6 +77,10 @@ func TestParseBootLabel(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, grub.BootB, label)
|
assert.Equal(t, grub.BootB, label)
|
||||||
|
|
||||||
|
label, err = grub.ParseBootLabel("Reset Talos installation and return to maintenance mode\n")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, grub.BootReset, label)
|
||||||
|
|
||||||
_, err = grub.ParseBootLabel("C - v3")
|
_, err = grub.ParseBootLabel("C - v3")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
@ -94,7 +98,7 @@ func TestWrite(t *testing.T) {
|
|||||||
|
|
||||||
tempFile, _ := os.CreateTemp("", "talos-test-grub-*.cfg")
|
tempFile, _ := os.CreateTemp("", "talos-test-grub-*.cfg")
|
||||||
|
|
||||||
defer os.Remove(tempFile.Name())
|
t.Cleanup(func() { require.NoError(t, os.Remove(tempFile.Name())) })
|
||||||
|
|
||||||
config := grub.NewConfig("cmdline A")
|
config := grub.NewConfig("cmdline A")
|
||||||
|
|
||||||
|
|||||||
@ -20,3 +20,10 @@ menuentry "B - v2" {
|
|||||||
linux /B/vmlinuz cmdline B
|
linux /B/vmlinuz cmdline B
|
||||||
initrd /B/initramfs.xz
|
initrd /B/initramfs.xz
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menuentry "Reset Talos installation and return to maintenance mode" {
|
||||||
|
set gfxmode=auto
|
||||||
|
set gfxpayload=text
|
||||||
|
linux /A/vmlinuz cmdline A talos.experimental.wipe=system:EPHEMERAL,STATE
|
||||||
|
initrd /A/initramfs.xz
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user