Class: Yast::BootCommonClass
- Inherits:
-
Module
- Object
- Module
- Yast::BootCommonClass
- Defined in:
- src/modules/BootCommon.rb
Constant Summary
- SUPPORTED_BOOTLOADERS =
[ "none", # allow user to manage bootloader itself "grub2", "grub2-efi" ]
Instance Method Summary (collapse)
- - (Boolean) boot_efi?
-
- (Object) Export
Export bootloader settings to a map.
-
- (Object) getBootloaders
List bootloaders available for configured architecture.
-
- (String) getLoaderType(recheck)
Get currently used bootloader, detect if not set yet.
- - (Object) getSystemSecureBootStatus(recheck)
-
- (Boolean) Import(settings)
Import settings from a map.
- - (Object) main
-
- (Object) Md2Partitions(md_device)
FIXME: just backward compatible interface, call directly BootStorage.
-
- (Object) Propose
Propose bootloader settings.
-
- (Boolean) Read(reread, avoid_reading_device_map)
Read settings from disk internal data.
-
- (Object) Reset
Reset bootloader settings.
-
- (Boolean) Save(_clean, init, flush)
Save all bootloader configuration files to the cache of the PlugLib PlugLib must be initialized properly !!!.
-
- (Object) setCurrentLoaderAttribs(loader_type)
Set attributes of specified bootloader to variable containing attributes of currently used bootloader, call its initializer.
-
- (Object) setLoaderType(bootloader)
set type of bootloader.
- - (Object) setSystemSecureBootStatus(enable)
-
- (Object) Summary
Display bootloader summary.
-
- (String) SupportedLoader(loader)
Check whether loader with specified name is supported.
-
- (Object) Update
Update read settings to new version of configuration files.
-
- (Boolean) VerifyMDArray
FATE#305008: Failover boot configurations for md arrays with redundancy Verify if proposal includes md array with more diferent disks.
-
- (Boolean) Write
Write bootloader settings to disk.
Instance Method Details
- (Boolean) boot_efi?
369 370 371 372 373 374 375 376 |
# File 'src/modules/BootCommon.rb', line 369 def boot_efi? if Mode.live_installation SCR.Execute(path(".target.bash_output"), "modprobe efivars >/dev/null 2>&1") return FileUtils.Exists("/sys/firmware/efi/systab") else return Linuxrc.InstallInf("EFI") == "1" end end |
- (Object) Export
Export bootloader settings to a map
151 152 153 154 155 156 157 158 159 |
# File 'src/modules/BootCommon.rb', line 151 def Export exp = { "global" => remapGlobals(@globals), "device_map" => BootStorage.device_map.remapped_hash } exp["activate"] = @activate if @loader_type != "grub2" exp end |
- (Object) getBootloaders
List bootloaders available for configured architecture
487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'src/modules/BootCommon.rb', line 487 def getBootloaders if Mode.config # default means bootloader use what it think is the best return SUPPORTED_BOOTLOADERS + ["default"] end ret = [getLoaderType(false)] ret << "grub2" unless Arch.aarch64 # grub2 everywhere except aarch64 ret << "grub2-efi" if Arch.x86_64 || Arch.aarch64 ret << "none" # avoid double entry for selected one ret.uniq end |
- (String) getLoaderType(recheck)
Get currently used bootloader, detect if not set yet
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 412 413 414 415 416 417 |
# File 'src/modules/BootCommon.rb', line 381 def getLoaderType(recheck) return @loader_type if !recheck && @loader_type # read bootloader to use from disk if Mode.update || Mode.normal || Mode.repair sysconfig = ::Bootloader::Sysconfig.from_system @loader_type = sysconfig.bootloader if @loader_type && !@loader_type.empty? @loader_type = "grub2" if @loader_type == "s390" Builtins.y2milestone( "Sysconfig bootloader is %1, using", @loader_type ) @loader_type = SupportedLoader(@loader_type) Builtins.y2milestone( "Sysconfig bootloader is %1, using", @loader_type ) setCurrentLoaderAttribs(@loader_type) return @loader_type end end # detect bootloader @loader_type = SCR.Read(path(".probe.boot_arch")) # s390,ppc and also old grub now uses grub2 (fate #315753) @loader_type = "grub2" if ["s390", "ppc", "grub"].include? @loader_type Builtins.y2milestone("Bootloader detection returned %1", @loader_type) if (Arch.i386 || Arch.x86_64 || Arch.aarch64) && boot_efi? # use grub2-efi as default bootloader for x86_64/i386/aarch64 EFI @loader_type = "grub2-efi" end @loader_type = SupportedLoader(@loader_type) Builtins.y2milestone("Detected bootloader %1", @loader_type) setCurrentLoaderAttribs(@loader_type) @loader_type end |
- (Object) getSystemSecureBootStatus(recheck)
464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'src/modules/BootCommon.rb', line 464 def getSystemSecureBootStatus(recheck) return @secure_boot if !recheck && !@secure_boot.nil? if Mode.update || Mode.normal || Mode.repair @secure_boot = ::Bootloader::Sysconfig.from_system.secure_boot else # propose secure boot always to true on x86 (bnc#872054), otherwise respect user choice @secure_boot = Arch.i386 || Arch.x86_64 end @secure_boot end |
- (Boolean) Import(settings)
Import settings from a map
164 165 166 167 168 169 170 171 172 173 |
# File 'src/modules/BootCommon.rb', line 164 def Import(settings) settings = deep_copy(settings) @globals = Ops.get_map(settings, "global", {}) if @loader_type != "grub2" @activate = Ops.get_boolean(settings, "activate", false) end BootStorage.device_map = ::Bootloader::DeviceMap.new(settings["device_map"] || {}) true end |
- (Object) main
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 139 140 141 142 143 144 145 |
# File 'src/modules/BootCommon.rb', line 33 def main Yast.import "Pkg" Yast.import "UI" textdomain "bootloader" Yast.import "Arch" Yast.import "HTML" Yast.import "Mode" Yast.import "PackageSystem" Yast.import "Storage" Yast.import "PackagesProposal" Yast.import "BootStorage" Yast.import "Linuxrc" # General bootloader settings # map of global options and values @globals = {} # list of section @sections = [] # Saved change time from target map - proposal @cached_settings_base_data_change_time = nil # device to save loader stage 1 to # NOTE: this variable is being phased out. The boot_* keys in the globals map # are now used to remember the selected boot location. Thus, we now have a # list of selected loader devices. It can be generated from the information in # the boot_* keys and the global variables (Boot|Root|Extended)PartitionDevice # and mbrDisk by calling GetBootloaderDevices(). # FIXME: need remove to read only loader location from perl-Bootloader @loader_device = nil # proposal helping variables # The kind of bootloader location that the user selected last time he went to # the dialog. Used as a hint next time a proposal is requested, so the # proposal can try to satisfy the user's previous preference. # NOTE: this variable is being phased out. The boot_* keys in the globals map # will be used to remember the last selected location. # Currently, valid values are: mbr, boot, root, mbr_md, none # FIXME: need remove to read only loader location from perl-Bootloader @selected_location = nil # These global variables and functions are needed in included files # Parameters of currently used bootloader @current_bootloader_attribs = {} # Parameters of all bootloaders @bootloader_attribs = {} # device holding MBR for bootloader @mbrDisk = "" # Backup original MBR before installing bootloader @backup_mbr = false # Activate bootloader partition during installation? @activate = false # action to do with pbmr flag on boot disk # values are :add, :remove or nil, means do nothing @pmbr_action = nil # were settings changed (== true) @changed = false # common variables # type of bootloader to configure/being configured # shall be one of "grub2", "grub2-efi" @loader_type = nil @secure_boot = nil # saving mode setting functions # map of save mode settings @write_settings = {} # other variables # bootloader installation variables # Was the activate flag changed by user? @activate_changed = false # Save everything, not only changed settings @save_all = false # state variables # was the propose function called (== true) @was_proposed = false # Were module settings read (== true) @was_read = false # Was bootloader location changed? (== true) @location_changed = false # FATE#305008: Failover boot configurations for md arrays with redundancy # if true enable redundancy for md array @enable_md_array_redundancy = nil # help message and dscription definitions Yast.include self, "bootloader/routines/popups.rb" Yast.include self, "bootloader/routines/misc.rb" # FIXME: there are other archs than i386, this is not 'commmon' Yast.include self, "bootloader/routines/lilolike.rb" Yast.include self, "bootloader/routines/lib_iface.rb" end |
- (Object) Md2Partitions(md_device)
FIXME: just backward compatible interface, call directly BootStorage
517 518 519 |
# File 'src/modules/BootCommon.rb', line 517 def Md2Partitions(md_device) BootStorage.Md2Partitions(md_device) end |
- (Object) Propose
Propose bootloader settings
222 223 224 225 226 |
# File 'src/modules/BootCommon.rb', line 222 def Propose Builtins.y2error("No generic propose function available") nil end |
- (Boolean) Read(reread, avoid_reading_device_map)
Read settings from disk internal data
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'src/modules/BootCommon.rb', line 180 def Read(reread, avoid_reading_device_map) bl = getLoaderType(false) return true if bl == "none" InitializeLibrary(reread, bl) ReadFiles(avoid_reading_device_map) if reread @sections = GetSections() @globals = GetGlobal() dev_map = GetDeviceMap() # convert device names in device map to the kernel device names dev_map = Builtins.mapmap(dev_map) do |k, v| { ::Bootloader::UdevMapping.to_mountby_device(k) => v } end BootStorage.device_map = ::Bootloader::DeviceMap.new(dev_map) # convert custom boot device names in globals to the kernel device names # also, for legacy bootloaders like LILO that still pass device names, # convert the stage1_dev @globals = Builtins.mapmap(@globals) do |k, v| if k == "stage1_dev" || Builtins.regexpmatch(k, "^boot_.*custom$") next { k => ::Bootloader::UdevMapping.to_kernel_device(v) } else next { k => v } end end true end |
- (Object) Reset
Reset bootloader settings
211 212 213 214 215 216 217 218 219 |
# File 'src/modules/BootCommon.rb', line 211 def Reset @sections = [] @globals = {} @activate = false @activate_changed = false @was_proposed = false nil end |
- (Boolean) Save(_clean, init, flush)
Save all bootloader configuration files to the cache of the PlugLib PlugLib must be initialized properly !!!
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 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 |
# File 'src/modules/BootCommon.rb', line 235 def Save(_clean, init, flush) ret = true bl = getLoaderType(false) InitializeLibrary(init, bl) return true if bl == "none" # bnc#589433 - Install grub into root (/) partition gives error @globals.delete("boot_custom") if @globals["boot_custom"] == "" # FIXME: give mountby information to perl-Bootloader (or define some # better interface), so that perl-Bootloader can use mountby device names # for these devices instead. Tracked in bug #248162. # convert custom boot device names in globals to the device names # indicated by "mountby" # also, for legacy bootloaders like LILO that still pass device names, # convert the stage1_dev my_globals = Builtins.mapmap(@globals) do |k, v| if k == "stage1_dev" || Builtins.regexpmatch(k, "^boot_.*custom$") next { k => ::Bootloader::UdevMapping.to_mountby_device(v) } else next { k => v } end end # convert device names in device map to the device names indicated by # "mountby" Builtins.y2milestone( "device map before mapping #{BootStorage.device_map}" ) my_device_mapping = Builtins.mapmap(BootStorage.device_map.to_hash) do |k, v| { ::Bootloader::UdevMapping.to_mountby_device(k) => v } end Builtins.y2milestone("device map after mapping %1", my_device_mapping) if VerifyMDArray() if !@enable_md_array_redundancy my_globals.delete("boot_md_mbr") elsif !my_globals["boot_md_mbr"] my_globals["boot_md_mbr"] = BootStorage.devices_for_redundant_boot.join(",") end else my_globals.delete("boot_md_mbr") end Builtins.y2milestone("SetSecureBoot %1", @secure_boot) ret &&= SetSecureBoot(@secure_boot) ret &&= DefineMultipath(BootStorage.multipath_mapping) ret &&= SetDeviceMap(my_device_mapping) ret &&= SetSections(@sections) ret &&= SetGlobal(my_globals) ret &&= CommitSettings() if flush # write settings to /etc/sysconfig/bootloader sysconf = ::Bootloader::Sysconfig.new(bootloader: bl, secure_boot: @secure_boot) sysconf.write ret end |
- (Object) setCurrentLoaderAttribs(loader_type)
Set attributes of specified bootloader to variable containing attributes of currently used bootloader, call its initializer
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 |
# File 'src/modules/BootCommon.rb', line 335 def setCurrentLoaderAttribs(loader_type) Builtins.y2milestone("Setting attributes for bootloader %1", loader_type) if !loader_type Builtins.y2error("Setting loader type to nil, this is wrong") return end # FIXME: this should be blInitializer in switcher.ycp for code cleanness # and understandability boot_initializer = Ops.get(@bootloader_attribs, [loader_type, "initializer"]) if boot_initializer Builtins.y2milestone("Running bootloader initializer") boot_initializer.call Builtins.y2milestone("Initializer finished") else Builtins.y2error("No initializer found for >>%1<<", loader_type) @current_bootloader_attribs = {} end @current_bootloader_attribs = Builtins.union( @current_bootloader_attribs, Builtins.eval(Ops.get(@bootloader_attribs, loader_type, {})) ) nil end |
- (Object) setLoaderType(bootloader)
set type of bootloader
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'src/modules/BootCommon.rb', line 421 def setLoaderType(bootloader) if !bootloader Builtins.y2milestone("Resetting the loader type") @loader_type = nil return end Builtins.y2milestone("Setting bootloader to >>%1<<", bootloader) raise "Unsupported bootloader '#{bootloader}'" unless SUPPORTED_BOOTLOADERS.include?(bootloader) bootloader_packages = Ops.get_list( @bootloader_attribs, [bootloader, "required_packages"], [] ) # added kexec-tools fate# 303395 # if kexec option is equal 0 or running live installation # doesn't install kexec-tools if !Mode.live_installation && Linuxrc.InstallInf("kexec_reboot") != "0" bootloader_packages = Builtins.add(bootloader_packages, "kexec-tools") end # we need perl-Bootloader-YAML API to communicate with pbl bootloader_packages << "perl-Bootloader-YAML" Builtins.y2milestone("Bootloader packages: %1", bootloader_packages) # don't configure package manager during autoinstallation preparing if Mode.normal PackageSystem.InstallAll(bootloader_packages) elsif Stage.initial bootloader_packages.each do |p| Builtins.y2milestone("Select bootloader package: %1", p) PackagesProposal.AddResolvables("yast2-bootloader", :package, [p]) end end @loader_type = bootloader setCurrentLoaderAttribs(@loader_type) Builtins.y2milestone("Loader type set") nil end |
- (Object) setSystemSecureBootStatus(enable)
477 478 479 480 481 482 483 |
# File 'src/modules/BootCommon.rb', line 477 def setSystemSecureBootStatus(enable) Builtins.y2milestone("Set secure boot: %2 => %1", enable, @secure_boot) @location_changed = true if @secure_boot != enable # secure boot require reinstall of stage 1 @secure_boot = enable nil end |
- (Object) Summary
Display bootloader summary
300 301 302 303 304 305 306 307 308 309 310 |
# File 'src/modules/BootCommon.rb', line 300 def Summary bl = getLoaderType(false) if bl == "none" return [ HTML.Colorize(getLoaderName(getLoaderType(false), :summary), "red") ] end # each Boot* should have own summary, that can differ raise "Not implemented for bootloader \"#{bl}\"" end |
- (String) SupportedLoader(loader)
Check whether loader with specified name is supported
365 366 367 |
# File 'src/modules/BootCommon.rb', line 365 def SupportedLoader(loader) SUPPORTED_BOOTLOADERS.include?(loader) ? loader : "none" end |
- (Object) Update
Update read settings to new version of configuration files
313 314 315 316 317 |
# File 'src/modules/BootCommon.rb', line 313 def Update Builtins.y2debug("No generic update function available") nil end |
- (Boolean) VerifyMDArray
FATE#305008: Failover boot configurations for md arrays with redundancy Verify if proposal includes md array with more diferent disks
504 505 506 507 508 509 510 511 512 513 514 |
# File 'src/modules/BootCommon.rb', line 504 def VerifyMDArray if @globals["boot_md_mbr"] md_array = @globals["boot_md_mbr"] disks = md_array.split(",").reject(&:empty?) if Builtins.size(disks) > 1 Builtins.y2milestone("boot_md_mbr includes disks: %1", disks) return true end end false end |
- (Boolean) Write
Write bootloader settings to disk
321 322 323 324 |
# File 'src/modules/BootCommon.rb', line 321 def Write Builtins.y2error("No generic write function available") false end |