Class: Yast::BootloaderClass
- Inherits:
-
Module
- Object
- Module
- Yast::BootloaderClass
- Includes:
- Logger
- Defined in:
- src/modules/Bootloader.rb
Constant Summary
- BOOLEAN_MAPPING =
{ true => :present, false => :missing }.freeze
- FLAVOR_KERNEL_LINE_MAP =
{ :common => "append", :xen_guest => "xen_append", :xen_host => "xen_kernel_append" }.freeze
Instance Method Summary (collapse)
-
- (Boolean) checkUsedStorage
bnc #419197 yast2-bootloader does not correctly initialise libstorage Function try initialize yast2-storage if other module used it then don't continue with initialize.
-
- (Object) Export
Export bootloader settings to a map.
-
- (String) getDefaultSection
return default section label.
-
- (String) getLoaderType
Get currently used bootloader, detect if not set yet.
-
- (Boolean) Import(data)
Import settings from a map.
-
- (Object) kernel_param(flavor, key)
Gets value for given parameter in kernel parameters for given flavor.
- - (Object) main
-
- (Boolean) modify_kernel_params(*args)
Modify kernel parameters for installed kernels according to values.
-
- (Object) Propose
Propose bootloader settings.
-
- (Boolean) Read
Read settings from disk.
-
- (Object) ReadOrProposeIfNeeded
Check whether settings were read or proposed, if not, decide what to do and read or propose settings.
-
- (Object) Reset
Reset bootloader settings.
-
- (Object) Summary
Display bootloader summary.
-
- (Boolean) testAbort
Check whether abort was pressed.
-
- (Boolean) Update
Update the whole configuration.
-
- (Boolean) Write
Write bootloader settings to disk.
Instance Method Details
- (Boolean) checkUsedStorage
bnc #419197 yast2-bootloader does not correctly initialise libstorage Function try initialize yast2-storage if other module used it then don't continue with initialize
71 72 73 |
# File 'src/modules/Bootloader.rb', line 71 def checkUsedStorage Storage.InitLibstorage(true) || !Mode.normal end |
- (Object) Export
Export bootloader settings to a map
77 78 79 80 81 82 83 84 85 86 87 |
# File 'src/modules/Bootloader.rb', line 77 def Export Yast::BootStorage.detect_disks config = ::Bootloader::BootloaderFactory.current config.read if !config.read? && !config.proposed? result = ::Bootloader::AutoyastConverter.export(config) log.info "autoyast map for bootloader: #{result.inspect}" result end |
- (String) getDefaultSection
return default section label
259 260 261 262 263 264 265 |
# File 'src/modules/Bootloader.rb', line 259 def getDefaultSection ReadOrProposeIfNeeded() bootloader = Bootloader::BootloaderFactory.current return "" unless bootloader.respond_to?(:sections) bootloader.sections.default end |
- (String) getLoaderType
Get currently used bootloader, detect if not set yet
399 400 401 |
# File 'src/modules/Bootloader.rb', line 399 def getLoaderType ::Bootloader::BootloaderFactory.current.name end |
- (Boolean) Import(data)
Import settings from a map
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'src/modules/Bootloader.rb', line 92 def Import(data) # AutoYaST configuration mode. There is no access to the system Yast::BootStorage.detect_disks factory = ::Bootloader::BootloaderFactory imported_configuration = ::Bootloader::AutoyastConverter.import(data) factory.clear_cache proposed_configuration = factory.bootloader_by_name(imported_configuration.name) unless Mode.config # no AutoYaST configuration mode proposed_configuration.propose proposed_configuration.merge(imported_configuration) end factory.current = proposed_configuration true end |
- (Object) kernel_param(flavor, key)
Gets value for given parameter in kernel parameters for given flavor.
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'src/modules/Bootloader.rb', line 292 def kernel_param(flavor, key) if flavor == :recovery log.warn "Using deprecated recovery flavor" return :missing end ReadOrProposeIfNeeded() # ensure we have some data current_bl = ::Bootloader::BootloaderFactory.current # currently only grub2 bootloader supported return :missing unless current_bl.respond_to?(:grub_default) grub_default = current_bl.grub_default params = case flavor when :common then grub_default.kernel_params when :xen_guest then grub_default.xen_kernel_params when :xen_host then grub_default.xen_hypervisor_params else raise ArgumentError, "Unknown flavor #{flavor}" end res = params.parameter(key) BOOLEAN_MAPPING[res] || res end |
- (Object) main
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'src/modules/Bootloader.rb', line 40 def main textdomain "bootloader" # installation proposal help variables # Configuration was changed during inst. proposal if true @proposed_cfg_changed = false # old vga value handling function # old value of vga parameter of default bootloader section @old_vga = nil # general functions @test_abort = nil end |
- (Boolean) modify_kernel_params(*args)
Modify kernel parameters for installed kernels according to values
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'src/modules/Bootloader.rb', line 340 def modify_kernel_params(*args) ReadOrProposeIfNeeded() # ensure we have data to modify current_bl = ::Bootloader::BootloaderFactory.current # currently only grub2 bootloader supported return :missing unless current_bl.respond_to?(:grub_default) grub_default = current_bl.grub_default values = args.pop raise ArgumentError, "Missing parameters to modify #{args.inspect}" if !values.is_a? Hash args = [:common] if args.empty? # by default change common kernels only args = args.first if args.first.is_a? Array # support array like syntax if args.include?(:recovery) args.delete(:recovery) log.warn "recovery flavor is deprecated and not set" end remap_values = BOOLEAN_MAPPING.invert values.each_key do |key| values[key] = remap_values[values[key]] if remap_values.key?(values[key]) end params = args.map do |flavor| case flavor when :common then grub_default.kernel_params when :xen_guest then grub_default.xen_kernel_params when :xen_host then grub_default.xen_hypervisor_params else raise ArgumentError, "Unknown flavor #{flavor}" end end changed = false values.each do |key, value| params.each do |param| old_val = param.parameter(key) next if old_val == value changed = true # at first clean old entries matcher = CFA::Matcher.new(key: key) param.remove_parameter(matcher) case value when false then next # already done when true then param.add_parameter(key, value) when Array value.each { |val| param.add_parameter(key, val) } else param.add_parameter(key, value) end end end changed end |
- (Object) Propose
Propose bootloader settings
178 179 180 181 182 183 184 185 186 187 |
# File 'src/modules/Bootloader.rb', line 178 def Propose log.info "Proposing configuration" # always have a current target map available in the log log.info "unfiltered target map: #{Storage.GetTargetMap.inspect}" ::Bootloader::BootloaderFactory.current.propose log.info "Proposed settings: #{Export()}" nil end |
- (Boolean) Read
Read settings from disk
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'src/modules/Bootloader.rb', line 113 def Read log.info "Reading configuration" # run Progress bar stages = [ # progress stage, text in dialog (short, infinitiv) _("Check boot loader"), # progress stage, text in dialog (short, infinitiv) _("Read partitioning"), # progress stage, text in dialog (short, infinitiv) _("Load boot loader settings") ] titles = [ # progress step, text in dialog (short) _("Checking boot loader..."), # progress step, text in dialog (short) _("Reading partitioning..."), # progress step, text in dialog (short) _("Loading boot loader settings...") ] # dialog header Progress.New( _("Initializing Boot Loader Configuration"), " ", 3, stages, titles, "" ) Progress.NextStage return false if testAbort Progress.NextStage return false if !checkUsedStorage BootStorage.detect_disks Progress.NextStage return false if testAbort ::Bootloader::BootloaderFactory.current.read Progress.Finish true end |
- (Object) ReadOrProposeIfNeeded
Check whether settings were read or proposed, if not, decide what to do and read or propose settings
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'src/modules/Bootloader.rb', line 405 def ReadOrProposeIfNeeded current_bl = ::Bootloader::BootloaderFactory.current return if current_bl.read? || current_bl.proposed? if Mode.config log.info "Initialize libstorage in readonly mode" # bnc#942360 Storage.InitLibstorage(true) log.info "Not reading settings in Mode::config ()" Propose() elsif Stage.initial && !Mode.update Propose() else progress_orig = Progress.set(false) Read() Progress.set(progress_orig) end end |
- (Object) Reset
Reset bootloader settings
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'src/modules/Bootloader.rb', line 161 def Reset return if Mode.autoinst log.info "Resetting configuration" ::Bootloader::BootloaderFactory.clear_cache if Stage.initial config = ::Bootloader::BootloaderFactory.proposed config.propose else config = ::Bootloader::BootloaderFactory.system config.read end ::Bootloader::BootloaderFactory.current = config nil end |
- (Object) Summary
Display bootloader summary
191 192 193 194 195 196 197 198 199 |
# File 'src/modules/Bootloader.rb', line 191 def Summary # kokso: additional warning that root partition is nfs type -> bootloader will not be installed if BootStorage.disk_with_boot_partition == "/dev/nfs" log.info "Bootloader::Summary() -> Boot partition is nfs type, bootloader will not be installed." return _("The boot partition is of type NFS. Bootloader cannot be installed.") end ::Bootloader::BootloaderFactory.current.summary end |
- (Boolean) testAbort
Check whether abort was pressed
60 61 62 63 64 |
# File 'src/modules/Bootloader.rb', line 60 def testAbort return false if Mode.commandline UI.PollInput == :abort end |
- (Boolean) Update
Update the whole configuration
203 204 205 |
# File 'src/modules/Bootloader.rb', line 203 def Update Write() # write also reads the configuration and updates it end |
- (Boolean) Write
Write bootloader settings to disk
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'src/modules/Bootloader.rb', line 209 def Write ReadOrProposeIfNeeded() mark_as_changed log.info "Writing bootloader configuration" # run Progress bar stages = [ # progress stage, text in dialog (short) _("Create initrd"), # progress stage, text in dialog (short) _("Save boot loader configuration") ] titles = [ # progress step, text in dialog (short) _("Creating initrd..."), # progress step, text in dialog (short) _("Saving boot loader configuration...") ] # progress bar caption if Mode.normal # progress line Progress.New( _("Saving Boot Loader Configuration"), " ", stages.size, stages, titles, "" ) Progress.NextStage else Progress.Title(titles[0]) end ret = write_initrd log.error "Error occurred while creating initrd" unless ret Progress.NextStep Progress.Title(titles[1]) unless Mode.normal ::Bootloader::BootloaderFactory.current.write true end |