Class: Bootloader::Grub2Base

Inherits:
BootloaderBase show all
Includes:
Yast::I18n, Yast::Logger
Defined in:
src/lib/bootloader/grub2base.rb

Overview

Common base for GRUB2 specialized classes rubocop:disable Metrics/ClassLength

Direct Known Subclasses

Grub2, Grub2Bls, Grub2EFI

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BootloaderBase

#prepare, #proposed?, #read?, #summary, #write_sysconfig

Constructor Details

#initializeGrub2Base

Returns a new instance of Grub2Base.


68
69
70
71
72
73
74
75
76
77
78
# File 'src/lib/bootloader/grub2base.rb', line 68

def initialize
  super

  textdomain "bootloader"
  @password = ::Bootloader::GRUB2Pwd.new
  @grub_default = ::CFA::Grub2::Default.new
  @sections = ::Bootloader::Sections.new
  @pmbr_action = :nothing
  @explicit_cpu_mitigations = false
  @update_nvram = true
end

Instance Attribute Details

#consoleObject

Returns the value of attribute console.


62
63
64
# File 'src/lib/bootloader/grub2base.rb', line 62

def console
  @console
end

#grub_defaultObject

Returns the value of attribute grub_default.


44
45
46
# File 'src/lib/bootloader/grub2base.rb', line 44

def grub_default
  @grub_default
end

#passwordObject

Returns the value of attribute password.


39
40
41
# File 'src/lib/bootloader/grub2base.rb', line 39

def password
  @password
end

#pmbr_actionObject

Returns the value of attribute pmbr_action.


46
47
48
# File 'src/lib/bootloader/grub2base.rb', line 46

def pmbr_action
  @pmbr_action
end

#sectionsObject (readonly)

Returns the value of attribute sections.


41
42
43
# File 'src/lib/bootloader/grub2base.rb', line 41

def sections
  @sections
end

#secure_bootBoolean

Returns current secure boot setting.

Returns:

  • (Boolean)

    current secure boot setting


54
55
56
# File 'src/lib/bootloader/grub2base.rb', line 54

def secure_boot
  @secure_boot
end

#stage1Object

Returns the value of attribute stage1.


66
67
68
# File 'src/lib/bootloader/grub2base.rb', line 66

def stage1
  @stage1
end

#trusted_bootBoolean

Returns current trusted boot setting.

Returns:

  • (Boolean)

    current trusted boot setting


50
51
52
# File 'src/lib/bootloader/grub2base.rb', line 50

def trusted_boot
  @trusted_boot
end

#update_nvramBoolean

Returns current update nvram setting.

Returns:

  • (Boolean)

    current update nvram setting


58
59
60
# File 'src/lib/bootloader/grub2base.rb', line 58

def update_nvram
  @update_nvram
end

Instance Method Details

#cpu_mitigationsObject

general functions


82
83
84
# File 'src/lib/bootloader/grub2base.rb', line 82

def cpu_mitigations
  CpuMitigations.from_kernel_params(grub_default.kernel_params)
end

#cpu_mitigations=(value) ⇒ Object


90
91
92
93
94
# File 'src/lib/bootloader/grub2base.rb', line 90

def cpu_mitigations=(value)
  log.info "setting mitigations to #{value}"
  @explicit_cpu_mitigations = true
  value.modify_kernel_params(grub_default.kernel_params)
end

#disable_serial_consoleObject


190
191
192
193
194
# File 'src/lib/bootloader/grub2base.rb', line 190

def disable_serial_console
  @console = nil
  grub_default.kernel_params.remove_parameter(serial_console_matcher)
  grub_default.serial_console = ""
end

#enable_serial_console(console_arg_string) ⇒ Object


179
180
181
182
183
184
185
186
187
188
# File 'src/lib/bootloader/grub2base.rb', line 179

def enable_serial_console(console_arg_string)
  @console = SerialConsole.load_from_console_args(console_arg_string)
  raise ::Bootloader::InvalidSerialConsoleArguments unless @console

  grub_default.serial_console = console.console_args

  placer = CFA::ReplacePlacer.new(serial_console_matcher)
  kernel_params = grub_default.kernel_params
  kernel_params.add_parameter("console", console.kernel_args, placer)
end

#explicit_cpu_mitigationsObject


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

def explicit_cpu_mitigations
  @explicit_cpu_mitigations ? cpu_mitigations : nil
end

#include_os_prober_package?Boolean

Checks if the os-prober package should be included.

This default implementation checks if os-prober is supported on the current architecture (all except s/390) and if the package is available (not all products include it).

Returns:

  • (Boolean)

    true if the os-prober package should be included; false otherwise.


175
176
177
# File 'src/lib/bootloader/grub2base.rb', line 175

def include_os_prober_package?
  OsProber.arch_supported? && OsProber.package_available?
end

#merge(other) ⇒ Object


149
150
151
152
153
154
155
156
157
158
159
160
# File 'src/lib/bootloader/grub2base.rb', line 149

def merge(other)
  super

  merge_grub_default(other)
  merge_password(other)
  merge_pmbr_action(other)
  merge_sections(other)

  self.trusted_boot = other.trusted_boot unless other.trusted_boot.nil?
  self.secure_boot = other.secure_boot unless other.secure_boot.nil?
  self.update_nvram = other.update_nvram unless other.update_nvram.nil?
end

#packagesObject


162
163
164
165
166
# File 'src/lib/bootloader/grub2base.rb', line 162

def packages
  res = super
  res << OsProber.package_name if include_os_prober_package?
  res
end

#proposeObject


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'src/lib/bootloader/grub2base.rb', line 133

def propose
  super

  propose_os_probing
  propose_terminal
  propose_timeout
  propose_encrypted
  propose_grub_default
  propose_serial
  propose_xen_hypervisor

  self.trusted_boot = false
  self.secure_boot = Systeminfo.secure_boot_supported?
  self.update_nvram = true
end

#readObject


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'src/lib/bootloader/grub2base.rb', line 96

def read
  super

  begin
    grub_default.load
  rescue Errno::ENOENT
    raise BrokenConfiguration, _("File /etc/default/grub missing on system")
  end

  grub_cfg = CFA::Grub2::GrubCfg.new
  begin
    grub_cfg.load
  rescue Errno::ENOENT
    # there may not need to be grub.cfg generated (bnc#976534),(bsc#1124064)
    log.info "/boot/grub2/grub.cfg is missing. Defaulting to empty one."
  end
  @sections = ::Bootloader::Sections.new(grub_cfg)
  log.info "grub sections: #{@sections.all}"

  self.trusted_boot = Systeminfo.trusted_boot_active?
  self.secure_boot = Systeminfo.secure_boot_active?
  self.update_nvram = Systeminfo.update_nvram_active?
end

#serial_console?Boolean

Returns:

  • (Boolean)

196
197
198
# File 'src/lib/bootloader/grub2base.rb', line 196

def serial_console?
  !console.nil?
end

#write(etc_only: false) ⇒ Object


120
121
122
123
124
125
126
127
128
129
130
131
# File 'src/lib/bootloader/grub2base.rb', line 120

def write(etc_only: false)
  super

  log.info "writing /etc/default/grub #{grub_default.inspect}"
  grub_default.save
  @sections.write
  @password.write
  return if etc_only

  Yast::Execute.on_target("/usr/sbin/grub2-mkconfig", "-o", "/boot/grub2/grub.cfg",
    env: systemwide_locale)
end