Class: Yast::BootloaderClass
- Inherits:
-
Module
- Object
- Module
- Yast::BootloaderClass
- Includes:
- Logger
- Defined in:
- src/modules/Bootloader.rb
Constant Summary
- OLD_API_MAPPING =
{ "true" => :present, "false" => :missing }
- FLAVOR_KERNEL_LINE_MAP =
{ :common => "append", :xen_guest => "xen_append", :xen_host => "xen_kernel_append" }
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.
-
- (Boolean) FlagOnetimeBoot(section)
Set section to boot on next reboot.
-
- (String) getDefaultSection
return default section label.
-
- (String) getLoaderType
Get currently used bootloader, detect if not set yet.
-
- (Boolean) Import(settings)
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.
-
- (Object) UpdateConfiguration
Update read settings to new version of configuration files.
-
- (Boolean) Write
Write bootloader settings to disk.
-
- (Boolean) WriteInstallation
Write bootloader settings during installation.
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
83 84 85 |
# File 'src/modules/Bootloader.rb', line 83 def checkUsedStorage Storage.InitLibstorage(true) || !Mode.normal end |
- (Object) Export
Export bootloader settings to a map
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'src/modules/Bootloader.rb', line 89 def Export ReadOrProposeIfNeeded() out = { "loader_type" => getLoaderType, "initrd" => Initrd.Export, "specific" => blExport, "write_settings" => BootCommon.write_settings, "loader_device" => BootCommon.loader_device, "loader_location" => BootCommon.selected_location } log.info "Exporting settings: #{out}" out end |
- (Boolean) FlagOnetimeBoot(section)
Set section to boot on next reboot
537 538 539 |
# File 'src/modules/Bootloader.rb', line 537 def FlagOnetimeBoot(section) blFlagOnetimeBoot(section) end |
- (String) getDefaultSection
return default section label
415 416 417 418 |
# File 'src/modules/Bootloader.rb', line 415 def getDefaultSection ReadOrProposeIfNeeded() BootCommon.globals["default"] || "" end |
- (String) getLoaderType
Get currently used bootloader, detect if not set yet
530 531 532 |
# File 'src/modules/Bootloader.rb', line 530 def getLoaderType BootCommon.getLoaderType(false) end |
- (Boolean) Import(settings)
Import settings from a map
106 107 108 109 110 111 112 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 |
# File 'src/modules/Bootloader.rb', line 106 def Import(settings) settings = deep_copy(settings) log.info "Importing settings: #{settings}" Reset() BootCommon.was_read = true BootCommon.was_proposed = true BootCommon.changed = true BootCommon.location_changed = true settings["loader_type"] = nil if settings["loader_type"] == "" # if bootloader is not set, then propose it loader_type = settings["loader_type"] || BootCommon.getLoaderType(true) # Explitelly set it to ensure it is installed BootCommon.setLoaderType(loader_type) # import loader_device and selected_location only for bootloaders # that have not phased them out yet BootCommon.loader_device = settings["loader_device"] || "" BootCommon.selected_location = settings["loader_location"] || "custom" # FIXME: obsolete for grub (but inactive through the outer "if" now anyway): # for grub, always correct the bootloader device according to # selected_location (or fall back to value of loader_device) if Arch.i386 || Arch.x86_64 BootCommon.loader_device = BootCommon.GetBootloaderDevice end Initrd.Import(settings["initrd"] || {}) ret = blImport(settings["specific"] || {}) BootCommon.write_settings = settings["write_settings"] || {} ret end |
- (Object) kernel_param(flavor, key)
Gets value for given parameter in kernel parameters for given flavor.
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'src/modules/Bootloader.rb', line 445 def kernel_param(flavor, key) if flavor == :recovery log.warn "Using deprecated recovery flavor" return :missing end ReadOrProposeIfNeeded() # ensure we have some data kernel_line_key = FLAVOR_KERNEL_LINE_MAP[flavor] raise ArgumentError, "Unknown flavor #{flavor}" unless kernel_line_key line = BootCommon.globals[kernel_line_key] values = BootCommon.getKernelParamFromLine(line, key) # map old api response to new one if values.is_a?(Array) # more than one value values else # only one value OLD_API_MAPPING[values] || values end end |
- (Object) main
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'src/modules/Bootloader.rb', line 27 def main Yast.import "UI" textdomain "bootloader" Yast.import "Arch" Yast.import "BootCommon" Yast.import "BootStorage" Yast.import "Installation" Yast.import "Initrd" Yast.import "Kernel" Yast.import "Mode" Yast.import "Progress" Yast.import "Stage" Yast.import "Storage" Yast.import "StorageDevices" Yast.import "Directory" # fate 303395 Yast.import "ProductFeatures" # Write is repeating again # Because of progress bar during inst_finish @repeating_write = false # 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 # UI helping variables Yast.include self, "bootloader/routines/switcher.rb" Yast.include self, "bootloader/routines/popups.rb" # general functions @test_abort = nil end |
- (Boolean) modify_kernel_params(*args)
Modify kernel parameters for installed kernels according to values
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'src/modules/Bootloader.rb', line 491 def modify_kernel_params(*args) values = args.pop if !values.is_a? Hash raise ArgumentError, "Missing parameters to modify #{args.inspect}" end 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 symbols to something that setKernelParamToLine understand remap_values = { :missing => "false", :present => "true" } values.each_key do |key| values[key] = remap_values[values[key]] || values[key] end kernel_lines = args.map do |a| FLAVOR_KERNEL_LINE_MAP[a] || raise(ArgumentError, "Invalid argument #{a.inspect}") end changed = false values.each do |key, value| changed = true if add_kernel_param(kernel_lines, key, value) end return false unless changed BootCommon.globals["__modified"] = "1" BootCommon.changed = true end |
- (Object) Propose
Propose bootloader settings
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'src/modules/Bootloader.rb', line 222 def Propose log.info "Proposing configuration" # always have a current target map available in the log log.info "unfiltered target map: #{Storage.GetTargetMap.inspect}" BootCommon.UpdateInstallationKernelParameters blPropose BootCommon.was_proposed = true BootCommon.changed = true BootCommon.location_changed = true BootCommon.backup_mbr = true log.info "Proposed settings: #{Export()}" nil end |
- (Boolean) Read
Read settings from disk
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'src/modules/Bootloader.rb', line 142 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 getLoaderType # While calling "yast clone_system" and while cloning bootloader # in the AutoYaST module, libStorage has to be set to "normal" # mode in order to read mountpoints correctly. # (bnc#950105) old_mode = Mode.mode if Mode.config Mode.SetMode("normal") StorageDevices.InitDone # Set StorageDevices flag disks_valid to true end BootCommon.DetectDisks Mode.SetMode(old_mode) if old_mode == "autoinst_config" Progress.NextStage return false if testAbort ret = blRead(true, false) BootCommon.was_read = true @old_vga = BootCommon.globals["vgamode"] Progress.Finish return false if testAbort log.debug "Read settings: #{Export()}" ret end |
- (Object) ReadOrProposeIfNeeded
Check whether settings were read or proposed, if not, decide what to do and read or propose settings
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'src/modules/Bootloader.rb', line 543 def ReadOrProposeIfNeeded return if BootCommon.was_read || BootCommon.was_proposed if Mode.config log.info "Not reading settings in Mode::config ()" BootCommon.was_read = true BootCommon.was_proposed = true log.info "But initialize libstorage in readonly mode" # bnc#942360 Storage.InitLibstorage(true) elsif Stage.initial && !Mode.update Propose() else progress_orig = Progress.set(false) Read() Progress.set(progress_orig) if Mode.update UpdateConfiguration() BootCommon.changed = true BootCommon.location_changed = true end end end |
- (Object) Reset
Reset bootloader settings
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'src/modules/Bootloader.rb', line 206 def Reset return if Mode.autoinst log.info "Reseting configuration" BootCommon.was_proposed = false BootCommon.was_read = false BootCommon.loader_device = "" # BootCommon::setLoaderType (nil); BootCommon.changed = false BootCommon.location_changed = false BootCommon.write_settings = {} blReset nil end |
- (Object) Summary
Display bootloader summary
240 241 242 243 244 245 246 247 248 |
# File 'src/modules/Bootloader.rb', line 240 def Summary # kokso: additional warning that root partition is nfs type -> bootloader will not be installed if BootCommon.getBootDisk == "/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 blSummary end |
- (Boolean) testAbort
Check whether abort was pressed
73 74 75 76 |
# File 'src/modules/Bootloader.rb', line 73 def testAbort return false if @test_abort.nil? @test_abort.call end |
- (Boolean) Update
Update the whole configuration
266 267 268 |
# File 'src/modules/Bootloader.rb', line 266 def Update Write() # write also reads the configuration and updates it end |
- (Object) UpdateConfiguration
Update read settings to new version of configuration files
251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'src/modules/Bootloader.rb', line 251 def UpdateConfiguration # first run bootloader-specific update function blUpdate # remove no more needed Kernel modules from /etc/modules-load.d/ ["cdrom", "ide-cd", "ide-scsi"].each do |kernel_module| Kernel.RemoveModuleToLoad(kernel_module) if Kernel.module_to_be_loaded?(kernel_module) end Kernel.SaveModulesToLoad nil end |
- (Boolean) Write
Write bootloader settings to disk
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 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 |
# File 'src/modules/Bootloader.rb', line 272 def Write if @repeating_write BootCommon.was_read = true else ReadOrProposeIfNeeded() end 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 files"), # progress stage, text in dialog (short) _("Install boot loader") ] titles = [ # progress step, text in dialog (short) _("Creating initrd..."), # progress step, text in dialog (short) _("Saving boot loader configuration files..."), # progress step, text in dialog (short) _("Installing boot loader...") ] # 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 params_to_save = {} ret = write_initrd(params_to_save) log.error "Error occurred while creating initrd" unless ret BootCommon.changed = true if Mode.commandline if !(BootCommon.changed || BootCommon.write_settings["initrd_changed_externally"]) log.info "No bootloader cfg. file saving needed, exiting" end if Mode.normal Progress.NextStage else Progress.NextStep if !@repeating_write Progress.Title(titles[1]) end write_sysconfig write_proposed_params(params_to_save) return ret if getLoaderType == "none" # F#300779 - Install diskless client (NFS-root) # kokso: bootloader will not be installed if BootCommon.getBootDisk == "/dev/nfs" log.info "Bootloader::Write() -> Boot partition is nfs type, bootloader will not be installed." return ret end # F#300779 -end # save bootloader settings reinit = !Mode.normal log.info "Reinitialize bootloader library before saving: #{reinit}" ret = blSave(true, reinit, true) && ret log.error "Error before configuration files saving finished" unless ret if Mode.normal Progress.NextStage else Progress.NextStep if !@repeating_write Progress.Title(titles[2]) end # call bootloader executable log.info "Calling bootloader executable" ret &&= blWrite ret = handle_failed_write unless ret ret end |
- (Boolean) WriteInstallation
Write bootloader settings during installation
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'src/modules/Bootloader.rb', line 373 def WriteInstallation log.info "Writing bootloader configuration during installation" mark_as_changed params_to_save = {} ret = write_initrd(params_to_save) log.error "Error occurred while creating initrd" unless ret write_sysconfig write_proposed_params(params_to_save) return ret if getLoaderType == "none" # F#300779 - Install diskless client (NFS-root) # kokso: bootloader will not be installed if BootCommon.getBootDisk == "/dev/nfs" log.info "Bootloader::Write() -> Boot partition is nfs type, bootloader will not be installed." return ret end # F#300779 -end # save bootloader settings reinit = !(Mode.update || Mode.normal) log.info "Reinitialize bootloader library before saving: #{reinit}" ret = blSave(true, reinit, true) && ret log.eror "Error before configuration files saving finished" unless ret # call bootloader executable log.info "Calling bootloader executable" ret &&= blWrite ret = handle_failed_write unless ret ret end |