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.



64
65
66
67
68
69
70
71
72
73
74
# File 'src/lib/bootloader/grub2base.rb', line 64

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.



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

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



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

def secure_boot
  @secure_boot
end

#stage1Object

Returns the value of attribute stage1.



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

def stage1
  @stage1
end

#update_nvramBoolean

Returns current update nvram setting.

Returns:

  • (Boolean)

    current update nvram setting



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

def update_nvram
  @update_nvram
end

Instance Method Details

#cpu_mitigationsObject

general functions



77
78
79
# File 'src/lib/bootloader/grub2base.rb', line 77

def cpu_mitigations
  CpuMitigations.from_kernel_params(grub_default.kernel_params)
end

#cpu_mitigations=(value) ⇒ Object



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

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



182
183
184
185
186
# File 'src/lib/bootloader/grub2base.rb', line 182

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



171
172
173
174
175
176
177
178
179
180
# File 'src/lib/bootloader/grub2base.rb', line 171

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



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

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.



167
168
169
# File 'src/lib/bootloader/grub2base.rb', line 167

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

#merge(other) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'src/lib/bootloader/grub2base.rb', line 142

def merge(other)
  super

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

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

#packagesObject



154
155
156
157
158
# File 'src/lib/bootloader/grub2base.rb', line 154

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

#proposeObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'src/lib/bootloader/grub2base.rb', line 127

def propose
  super

  propose_os_probing
  propose_terminal
  propose_timeout
  propose_encrypted
  propose_grub_default
  propose_serial
  propose_xen_hypervisor

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

#readObject



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

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.secure_boot = Systeminfo.secure_boot_active?
  self.update_nvram = Systeminfo.update_nvram_active?
end

#serial_console?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'src/lib/bootloader/grub2base.rb', line 188

def serial_console?
  !console.nil?
end

#write(etc_only: false) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'src/lib/bootloader/grub2base.rb', line 114

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