Class: Bootloader::Grub2EFI

Inherits:
Grub2Base show all
Includes:
Yast::Logger
Defined in:
src/lib/bootloader/grub2efi.rb

Overview

Represents grub2 bootloader with efi target

Instance Attribute Summary (collapse)

Attributes inherited from Grub2Base

#grub_default, #password, #pmbr_action, #sections

Instance Method Summary (collapse)

Methods inherited from Grub2Base

#disable_serial_console, #enable_serial_console, #pmbr_setup

Methods inherited from BootloaderBase

#proposed?, #read?

Constructor Details

- (Grub2EFI) initialize

Returns a new instance of Grub2EFI



16
17
18
19
20
21
22
# File 'src/lib/bootloader/grub2efi.rb', line 16

def initialize
  super

  textdomain "bootloader"

  @grub_install = GrubInstall.new(efi: true)
end

Instance Attribute Details

- (Object) secure_boot

Returns the value of attribute secure_boot



14
15
16
# File 'src/lib/bootloader/grub2efi.rb', line 14

def secure_boot
  @secure_boot
end

Instance Method Details

- (Object) merge(other)



63
64
65
66
67
# File 'src/lib/bootloader/grub2efi.rb', line 63

def merge(other)
  super

  @secure_boot = other.secure_boot unless other.secure_boot.nil?
end

- (Object) name



85
86
87
# File 'src/lib/bootloader/grub2efi.rb', line 85

def name
  "grub2-efi"
end

- (Object) packages



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'src/lib/bootloader/grub2efi.rb', line 89

def packages
  res = super

  case Yast::Arch.architecture
  when "i386"
    res << "grub2-i386-efi"
  when "x86_64"
    res << "grub2-x86_64-efi"
    res << "shim" << "mokutil" if @secure_boot
  when "aarch64"
    res << "grub2-arm64-efi"
  else
    log.warn "Unknown architecture #{Yast::Arch.architecture} for EFI"
  end

  res
end

- (Object) propose



53
54
55
56
57
58
59
60
61
# File 'src/lib/bootloader/grub2efi.rb', line 53

def propose
  super

  # for UEFI always remove PMBR flag on disk (bnc#872054)
  self.pmbr_action = :remove

  @secure_boot = true
  grub_default.generic_set("GRUB_USE_LINUXEFI", Yast::Arch.aarch64 ? "false" : "true")
end

- (Boolean) read(reread: false)

Read settings from disk internal data

Parameters:

  • reread (Boolean)

    boolean true to force reread settings from system

Returns:

  • (Boolean)

    true on success



28
29
30
31
32
# File 'src/lib/bootloader/grub2efi.rb', line 28

def read(reread: false)
  @secure_boot = Sysconfig.from_system.secure_boot if reread || @secure_boot.nil?

  super
end

- (Object) summary

Display bootloader summary

Returns:

  • a list of summary lines



72
73
74
75
76
77
78
79
80
81
82
83
# File 'src/lib/bootloader/grub2efi.rb', line 72

def summary
  [
    Yast::Builtins.sformat(
      _("Boot Loader Type: %1"),
      "GRUB2 EFI"
    ),
    Yast::Builtins.sformat(
      _("Enable Secure Boot: %1"),
      @secure_boot ? _("yes") : _("no")
    )
  ]
end

- (Object) write

Write bootloader settings to disk



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'src/lib/bootloader/grub2efi.rb', line 35

def write
  # super have to called as first as grub install require some config writen in ancestor
  super

  if pmbr_action
    efi_partition = Yast::Storage.GetEntryForMountpoint("/boot/efi")["device"]
    efi_partition ||= Yast::Storage.GetEntryForMountpoint("/boot")["device"]
    efi_partition ||= Yast::Storage.GetEntryForMountpoint("/")["device"]
    efi_disk = Yast::Storage.GetDiskPartition(efi_partition)["disk"]

    pmbr_setup(efi_disk)
  end

  @grub_install.execute(secure_boot: @secure_boot)

  true
end

- (Object) write_sysconfig(prewrite: false)

overwrite BootloaderBase version to save secure boot



108
109
110
111
# File 'src/lib/bootloader/grub2efi.rb', line 108

def write_sysconfig(prewrite: false)
  sysconfig = Bootloader::Sysconfig.new(bootloader: name, secure_boot: @secure_boot)
  prewrite ? sysconfig.pre_write : sysconfig.write
end