Class: Yast::BootELILOClass
- Inherits:
-
Module
- Object
- Module
- Yast::BootELILOClass
- Defined in:
- ../../src/modules/BootELILO.rb
Instance Method Summary (collapse)
-
- (Object) BootELILO
Constructor.
-
- (Object) CreateGlobals
Propose global options of bootloader modifies internal structures.
-
- (Object) CreateLinuxSection(title)
wrapper function to adjust to new grub name sceme.
-
- (Object) CreateSections
Propose sections to bootloader menu modifies internal structures.
-
- (Object) deleteSameEFIBootEntry(name, part_no)
FIXME: efibootmgr doesn't provide info about disk! bnc #450682 - adding boot entry to EFI function delete all existing boot entry with same name and partition number.
- - (Object) Dialogs
- - (Object) elilo_section_types
-
- (Object) Export
Export bootloader settings to a map.
-
- (Boolean) FlagBootDefaultOnce(section)
Set section to boot on next reboot.
-
- (Object) getEfiMountPoint
Return mountpoint of partition holding EFI data.
-
- (String) getEliloConfFilename
Return path to elilo.conf file.
-
- (Object) getEliloConfSubdir
Get directory containing elilo.conf relative to EFI partition's root.
-
- (String) getEliloConfSubpath
Get path of elilo.conf relative to EFI partition's root.
-
- (Object) GetFunctions
Return map of provided functions.
-
- (Object) Import(settings)
Import settings from a map.
-
- (Object) Initializer
Initializer of ELILO bootloader.
-
- (Boolean) installBootLoader(command, logfile)
Install the bootloader, display a popup with log if something goes wrong FIXME get rid of this function.
- - (Object) main
-
- (Object) Propose
Propose bootloader settings.
-
- (Boolean) Read(reread, avoid_reading_device_map)
Read settings from disk internal data.
-
- (Object) Reset(init)
Reset bootloader settings.
-
- (Boolean) Save(clean, init, flush)
Save all bootloader configuration files.
-
- (Object) Summary
Display bootloader summary.
-
- (String) tomyhexa(boot_part)
bnc #438215 - YaST creates efibootloader entry twice Function convert number of partition to hexa.
-
- (Object) Update
Update read settings to new version of configuration files.
-
- (Object) updateEFILabel
bnc #269198 change efi-label Function check if there exist same efi-label or different for same partition if efi-label is different delete it and create new one if it is same nothing to do it.
-
- (Boolean) Write
Write bootloader settings to disk.
Instance Method Details
- (Object) BootELILO
Constructor
901 902 903 904 905 906 907 908 909 910 911 912 913 |
# File '../../src/modules/BootELILO.rb', line 901 def BootELILO Ops.set( BootCommon.bootloader_attribs, "elilo", { "required_packages" => ["elilo", "efibootmgr"], "loader_name" => "ELILO", "initializer" => fun_ref(method(:Initializer), "void ()") } ) nil end |
- (Object) CreateGlobals
Propose global options of bootloader modifies internal structures
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File '../../src/modules/BootELILO.rb', line 165 def CreateGlobals BootCommon.globals = { # FIXME do it later # "append" : BootArch::DefaultKernelParams (""), "default" => "linux", "timeout" => "8", "prompt" => "true", # bnc #438276 - no 'read-only' "relocatable" => "true" } nil end |
- (Object) CreateLinuxSection(title)
wrapper function to adjust to new grub name sceme
127 128 129 130 131 132 133 134 135 |
# File '../../src/modules/BootELILO.rb', line 127 def CreateLinuxSection(title) section = BootCommon.CreateLinuxSection(title) # don't translate label bnc #151486 Ops.set(section, "description", Ops.get_string(section, "name", "")) Ops.set(section, "name", title) deep_copy(section) end |
- (Object) CreateSections
Propose sections to bootloader menu modifies internal structures
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File '../../src/modules/BootELILO.rb', line 141 def CreateSections linux = CreateLinuxSection("linux") failsafe = CreateLinuxSection("failsafe") # bnc#588609 - Problems writing elilo xen = {} xen = CreateLinuxSection("xen") if BootCommon.XenPresent # append for default section is in global # FIXME do it later # if (haskey (linux, "append")) # linux = remove (linux, "append"); if xen != nil && Ops.greater_than(Builtins.size(xen), 0) BootCommon.sections = [linux, failsafe, xen] else BootCommon.sections = [linux, failsafe] end nil end |
- (Object) deleteSameEFIBootEntry(name, part_no)
FIXME: efibootmgr doesn't provide info about disk! bnc #450682 - adding boot entry to EFI function delete all existing boot entry with same name and partition number
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File '../../src/modules/BootELILO.rb', line 596 def deleteSameEFIBootEntry(name, part_no) part_no = deep_copy(part_no) still_exist = true cmd = Builtins.sformat( "efibootmgr -v |grep \"%1.*HD(%2.*File(.\\efi.\\SuSE.\\elilo.efi)\" | cut -d \" \" -f 1", name, tomyhexa(part_no) ) Builtins.y2milestone("run command %1", cmd) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) Builtins.y2milestone("output of command %1", out) boot_entries = Ops.get_string(out, "stdout", "") Builtins.y2milestone( "EFI boot entries with \"same\" boot partition %1", boot_entries ) list_boot_entries = Builtins.splitstring(boot_entries, "\n") Builtins.y2milestone("list_boot_entries=%1", list_boot_entries) Builtins.foreach(list_boot_entries) do |entry| if Builtins.deletechars(entry, "\n*") != "" && Builtins.deletechars(entry, "\n*") != nil cmd = Builtins.sformat( "/usr/sbin/efibootmgr --delete-bootnum --bootnum %1 -q;", Builtins.substring(Builtins.deletechars(entry, "\n*"), 4, 4) ) Builtins.y2milestone("run command %1", cmd) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) Builtins.y2milestone("output of command %1", out) end end nil end |
- (Object) Dialogs
830 831 832 |
# File '../../src/modules/BootELILO.rb', line 830 def Dialogs { "loader" => fun_ref(method(:EliloLoaderDetailsDialog), "symbol ()") } end |
- (Object) elilo_section_types
842 843 844 |
# File '../../src/modules/BootELILO.rb', line 842 def elilo_section_types ["image", "xen"] end |
- (Object) Export
Export bootloader settings to a map
185 186 187 188 189 190 191 |
# File '../../src/modules/BootELILO.rb', line 185 def Export ret = BootCommon.Export Ops.set(ret, "old_efi_entry", @old_efi_entry) Ops.set(ret, "elilo_conf_filename", @elilo_conf_filename) Ops.set(ret, "create_efi_entry", @create_efi_entry) deep_copy(ret) end |
- (Boolean) FlagBootDefaultOnce(section)
Set section to boot on next reboot.
837 838 839 840 |
# File '../../src/modules/BootELILO.rb', line 837 def FlagBootDefaultOnce(section) # For now a dummy true end |
- (Object) getEfiMountPoint
Return mountpoint of partition holding EFI data
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File '../../src/modules/BootELILO.rb', line 79 def getEfiMountPoint mountpoint = "/" # FIXME: UGLY HACK because of testsuites mountpoints = {} if Mode.test mountpoints = { "/" => ["/dev/hda2"], "/boot" => ["/dev/hda1"] } else mountpoints = Storage.GetMountPoints end if Builtins.haskey(mountpoints, "/boot/efi") mountpoint = "/boot/efi" elsif Builtins.haskey(mountpoints, "/boot") mountpoint = "/boot" end Builtins.y2milestone("Mountpoint of EFI: %1", mountpoint) mountpoint end |
- (String) getEliloConfFilename
Return path to elilo.conf file
114 115 116 117 118 119 120 121 122 123 124 |
# File '../../src/modules/BootELILO.rb', line 114 def getEliloConfFilename # FIXME config file name location should be read from Library # and it should not be needed here!!! ret = Builtins.sformat( "%1/efi/%2/elilo.conf", getEfiMountPoint, @efi_vendor ) Builtins.y2milestone("elilo.conf sould be located at %1", ret) ret end |
- (Object) getEliloConfSubdir
Get directory containing elilo.conf relative to EFI partition's root
100 101 102 |
# File '../../src/modules/BootELILO.rb', line 100 def getEliloConfSubdir Builtins.sformat("/efi/%1", @efi_vendor) end |
- (String) getEliloConfSubpath
Get path of elilo.conf relative to EFI partition's root
107 108 109 |
# File '../../src/modules/BootELILO.rb', line 107 def getEliloConfSubpath Builtins.sformat("%1/elilo.conf", getEliloConfSubdir) end |
- (Object) GetFunctions
Return map of provided functions
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 |
# File '../../src/modules/BootELILO.rb', line 848 def GetFunctions { "export" => fun_ref(method(:Export), "map ()"), "import" => fun_ref(method(:Import), "boolean (map)"), "read" => fun_ref( method(:Read), "boolean (boolean, boolean)" ), "reset" => fun_ref(method(:Reset), "void (boolean)"), "propose" => fun_ref(method(:Propose), "void ()"), "save" => fun_ref( method(:Save), "boolean (boolean, boolean, boolean)" ), "summary" => fun_ref(method(:Summary), "list <string> ()"), "update" => fun_ref(method(:Update), "void ()"), "write" => fun_ref(method(:Write), "boolean ()"), "widgets" => fun_ref( method(:Widgets), "map <string, map <string, any>> ()" ), "dialogs" => fun_ref( method(:Dialogs), "map <string, symbol ()> ()" ), "section_types" => fun_ref( method(:elilo_section_types), "list <string> ()" ), "flagbootdefaultonce" => fun_ref( method(:FlagBootDefaultOnce), "boolean (string)" ) } end |
- (Object) Import(settings)
Import settings from a map
196 197 198 199 200 201 202 203 204 205 206 207 |
# File '../../src/modules/BootELILO.rb', line 196 def Import(settings) settings = deep_copy(settings) BootCommon.Import(settings) @old_efi_entry = Ops.get_string(settings, "old_efi_entry") @elilo_conf_filename = getEliloConfFilename @create_efi_entry = Ops.get_boolean( settings, "create_efi_entry", Ops.get_string(settings, "location", "") != "" ) true end |
- (Object) Initializer
Initializer of ELILO bootloader
885 886 887 888 889 890 891 892 893 894 895 896 897 898 |
# File '../../src/modules/BootELILO.rb', line 885 def Initializer Builtins.y2milestone("Called ELILO initializer") BootCommon.current_bootloader_attribs = { "propose" => true, "read" => true, "scratch" => true, "restore_mbr" => true, "bootloader_on_disk" => true } BootCommon.InitializeLibrary(false, "elilo") nil end |
- (Boolean) installBootLoader(command, logfile)
Install the bootloader, display a popup with log if something goes wrong FIXME get rid of this function
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 463 464 465 466 |
# File '../../src/modules/BootELILO.rb', line 431 def installBootLoader(command, logfile) Builtins.y2milestone("Running command %1", command) exit = Convert.to_map(SCR.Execute(path(".target.bash_output"), command)) ret = 0 == Ops.get_integer(exit, "exit", 1) if !ret Builtins.y2milestone( "Exit code of %1: %2", command, Ops.get_integer(exit, "exit", -1) ) log = Convert.to_string(SCR.Read(path(".target.string"), logfile)) log = Ops.add( Ops.add(log, Ops.get_string(exit, "stdout", "")), Ops.get_string(exit, "stderr", "") ) if Ops.get_integer(exit, "exit", 1) == 139 # means: process received signal SIGSEGV # please, use some usual translation # proofreaders: don't change this text log = Ops.add(log, _("Segmentation fault")) end errorWithLogPopup( Builtins.sformat( # error popup - label, %1 is bootloader name _("Error Occurred while Installing %1"), BootCommon.getLoaderName(BootCommon.getLoaderType(false), :summary) ), log ) else @added_label_to_efi = true Builtins.y2milestone("Adding label to EFI finish successful") end ret end |
- (Object) main
26 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 70 71 72 73 |
# File '../../src/modules/BootELILO.rb', line 26 def main Yast.import "UI" textdomain "bootloader" Yast.import "BootArch" Yast.import "BootCommon" Yast.import "BootStorage" Yast.import "Installation" Yast.import "Kernel" Yast.import "Mode" Yast.import "Report" Yast.import "Stage" Yast.import "Storage" Yast.import "String" Yast.import "Arch" Yast.include self, "bootloader/elilo/helps.rb" Yast.include self, "bootloader/routines/popups.rb" Yast.include self, "bootloader/elilo/dialogs.rb" # private variables # Name of EFI entry when read settings @old_efi_entry = nil # elilo.conf path @elilo_conf_filename = "/boot/efi/SuSE/elilo.conf" # True if EFI entry should be recreated @create_efi_entry = true @efi_vendor = "SuSE" # bnc #450682 - adding boot entry to EFI # true is label was added @added_label_to_efi = false # Is the /sys/firmware/efi directory available? @efi_available = true Yast.include self, "bootloader/elilo/widgets.rb" BootELILO() end |
- (Object) Propose
Propose bootloader settings
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 |
# File '../../src/modules/BootELILO.rb', line 294 def Propose Yast.import "Product" if !BootCommon.was_proposed @create_efi_entry = true # make sure the code handling globals below triggers and that # boot_efilabel is recreated if Builtins.haskey(BootCommon.globals, "boot_efilabel") BootCommon.globals = Builtins.remove( BootCommon.globals, "boot_efilabel" ) end end @create_efi_entry = true if !Stage.initial @create_efi_entry = false if Mode.update @efi_available = 0 == Convert.to_integer( SCR.Execute(path(".target.bash"), "test -d /sys/firmware/efi") ) @create_efi_entry = false if !@efi_available @elilo_conf_filename = getEliloConfFilename BootCommon.DetectDisks BootCommon.del_parts = BootStorage.getPartitionList(:deleted, "elilo") if BootCommon.sections == nil || Builtins.size(BootCommon.sections) == 0 CreateSections() BootCommon.kernelCmdLine = Kernel.GetCmdLine else if Mode.autoinst Builtins.y2debug("Nothing to do for propose in AI mode") else BootCommon.FixSections(fun_ref(method(:CreateSections), "void ()")) end end if BootCommon.globals == nil || Builtins.size(BootCommon.globals) == 0 CreateGlobals() end if Ops.get(BootCommon.globals, "boot_efilabel") == nil || Ops.get(BootCommon.globals, "boot_efilabel") == "" Ops.set(BootCommon.globals, "boot_efilabel", Product.name) end BootCommon.UpdateProposalFromClient if Mode.installation Builtins.y2milestone( "EFI entry name: %1", Ops.get(BootCommon.globals, "boot_efilabel", "") ) Builtins.y2milestone("Proposed sections: %1", BootCommon.sections) Builtins.y2milestone("Proposed globals: %1", BootCommon.globals) nil end |
- (Boolean) Read(reread, avoid_reading_device_map)
Read settings from disk internal data
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 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 |
# File '../../src/modules/BootELILO.rb', line 215 def Read(reread, avoid_reading_device_map) Yast.import "Product" efi_entry_found = false @elilo_conf_filename = getEliloConfFilename # copy old elilo.conf from /boot/<something> to /etc in case of upgrade # (if /etc/elilo.conf doesn't exist) if Ops.less_or_equal(SCR.Read(path(".target.size"), "/etc/elilo.conf"), 0) && Ops.greater_than( SCR.Read(path(".target.size"), @elilo_conf_filename), 0 ) SCR.Execute( path(".target.bash"), Builtins.sformat("/bin/cp %1 /etc/elilo.conf", @elilo_conf_filename) ) end SCR.Execute(path(".target.bash"), "/bin/touch /etc/elilo.conf") BootCommon.DetectDisks ret = BootCommon.Read(reread, avoid_reading_device_map) # check for meaningless EFI entry name in sysconfig if !Builtins.haskey(BootCommon.globals, "boot_efilabel") || Ops.get(BootCommon.globals, "boot_efilabel", "") == "mbr" || Ops.get(BootCommon.globals, "boot_efilabel", "") == "" || Ops.get(BootCommon.globals, "boot_efilabel", "") == nil efi_path = String.Replace(getEliloConfSubpath, "/", "\\") # Read Firmware setting from NVRam efi_status = Convert.to_map( SCR.Execute( path(".target.bash_output"), Builtins.sformat("/usr/sbin/efibootmgr |grep \"%1\"", efi_path) ) ) if Ops.get_integer(efi_status, "exit", 0) != 0 Ops.set(BootCommon.globals, "boot_efilabel", Product.name) else output = Ops.get_string(efi_status, "stdout", "") lines = Builtins.splitstring(output, "\n") output = Ops.get_string(lines, 0, "") if Builtins.regexpmatch(output, "Boot.** (.*) HD") Ops.set( BootCommon.globals, "boot_efilabel", Builtins.regexpsub(output, "Boot.** (.*) HD", "\\1") ) efi_entry_found = true else Ops.set(BootCommon.globals, "boot_efilabel", Product.name) end end else efi_entry_found = 0 == SCR.Execute( path(".target.bash"), Builtins.sformat( "/usr/sbin/efibootmgr |grep \"%1\"", Ops.get(BootCommon.globals, "boot_efilabel", "") ) ) end @create_efi_entry = !efi_entry_found @old_efi_entry = efi_entry_found ? Ops.get(BootCommon.globals, "boot_efilabel", "") : nil ret end |
- (Object) Reset(init)
Reset bootloader settings
284 285 286 287 288 289 290 |
# File '../../src/modules/BootELILO.rb', line 284 def Reset(init) return if Mode.autoinst @create_efi_entry = true BootCommon.Reset(init) nil end |
- (Boolean) Save(clean, init, flush)
Save all bootloader configuration files
353 354 355 356 |
# File '../../src/modules/BootELILO.rb', line 353 def Save(clean, init, flush) ret = BootCommon.Save(clean, init, flush) ret end |
- (Object) Summary
Display bootloader summary
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 396 397 398 399 400 401 402 403 404 405 406 |
# File '../../src/modules/BootELILO.rb', line 361 def Summary # summary text, %1 is bootloader name (eg. LILO) result = [ Builtins.sformat( _("Boot loader type: %1"), BootCommon.getLoaderName(BootCommon.getLoaderType(false), :summary) ) ] if Ops.get(BootCommon.globals, "boot_efilabel", "") == "" || !@create_efi_entry result = # summary text Builtins.add(result, _("Do Not Create EFI Boot Manager Entry")) else result = Builtins.add( result, Builtins.sformat( # summary text, %1 is label of the entry of EFI boot manager _("Create EFI Boot Manager Entry %1"), Ops.get(BootCommon.globals, "boot_efilabel", "") ) ) end sects = [] Builtins.foreach(BootCommon.sections) do |s| title = Ops.get_string(s, "name", "") # section name "suffix" for default section _def = title == Ops.get(BootCommon.globals, "default", "") ? _(" (default)") : "" sects = Builtins.add( sects, String.EscapeTags(Builtins.sformat("+ %1%2", title, _def)) ) end # summary text. %1 is list of bootloader sections result = Builtins.add( result, Builtins.sformat( _("Sections:<br>%1"), Builtins.mergestring(sects, "<br>") ) ) deep_copy(result) end |
- (String) tomyhexa(boot_part)
bnc #438215 - YaST creates efibootloader entry twice Function convert number of partition to hexa
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File '../../src/modules/BootELILO.rb', line 473 def tomyhexa(boot_part) boot_part = deep_copy(boot_part) ret = "1000" int_boot_part = Builtins.tointeger(boot_part) if int_boot_part != nil hexa = Builtins.tohexstring(int_boot_part) if Builtins.search(hexa, "x") != nil hexa_without_0x = Builtins.splitstring(hexa, "x") if Ops.greater_than(Builtins.size(hexa_without_0x), 1) ret = Ops.get(hexa_without_0x, 1, "1000") end end end ret end |
- (Object) Update
Update read settings to new version of configuration files
410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File '../../src/modules/BootELILO.rb', line 410 def Update # Update global options of bootloader # modifies internal structures if Ops.get(BootCommon.globals, "timeout", "") == "" Ops.set(BootCommon.globals, "timeout", "8") end Ops.set(BootCommon.globals, "append", BootArch.DefaultKernelParams("")) BootCommon.UpdateSections # FIXME EFI entry name nil end |
- (Object) updateEFILabel
bnc #269198 change efi-label Function check if there exist same efi-label or different for same partition if efi-label is different delete it and create new one if it is same nothing to do it.
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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File '../../src/modules/BootELILO.rb', line 496 def updateEFILabel ret = true cmd = "" mp = Storage.GetMountPoints boot_dev = Ops.get_string(mp, [getEfiMountPoint, 0], "/boot/efi") splited = Storage.GetDiskPartition(boot_dev) boot_part = Ops.get_integer(splited, "nr", 0) boot_disk = Ops.get_string(splited, "disk", "") # command for checking same boot entry in efi bnc #438215 (YaST creates efibootloader entry twice) cmd = Builtins.sformat( "/usr/sbin/efibootmgr -v | grep -c \"%1.*HD(%2.*File(.\\efi.\\SuSE.\\elilo.efi)\"", Ops.get(BootCommon.globals, "boot_efilabel", ""), tomyhexa(boot_part) ) # check how many entries with same label and partition is actually in efi Builtins.y2milestone("run command %1", cmd) out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) Builtins.y2milestone("output of command %1", out) # check number of same boot entries in efi # if boot entry is added -> don't add it again if Builtins.deletechars(Ops.get_string(out, "stdout", ""), "\n") != "0" if Ops.get_integer(out, "exit", 0) == 0 Builtins.y2milestone("Skip adding new boot entry - EFI Label exist") else Builtins.y2error("Calling command %1 faild", cmd) end return ret else cmd = Builtins.sformat( "/usr/sbin/efibootmgr -v | grep -c \"HD(%1.*File(.\\efi.\\SuSE.\\elilo.efi)\"", tomyhexa(boot_part) ) # check how many entries with same label and partition is actually in efi Builtins.y2milestone("run command %1", cmd) out2 = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) Builtins.y2milestone("output of command %1", out2) # check how many boot entries have same number of partitions if Builtins.deletechars(Ops.get_string(out2, "stdout", ""), "\n") != "0" # delete old boot entry cmd = Builtins.sformat( "efibootmgr -v |grep \"HD(%1.*File(.\\efi.\\SuSE.\\elilo.efi)\" | cut -d \" \" -f 1", tomyhexa(boot_part) ) Builtins.y2milestone("run command %1", cmd) out2 = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) Builtins.y2milestone("output of command %1", out2) boot_entries = Ops.get_string(out2, "stdout", "") Builtins.y2milestone( "EFI boot entries with \"same\" boot partition %1", boot_entries ) list_boot_entries = Builtins.splitstring(boot_entries, "\n") Builtins.y2milestone("list_boot_entries=%1", list_boot_entries) Builtins.foreach(list_boot_entries) do |entry| if Builtins.deletechars(entry, "\n*") != "" && Builtins.deletechars(entry, "\n*") != nil cmd = Builtins.sformat( "/usr/sbin/efibootmgr --delete-bootnum --bootnum %1 -q;", Builtins.substring(Builtins.deletechars(entry, "\n*"), 4, 4) ) Builtins.y2milestone("run command %1", cmd) out2 = Convert.to_map( SCR.Execute(path(".target.bash_output"), cmd) ) Builtins.y2milestone("output of command %1", out2) end end end # add new boot entry bl_logfile = "/var/log/YaST2/y2log_bootloader" bl_command = Builtins.sformat( "/usr/sbin/efibootmgr -v --create --label \"%1\" " + "--disk %2 --part %3 " + "--loader '\\efi\\SuSE\\elilo.efi' --write-signature >> %4 2>&1", Ops.get(BootCommon.globals, "boot_efilabel", ""), boot_disk, boot_part, bl_logfile ) ret = ret && installBootLoader(bl_command, bl_logfile) end ret end |
- (Boolean) Write
Write bootloader settings to disk
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
# File '../../src/modules/BootELILO.rb', line 637 def Write Builtins.y2milestone("run Write function from BootELILO") # SCR::Execute (.target.bash, "/sbin/elilo"); ret = BootCommon.UpdateBootloader ret = false if ret == nil # FIXME find a better way to report status if ret && !@efi_available Popup.TimedMessage( _( "System was not booted via EFI firmware. To boot your\ncomputer, you need to load ELILO via the EFI shell." ), 10 ) end updateEFILabel if Mode.normal if BootCommon.location_changed || @create_efi_entry mp = Storage.GetMountPoints boot_dev = Ops.get_string(mp, [getEfiMountPoint, 0], "/boot/efi") splited = Storage.GetDiskPartition(boot_dev) boot_part = Ops.get_integer(splited, "nr", 0) boot_disk = Ops.get_string(splited, "disk", "") Builtins.y2milestone("Disk: %1, Part: %2", boot_disk, boot_part) # Create new EFI Bootmgr Label if specified if Ops.get(BootCommon.globals, "boot_efilabel", "") != "" bl_logfile = "/var/log/YaST2/y2log_bootloader" bl_command = Builtins.sformat( "/usr/sbin/efibootmgr -v --create --label \"%1\" " + "--disk %2 --part %3 " + "--loader '\\efi\\SuSE\\elilo.efi' --write-signature >> %4 2>&1", Ops.get(BootCommon.globals, "boot_efilabel", ""), boot_disk, boot_part, bl_logfile ) # command for checking same boot entry in efi bnc #438215 (YaST creates efibootloader entry twice) cmd = Builtins.sformat( "/usr/sbin/efibootmgr -v | grep -c \"%1.*HD(%2.*File(.\\efi.\\SuSE.\\elilo.efi)\"", Ops.get(BootCommon.globals, "boot_efilabel", ""), tomyhexa(boot_part) ) Builtins.y2milestone("Command for checking same boot entry: %1", cmd) # check how many entries with same label and partition is actually in efi out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd)) # check number of same boot entries in efi # if boot entry is added -> don't add it again if Builtins.deletechars(Ops.get_string(out, "stdout", ""), "\n") == "0" ret = ret && installBootLoader(bl_command, bl_logfile) else if @added_label_to_efi Builtins.y2milestone( "Skip adding boot entry: %1 to EFI. There already exist and was added: %2 with \n\t\t\t\tsame label and partition.", Ops.get(BootCommon.globals, "boot_efilabel", ""), Builtins.deletechars(Ops.get_string(out, "stdout", ""), "\n") ) else # delete efi entry with same label name and partition deleteSameEFIBootEntry( Ops.get(BootCommon.globals, "boot_efilabel", ""), boot_part ) # add new efi boot entry ret = ret && installBootLoader(bl_command, bl_logfile) end end end # Remove existing old, obsolete menu entries # # FIXME should be handled completly through the library # Detect the current default boot entry (e.g. "0007") default_entry_map = Convert.to_map( SCR.Execute( path(".target.bash_output"), "/usr/sbin/efibootmgr |grep ^BootOrder: | " + "cut -d ' ' -f 2 | cut -d ',' -f 1" ) ) new_entry = Ops.get_string(default_entry_map, "stdout", "") # Check for validity -- returned default_entry has to be 4 chars long # and be composed of numbers and characters only if Builtins.size(new_entry) != 4 && Builtins.regexpmatch(new_entry, "[0-9A-F]") == false Builtins.y2error( "BootELILO: Found default boot entry %1 isn't valid", new_entry ) else # Remove newlines and carriage returns in string new_entry = Builtins.deletechars(new_entry, "\n ") # Attach prefix "Boot" for proper matching new_entry = Ops.add("Boot", new_entry) # Prepare command for fetching string "HD(...)" # from efibootmgr output command = Builtins.sformat( "set -o pipefail; /usr/sbin/efibootmgr -v | " + "grep '%1' |sed 's/%1.*\\(HD(.*)File(.*)\\).*/\\1/'", String.Quote(new_entry) ) hd_descr_map = Convert.to_map( SCR.Execute(path(".target.bash_output"), command) ) Builtins.y2milestone("BootELILO: hd_descr_map = %1", hd_descr_map) # Remove newlines and carriage returns in string hd_descr = Builtins.deletechars( Ops.get_string(hd_descr_map, "stdout", ""), "\n " ) # Prepare command for fetching boot entry number corresponding # to "HD(...)" string from efibootmgr output command = Builtins.sformat( "set -o pipefail; /usr/sbin/efibootmgr -v |" + "grep '%1' |awk '{print $1}'", String.Quote(hd_descr) ) entries2remove_map = Convert.to_map( SCR.Execute(path(".target.bash_output"), command) ) Builtins.y2milestone( "BootELILO: entries2remove_map = %1", entries2remove_map ) entries2remove_string = Ops.get_string( entries2remove_map, "stdout", "" ) # Convert the string containing the entries to be removed to a list entries2remove_list = Builtins.splitstring( entries2remove_string, "\n" ) # Check if there are entries to remove, thus if listsize is greater than 0 listsize = Builtins.size(entries2remove_list) if Ops.greater_than(listsize, 0) # Rermove the last entry of the list (because it's an empty one) lastentry = Ops.subtract(listsize, 1) entries2remove_list = Builtins.remove( entries2remove_list, lastentry ) Builtins.y2milestone( "BootELILO: entries2remove_list = %1", entries2remove_list ) # Filter the bootnumbers from strings for further usage entries2remove_list = Builtins.maplist(entries2remove_list) do |entry2remove| if Builtins.issubstring(entry2remove, new_entry) == false entry2remove = Builtins.substring(entry2remove, 4, 4) next entry2remove end end # Delete obsolete bootentries by bootnumbers Builtins.foreach(entries2remove_list) do |entry2remove| command2 = Builtins.sformat( "/usr/sbin/efibootmgr --delete-bootnum --bootnum %1 -q;", entry2remove ) Builtins.y2milestone("Running command %1", command2) ret_map = Convert.to_map( SCR.Execute(path(".target.bash_output"), command2) ) Builtins.y2milestone("BootELILO: ret_map = %1", ret_map) ret = Ops.get_integer(ret_map, "exit", 1) == 0 end else Builtins.y2milestone("BootELILO: No obsolete entry to remove") end end end ret end |