Class: Bootloader::Grub2Base
- Inherits:
-
BootloaderBase
- Object
- BootloaderBase
- Bootloader::Grub2Base
- Includes:
- Yast::I18n, Yast::Logger
- Defined in:
- src/lib/bootloader/grub2base.rb
Overview
Common base for GRUB2 specialized classes rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#console ⇒ Object
Returns the value of attribute console.
-
#grub_default ⇒ Object
Returns the value of attribute grub_default.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pmbr_action ⇒ Object
Returns the value of attribute pmbr_action.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#secure_boot ⇒ Boolean
Current secure boot setting.
-
#stage1 ⇒ Object
Returns the value of attribute stage1.
-
#trusted_boot ⇒ Boolean
Current trusted boot setting.
-
#update_nvram ⇒ Boolean
Current update nvram setting.
Instance Method Summary collapse
- #cpu_mitigations ⇒ Object
- #cpu_mitigations=(value) ⇒ Object
- #disable_serial_console ⇒ Object
- #enable_serial_console(console_arg_string) ⇒ Object
- #explicit_cpu_mitigations ⇒ Object
-
#include_os_prober_package? ⇒ Boolean
Checks if the os-prober package should be included.
-
#initialize ⇒ Grub2Base
constructor
A new instance of Grub2Base.
- #merge(other) ⇒ Object
- #packages ⇒ Object
-
#pmbr_setup(*devices) ⇒ Object
set pmbr flags on boot disks TODO: move it to own place.
- #propose ⇒ Object
- #read ⇒ Object
- #serial_console? ⇒ Boolean
- #write(etc_only: false) ⇒ Object
Methods inherited from BootloaderBase
#prepare, #proposed?, #read?, #summary, #write_sysconfig
Constructor Details
#initialize ⇒ Grub2Base
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
#console ⇒ Object
Returns the value of attribute console.
62 63 64 |
# File 'src/lib/bootloader/grub2base.rb', line 62 def console @console end |
#grub_default ⇒ Object
Returns the value of attribute grub_default.
44 45 46 |
# File 'src/lib/bootloader/grub2base.rb', line 44 def grub_default @grub_default end |
#password ⇒ Object
Returns the value of attribute password.
39 40 41 |
# File 'src/lib/bootloader/grub2base.rb', line 39 def password @password end |
#pmbr_action ⇒ Object
Returns the value of attribute pmbr_action.
46 47 48 |
# File 'src/lib/bootloader/grub2base.rb', line 46 def pmbr_action @pmbr_action end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
41 42 43 |
# File 'src/lib/bootloader/grub2base.rb', line 41 def sections @sections end |
#secure_boot ⇒ Boolean
Returns current secure boot setting.
54 55 56 |
# File 'src/lib/bootloader/grub2base.rb', line 54 def secure_boot @secure_boot end |
#stage1 ⇒ Object
Returns the value of attribute stage1.
66 67 68 |
# File 'src/lib/bootloader/grub2base.rb', line 66 def stage1 @stage1 end |
#trusted_boot ⇒ Boolean
Returns current trusted boot setting.
50 51 52 |
# File 'src/lib/bootloader/grub2base.rb', line 50 def trusted_boot @trusted_boot end |
#update_nvram ⇒ Boolean
Returns 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_mitigations ⇒ Object
98 99 100 |
# File 'src/lib/bootloader/grub2base.rb', line 98 def cpu_mitigations CpuMitigations.from_kernel_params(grub_default.kernel_params) end |
#cpu_mitigations=(value) ⇒ Object
106 107 108 109 110 |
# File 'src/lib/bootloader/grub2base.rb', line 106 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_console ⇒ Object
206 207 208 209 210 |
# File 'src/lib/bootloader/grub2base.rb', line 206 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
195 196 197 198 199 200 201 202 203 204 |
# File 'src/lib/bootloader/grub2base.rb', line 195 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_mitigations ⇒ Object
102 103 104 |
# File 'src/lib/bootloader/grub2base.rb', line 102 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).
191 192 193 |
# File 'src/lib/bootloader/grub2base.rb', line 191 def include_os_prober_package? OsProber.available? end |
#merge(other) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'src/lib/bootloader/grub2base.rb', line 165 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 |
#packages ⇒ Object
178 179 180 181 182 |
# File 'src/lib/bootloader/grub2base.rb', line 178 def packages res = super res << OsProber.package_name if include_os_prober_package? res end |
#pmbr_setup(*devices) ⇒ Object
set pmbr flags on boot disks TODO: move it to own place
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'src/lib/bootloader/grub2base.rb', line 84 def pmbr_setup(*devices) return if @pmbr_action == :nothing action_parted = case @pmbr_action when :add then "on" when :remove then "off" else raise "invalid action #{action}" end devices.each do |dev| Yast::Execute.locally("/usr/sbin/parted", "-s", dev, "disk_set", "pmbr_boot", action_parted) end end |
#propose ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'src/lib/bootloader/grub2base.rb', line 149 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 |
#read ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'src/lib/bootloader/grub2base.rb', line 112 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
212 213 214 |
# File 'src/lib/bootloader/grub2base.rb', line 212 def serial_console? !console.nil? end |
#write(etc_only: false) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'src/lib/bootloader/grub2base.rb', line 136 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 |