Class: Bootloader::Grub2EFI

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

Overview

Represents grub2 bootloader with efi target

Constant Summary

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



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

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



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

def secure_boot
  @secure_boot
end

Instance Method Details

- (Object) merge(other)



65
66
67
68
69
# File 'src/lib/bootloader/grub2efi.rb', line 65

def merge(other)
  super

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

- (Object) name



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

def name
  "grub2-efi"
end

- (Object) packages



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

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 "arm"
    res << "grub2-arm-efi"
  when "aarch64"
    res << "grub2-arm64-efi"
  else
    log.warn "Unknown architecture #{Yast::Arch.architecture} for EFI"
  end

  res
end

- (Object) propose



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

def propose
  super

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

  # non-x86_64 systems don't support secure boot yet (bsc#978157)
  @secure_boot = Yast::Arch.x86_64 ? true : false
  grub_default.generic_set("GRUB_USE_LINUXEFI", Yast::Arch.aarch64 ? "false" : "true")
end

- (Object) read

Read settings from disk overwritting already set values



26
27
28
29
30
# File 'src/lib/bootloader/grub2efi.rb', line 26

def read
  @secure_boot = Sysconfig.from_system.secure_boot

  super
end

- (Object) summary

Display bootloader summary

Returns:

  • a list of summary lines



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

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



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

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"]

    # get underlaying disk as it have to be set there and not on virtual one (bnc#981977)
    device = ::Bootloader::Stage1Device.new(efi_disk)

    pmbr_setup(*device.real_devices)
  end

  @grub_install.execute(secure_boot: @secure_boot)

  true
end

- (Object) write_sysconfig(prewrite: false)

overwrite BootloaderBase version to save secure boot



111
112
113
114
# File 'src/lib/bootloader/grub2efi.rb', line 111

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