Class: Yast::BootloaderClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Bootloader.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Bootloader

Constructor



96
97
98
# File '../../src/modules/Bootloader.rb', line 96

def Bootloader
  nil
end

- (Boolean) CheckClientForSLERT

bnc #450153 YaST bootloader doesn't handle kernel from add-on products in installation Function check if client kernel_bl_proposal exist

Returns:

  • (Boolean)

    true on success



787
788
789
790
791
792
793
# File '../../src/modules/Bootloader.rb', line 787

def CheckClientForSLERT
  if WFM.ClientExists("kernel_bl_proposal")
    return true
  else
    return false
  end
end

- (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

Returns:

  • (Boolean)

    true on success



87
88
89
90
91
92
93
# File '../../src/modules/Bootloader.rb', line 87

def checkUsedStorage
  if !Storage.InitLibstorage(true) && Mode.normal
    return false
  else
    return true
  end
end

- (String) checkZiplDefault(_def)

bnc #364904 Function check if default section is menu if yes it tries to find default section in list of names from menu section

Parameters:

Returns:

  • (String)

    name of default section



1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
# File '../../src/modules/Bootloader.rb', line 1070

def checkZiplDefault(_def)
  def_section_name = _def

  Builtins.foreach(BootCommon.sections) do |section|
    if Ops.get_string(section, "name", "") == def_section_name
      if Ops.get_string(section, "type", "") == "menu"
        def_position = Ops.get_string(section, "default", "")
        def_section_name = parseListDefault(
          Ops.get_string(section, "list", ""),
          def_position
        )
      else
        raise Break
      end
    end
  end if getLoaderType(
  ) == "zipl"

  Builtins.y2milestone("name of default section: %1", def_section_name)
  def_section_name
end

- (Boolean) CopyKernelInird

Copy initrd and kernel on the end of instalation (1st stage) fate #303395 Use kexec to avoid booting between first and second stage copy kernel and initrd to /var/lib/YaST run kernel via kexec instead of reboot if not success then reboot...

Returns:

  • (Boolean)

    on success



1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
# File '../../src/modules/Bootloader.rb', line 1436

def CopyKernelInird
  Builtins.y2milestone("CopyKernelInird: start copy kernel and inird")

  if Mode.live_installation
    Builtins.y2milestone("Running live_installation without using kexec")
    return true
  end

  if ProductFeatures.GetBooleanFeature("globals", "kexec_reboot") != true
    Builtins.y2milestone(
      "Option kexec_reboot is false. kexec will not be used."
    )
    return true
  end

  # check architecture for using kexec instead of reboot
  if Arch.ppc || Arch.ia64 || Arch.s390
    Builtins.y2milestone("Skip using of kexec on this architecture")
    return true
  end

  bios_data = Convert.convert(
    SCR.Read(path(".probe.bios")),
    :from => "any",
    :to   => "list <map>"
  )

  Builtins.y2milestone("CopyKernelInird::bios_data = %1", bios_data)

  if IsVirtualBox(bios_data)
    Builtins.y2milestone(
      "Installation run on VirtualBox, skip kexec loading"
    )
    return false
  end

  if IsHyperV(bios_data)
    Builtins.y2milestone("Installation run on HyperV, skip kexec loading")
    return false
  end

  # create default sections
  linux_default = BootCommon.CreateLinuxSection("linux")

  Builtins.y2milestone("linux_default: %1", linux_default)

  default_section = {}

  name = getDefaultSection
  # find default section in BootCommon::sections
  Builtins.foreach(BootCommon.sections) do |section|
    if Builtins.search(
        Builtins.tostring(Ops.get_string(section, "name", "")),
        name
      ) != nil &&
        Ops.get(section, "root") == Ops.get(linux_default, "root") &&
        Ops.get_string(section, "original_name", "") != "failsafe"
      Builtins.y2milestone("default section: %1", section)
      default_section = deep_copy(section)
    end
  end

  # create directory /var/lib/YaST2
  WFM.Execute(path(".local.mkdir"), "/var/lib/YaST2")

  # build command for copy kernel and initrd to /var/lib/YaST during instalation
  cmd = nil

  default_section = updateAppend(default_section)

  cmd = Builtins.sformat(
    "/bin/cp %1%2 %1%3 %4",
    Installation.destdir,
    Builtins.tostring(Ops.get_string(default_section, "image", "")),
    Builtins.tostring(Ops.get_string(default_section, "initrd", "")),
    Directory.vardir
  )

  Builtins.y2milestone("Command for copy: %1", cmd)
  out = Convert.to_map(WFM.Execute(path(".local.bash_output"), cmd))
  if Ops.get(out, "exit") != 0
    Builtins.y2error("Copy kernel and initrd failed, output: %1", out)
    return false
  end

  if Ops.get_string(default_section, "root", "") == ""
    Builtins.y2milestone("root is not defined in default section.")
    return false
  end

  if Ops.get_string(default_section, "vgamode", "") == ""
    Builtins.y2milestone("vgamode is not defined in default section.")
    return false
  end

  # flush kernel options into /var/lib/YaST/kernel_params
  cmd = Builtins.sformat(
    "echo \"root=%1 %2 vga=%3\" > %4/kernel_params",
    Builtins.tostring(Ops.get_string(default_section, "root", "")),
    Builtins.tostring(Ops.get_string(default_section, "append", "")),
    Builtins.tostring(Ops.get_string(default_section, "vgamode", "")),
    Directory.vardir
  )

  Builtins.y2milestone("Command for flushing kernel args: %1", cmd)
  out = Convert.to_map(WFM.Execute(path(".local.bash_output"), cmd))
  if Ops.get(out, "exit") != 0
    Builtins.y2error("Flushing kernel params failed, output: %1", out)
    return false
  end

  true
end

- (Fixnum) CountSection(find_section)

Find “same” boot sections and return numbers of sections from BootCommon::sections

Parameters:

  • map (string, any)

    section

Returns:

  • (Fixnum)

    number of “same” sactions



800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File '../../src/modules/Bootloader.rb', line 800

def CountSection(find_section)
  find_section = deep_copy(find_section)
  Builtins.y2milestone("Finding same boot sections")
  num_sections = 0
  Builtins.foreach(BootCommon.sections) do |section|
    if Ops.get(section, "root") == Ops.get(find_section, "root") &&
        Ops.get(section, "original_name") ==
          Ops.get(find_section, "original_name")
      num_sections = Ops.add(num_sections, 1)
    end
  end
  Builtins.y2milestone(
    "Number of similar section is %2 with %1",
    find_section,
    num_sections
  )
  num_sections
end

- (Object) createSELinuxDir



1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
# File '../../src/modules/Bootloader.rb', line 1549

def createSELinuxDir
  path_file = "/selinux"
  cmd = "ls -d /selinux  2>/dev/null"
  if BootCommon.enable_selinux
    if Mode.normal || Mode.installation
      out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
      Builtins.y2milestone(
        "runnning command: \"%1\" and return: %2",
        cmd,
        out
      )
      if Ops.get_string(out, "stdout", "") != "/selinux\n"
        SCR.Execute(path(".target.mkdir"), path_file)
      else
        Builtins.y2milestone("Directory /selinux already exist")
      end
    else
      Builtins.y2milestone("Skip creating /selinux directory -> wrong mode")
    end
  else
    Builtins.y2milestone("Skip creating /selinux directory")
  end

  nil
end

- (Object) DelDuplicatedSections

Delete duplicated boot sections from BootCommon::sections



822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
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
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File '../../src/modules/Bootloader.rb', line 822

def DelDuplicatedSections
  if CheckClientForSLERT()
    removeDummySections
    return
  end
  Builtins.y2milestone("Deleting duplicated boot sections")

  linux_default = {}
  linux_failsafe = {}
  linux_xen = {}
  if Arch.ppc
    linux_default = BootPOWERLILO.CreateImageSection("linux")
  else
    linux_default = BootCommon.CreateLinuxSection("linux")
    linux_failsafe = BootCommon.CreateLinuxSection("failsafe")
    linux_xen = BootCommon.CreateLinuxSection("xen")
  end

  Builtins.y2milestone(
    "Proposed section for linux_default: %1",
    linux_default
  )
  Builtins.y2milestone(
    "Proposed section for linux_failsafe: %1",
    linux_failsafe
  )
  Builtins.y2milestone("Proposed section for linux_xen: %1", linux_xen)

  Builtins.y2milestone(
    "Boot sections BEFORE deleting: %1",
    BootCommon.sections
  )

  # obtain number of relative same boot sections for linux_default
  num_linux_default = CountSection(linux_default)
  # obtain number of relative same boot sections for linux_failsafe
  num_linux_failsafe = CountSection(linux_failsafe)

  # obtain number of relative same boot sections for linux_failsafe
  num_linux_xen = CountSection(linux_xen)

  BootCommon.sections = Builtins.filter(BootCommon.sections) do |section|
    if (Ops.get(section, "name") == Ops.get(linux_default, "name") ||
        Ops.get_string(section, "description", "") ==
          Ops.get(linux_default, "name")) &&
        Ops.greater_than(num_linux_default, 1) ||
        (Ops.get(section, "name") == Ops.get(linux_failsafe, "name") ||
          Ops.get_string(section, "description", "") ==
            Ops.get(linux_failsafe, "name")) &&
          Ops.greater_than(num_linux_failsafe, 1) ||
        (Ops.get(section, "name") == Ops.get(linux_xen, "name") ||
          Ops.get_string(section, "description", "") ==
            Ops.get(linux_xen, "name")) &&
          Ops.greater_than(num_linux_xen, 1)
      if Ops.get(section, "root") == Ops.get(linux_default, "root") ||
          Ops.get(section, "root") == Ops.get(linux_failsafe, "root") ||
          Ops.get(section, "root") == Ops.get(linux_xen, "root")
        if Ops.get_string(section, "original_name", "") == "failsafe"
          num_linux_failsafe = Ops.subtract(num_linux_failsafe, 1)
        end

        if Ops.get_string(section, "original_name", "") == "linux"
          num_linux_default = Ops.subtract(num_linux_default, 1)
        end

        if Ops.get_string(section, "original_name", "") == "xen"
          num_linux_xen = Ops.subtract(num_linux_xen, 1)
        end

        Builtins.y2milestone("deleted boot section: %1", section)
        next false
      else
        next true
      end
    else
      next true
    end
    true
  end

  ResolveSymlinksInSections()
  FindAndSelectDefault(linux_default)
  Builtins.y2milestone(
    "Boot sections AFTER deleting: %1",
    BootCommon.sections
  )

  nil
end

- (Object) disableSELinuxPAM



1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
# File '../../src/modules/Bootloader.rb', line 1604

def disableSELinuxPAM
  cmd_disable_se = "pam-config -d --selinux  2>/dev/null"
  cmd_enable_aa = "pam-config -a --apparmor 2>/dev/null"

  out = Convert.to_map(SCR.Execute(path(".target.bash"), cmd_disable_se))
  Builtins.y2debug("result of disabling the SELinux PAM module is %1", out)

  out = Convert.to_map(SCR.Execute(path(".target.bash"), cmd_enable_aa))
  Builtins.y2debug("result of enabling the AppArmor PAM module is %1", out)

  nil
end

- (String) DMIRead(bios_data, section, key)

Get entry from DMI data returned by .probe.bios.

Parameters:

  • bios_data: (Array<Hash>)

    result of SCR::Read(.probe.bios)

  • section: (String)

    section name

  • key: (String)

    key in section

Returns:

  • (String)

    : entry



1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
# File '../../src/modules/Bootloader.rb', line 1377

def DMIRead(bios_data, section, key)
  bios_data = deep_copy(bios_data)
  result = ""

  Builtins.foreach(Ops.get_list(bios_data, [0, "smbios"], [])) do |x|
    if Ops.get_string(x, "type", "") == section
      result = Ops.get_string(x, key, "")
      raise Break
    end
  end

  Builtins.y2milestone(
    "Bootloader::DMIRead(%1, %2) = %3",
    section,
    key,
    result
  )

  result
end

- (Object) enableSELinuxPAM



1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
# File '../../src/modules/Bootloader.rb', line 1592

def enableSELinuxPAM
  cmd_enable_se = "pam-config -a --selinux  2>/dev/null"
  cmd_disable_aa = "pam-config -d --apparmor 2>/dev/null"

  out = Convert.to_map(SCR.Execute(path(".target.bash"), cmd_disable_aa))
  Builtins.y2debug("result of disabling the AppArmor PAM module is %1", out)

  out = Convert.to_map(SCR.Execute(path(".target.bash"), cmd_enable_se))
  Builtins.y2debug("result of enabling the SELinux PAM module is %1", out)

  nil
end

- (Object) Export

Export bootloader settings to a map

Returns:

  • bootloader settings



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File '../../src/modules/Bootloader.rb', line 102

def Export
  ReadOrProposeIfNeeded()
  out = {
    "loader_type"    => getLoaderType,
    "initrd"         => Initrd.Export,
    "specific"       => blExport,
    "write_settings" => BootCommon.write_settings
  }
  loader_type = Ops.get_string(out, "loader_type")

  if !(loader_type == "grub")
    # export loader_device and selected_location only for bootloaders
    # that have not phased them out yet
    Ops.set(out, "loader_device", BootCommon.loader_device)
    Ops.set(out, "loader_location", BootCommon.selected_location)
  end
  Builtins.y2milestone("Exporting settings: %1", out)
  deep_copy(out)
end

- (Object) FindAndSelectDefault(default_sec)



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
# File '../../src/modules/Bootloader.rb', line 713

def FindAndSelectDefault(default_sec)
  default_sec = deep_copy(default_sec)
  ret = false
  set_candidate = false
  default_name = Ops.get(BootCommon.globals, "default", "")
  default_candidate = ""

  Builtins.foreach(BootCommon.sections) do |section|
    if Ops.get(section, "name") == default_name
      Builtins.y2milestone("Default section was found.")
      ret = true
      raise Break
    else
      if Ops.get_string(section, "root", "") ==
          Ops.get_string(default_sec, "root", "") &&
          Ops.get_string(section, "type", "") == "image" &&
          Ops.get_string(section, "original_name", "") == "linux"
        default_candidate = Ops.get_string(section, "name", "")
        Builtins.y2milestone(
          "Candidate for default section is: %1",
          section
        )
        set_candidate = true
      end
    end
  end
  if !ret
    if set_candidate && default_candidate != ""
      Builtins.y2milestone(
        "Default section will be update to: %1",
        default_candidate
      )
      Ops.set(BootCommon.globals, "default", default_candidate)
      ret = true
    else
      Builtins.y2error("Default section was not found")
    end
  end
  ret
end

- (Boolean) FlagOnetimeBoot(section)

Set section to boot on next reboot

Parameters:

  • section (String)

    string section to boot

Returns:

  • (Boolean)

    true on success



1292
1293
1294
# File '../../src/modules/Bootloader.rb', line 1292

def FlagOnetimeBoot(section)
  blFlagOnetimeBoot(section)
end

- (String) getBootDevice

Get device containing /boot directory

Returns:

  • (String)

    boot device



1266
1267
1268
1269
# File '../../src/modules/Bootloader.rb', line 1266

def getBootDevice
  ReadOrProposeIfNeeded()
  BootStorage.BootPartitionDevice
end

- (String) getDefaultSection

return default section label

Returns:

  • (String)

    default section label



1094
1095
1096
1097
1098
1099
1100
# File '../../src/modules/Bootloader.rb', line 1094

def getDefaultSection
  ReadOrProposeIfNeeded()
  default_name = checkZiplDefault(
    Ops.get(BootCommon.globals, "default", "")
  )
  default_name
end

- (String) getKernelParam(section, key)

get kernel parameters from bootloader configuration file "true" if present key without value

Parameters:

  • section (String)

    string section title, use DEFAULT for default section

  • key (String)

    string

Returns:

  • (String)

    value, “false” if not present,



1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
# File '../../src/modules/Bootloader.rb', line 1134

def getKernelParam(section, key)
  ReadOrProposeIfNeeded()
  if section == "DEFAULT"
    section = getDefaultSection
  elsif section == "LINUX_DEFAULT"
    section = getProposedDefaultSection
  end
  return "" if section == nil
  params = Convert.to_map(BootCommon.getAnyTypeAttrib("kernel_params", {}))
  sectnum = -1
  index = -1
  Builtins.foreach(BootCommon.sections) do |s|
    index = Ops.add(index, 1)
    sectnum = index if Ops.get_string(s, "name", "") == section
  end
  return "" if sectnum == -1
  line = ""
  if Builtins.contains(["root", "vgamode"], key)
    return Ops.get_string(BootCommon.sections, [sectnum, key], "false")
  else
    line = Ops.get_string(BootCommon.sections, [sectnum, "append"], "")
    return BootCommon.getKernelParamFromLine(line, key)
  end
end

- (String) getLoaderType

Get currently used bootloader, detect if not set yet

Returns:

  • (String)

    botloader type



1235
1236
1237
# File '../../src/modules/Bootloader.rb', line 1235

def getLoaderType
  BootCommon.getLoaderType(false)
end

- (Object) getProposedDefaultSection

Get default section as proposed during installation if not known, return current default section if it is of type "image", if not found return first linux section, if no present, return empty string

Returns:

  • section that was proposed as default during installation,



1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
# File '../../src/modules/Bootloader.rb', line 1107

def getProposedDefaultSection
  ReadOrProposeIfNeeded()
  defaultv = ""
  first_image = ""
  default_image = ""
  Builtins.foreach(BootCommon.sections) do |s|
    title = Ops.get_string(s, "name", "")
    if Ops.get(s, "image") != nil
      first_image = title if first_image == ""
      default_image = title if title == getDefaultSection
    end
    if defaultv == "" && Ops.get_string(s, "original_name", "") == "linux"
      defaultv = title
    end
  end
  return defaultv if defaultv != ""
  return default_image if default_image != ""
  return first_image if first_image != ""
  ""
end

- (String) getRootDevice

Get root fs device

Returns:

  • (String)

    root device



1250
1251
1252
1253
# File '../../src/modules/Bootloader.rb', line 1250

def getRootDevice
  ReadOrProposeIfNeeded()
  BootStorage.RootPartitionDevice
end

- (Object) handleSELinuxPAM



1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
# File '../../src/modules/Bootloader.rb', line 1574

def handleSELinuxPAM
  Builtins.y2milestone("handleSELinuxPAM called")
  if Mode.normal || Mode.installation
    if BootCommon.enable_selinux
      Builtins.y2milestone("call enableSELinuxPAM")
      enableSELinuxPAM
    else
      Builtins.y2milestone("call disableSELinuxPAM")
      disableSELinuxPAM
    end
  else
    Builtins.y2milestone(
      "Skip changing SELinux/AppArmor PAM config -> wrong mode"
    )
  end

  nil
end

- (Boolean) Import(settings)

Import settings from a map

Parameters:

  • settings (Hash)

    map of bootloader settings

Returns:

  • (Boolean)

    true on success



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
159
160
161
162
163
164
165
166
# File '../../src/modules/Bootloader.rb', line 124

def Import(settings)
  settings = deep_copy(settings)
  Builtins.y2milestone("Importing settings: %1", settings)
  Reset()

  BootCommon.was_read = true
  BootCommon.was_proposed = true
  BootCommon.changed = true
  BootCommon.location_changed = true

  if Ops.get(settings, "loader_type") == ""
    Ops.set(settings, "loader_type", nil)
  end
  loader_type = Ops.get_string(settings, "loader_type")
  BootCommon.setLoaderType(loader_type)
  BootCommon.getLoaderType(false)

  if !(loader_type == "grub")
    # import loader_device and selected_location only for bootloaders
    # that have not phased them out yet
    BootCommon.loader_device = Ops.get_string(settings, "loader_device", "")
    BootCommon.selected_location = Ops.get_string(
      settings,
      "loader_location",
      "custom"
    )
    # FIXME: obsolete for grub (but inactive through the outer "if" now anyway):
    # for lilo and grub, always correct the bootloader device according to
    # selected_location (or fall back to value of loader_device)
    # Why only for lilo and grub?
    if loader_type == "lilo" || loader_type == "grub" || Arch.i386 ||
        Arch.x86_64
      BootCommon.loader_device = BootCommon.GetBootloaderDevice
    end
  end

  if Ops.get_map(settings, "initrd", {}) != nil
    Initrd.Import(Ops.get_map(settings, "initrd", {}))
  end
  ret = blImport(Ops.get_map(settings, "specific", {}))
  BootCommon.write_settings = Ops.get_map(settings, "write_settings", {})
  ret
end

- (Boolean) IsHyperV(bios_data)

Check if we run in a hyperv vm.

Parameters:

  • bios_data: (Array<Hash>)

    result of SCR::Read(.probe.bios)

Returns:

  • (Boolean)

    : true if yast runs in a hyperv vm



1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
# File '../../src/modules/Bootloader.rb', line 1417

def IsHyperV(bios_data)
  bios_data = deep_copy(bios_data)
  r = DMIRead(bios_data, "sysinfo", "manufacturer") ==
    "Microsoft Corporation" &&
    DMIRead(bios_data, "sysinfo", "product") == "Virtual Machine"

  Builtins.y2milestone("Bootloader::IsHyperV = %1", r)

  r
end

- (Boolean) IsVirtualBox(bios_data)

Check if we run in a vbox vm.

Parameters:

  • bios_data: (Array<Hash>)

    result of SCR::Read(.probe.bios)

Returns:

  • (Boolean)

    : true if yast runs in a vbox vm



1403
1404
1405
1406
1407
1408
1409
1410
# File '../../src/modules/Bootloader.rb', line 1403

def IsVirtualBox(bios_data)
  bios_data = deep_copy(bios_data)
  r = DMIRead(bios_data, "sysinfo", "product") == "VirtualBox"

  Builtins.y2milestone("Bootloader::IsVirtualBox = %1", r)

  r
end

- (Object) main



22
23
24
25
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/Bootloader.rb', line 22

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 "Directory"

  Yast.import "BootELILO"
  Yast.import "BootLILO"
  Yast.import "BootGRUB"
  Yast.import "BootPOWERLILO" # The ppc-LILO File
  #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

  # Cache for the installation proposal
  @cached_proposal = nil
  @cached_settings = {}

  # 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
  Bootloader()
end

- (String) parseListDefault(names, position)

bnc #364904 Function parse zipl list names if default section is menu

Parameters:

  • string (string)

    list of names

  • position (String)

    of default name in list

Returns:

  • (String)

    name of default section from list



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# File '../../src/modules/Bootloader.rb', line 1037

def parseListDefault(names, position)
  ret = ""

  Builtins.y2milestone(
    "section names (string) list: %1 and default name position in list: %2",
    names,
    position
  )
  return ret if names == "" || position == ""

  if Builtins.search(names, ",") != nil
    tmp_names = Builtins.deletechars(names, " ")
    list_names = Builtins.splitstring(tmp_names, ",")
    ret = Ops.get(
      list_names,
      Ops.subtract(Builtins.tointeger(position), 1),
      ""
    )
  else
    ret = names
  end

  ret
end

- (Object) PreUpdate

Process update actions needed before packages update starts



352
353
354
355
356
# File '../../src/modules/Bootloader.rb', line 352

def PreUpdate
  Builtins.y2milestone("Running bootloader pre-update stuff")

  nil
end

- (Object) Propose

Propose bootloader settings



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File '../../src/modules/Bootloader.rb', line 244

def Propose
  Builtins.y2milestone("Proposing configuration")
  # always have a current target map available in the log
  Builtins.y2milestone("unfiltered target map: %1", Storage.GetTargetMap)
  BootCommon.UpdateInstallationKernelParameters
  blPropose

  BootCommon.was_proposed = true
  BootCommon.changed = true
  BootCommon.location_changed = true
  BootCommon.partitioning_last_change = Storage.GetTargetChangeTime
  BootCommon.backup_mbr = true
  Builtins.y2milestone("Proposed settings: %1", Export())

  nil
end

- (Boolean) Read

Read settings from disk

Returns:

  • (Boolean)

    true on success



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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File '../../src/modules/Bootloader.rb', line 169

def Read
  Builtins.y2milestone("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

  BootCommon.DetectDisks
  Progress.NextStage
  return false if testAbort

  ret = blRead(true, false)
  BootCommon.was_read = true
  @old_vga = getKernelParam(getDefaultSection, "vgamode")

  Progress.Finish
  return false if testAbort
  Builtins.y2debug("Read settings: %1", Export())
  ret
end

- (Object) ReadOrProposeIfNeeded

Check whether settings were read or proposed, if not, decide what to do and read or propose settings



1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
# File '../../src/modules/Bootloader.rb', line 1298

def ReadOrProposeIfNeeded
  if !(BootCommon.was_read || BootCommon.was_proposed)
    Builtins.y2milestone(
      "Stage::initial (): %1, update: %2, config: %3",
      Stage.initial,
      Mode.update,
      Mode.config
    )
    if Mode.config
      Builtins.y2milestone("Not reading settings in Mode::config ()")
      BootCommon.was_read = true
      BootCommon.was_proposed = true
    elsif Arch.ia64 && Mode.update # FIXME		&& BootELILO::efi_layout_changed)
      Builtins.y2milestone(
        "Reproposing new configuration - IPF, EFI layout has changed"
      )
      Propose()
    elsif Stage.initial && !Mode.update
      Propose()
    else
      progress_orig = Progress.set(false)
      Read()
      Progress.set(progress_orig)
      if Mode.update
        UpdateConfiguration()
        ResolveSymlinksInSections()
        BootCommon.changed = true
        BootCommon.location_changed = true
      end
    end
  end

  nil
end

- (Object) removeDummySections

bnc #450153 YaST bootloader doesn't handle kernel from add-on products in installation Remove all section with empty keys "image" and "initrd"



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File '../../src/modules/Bootloader.rb', line 758

def removeDummySections
  BootCommon.sections = Builtins.filter(BootCommon.sections) do |section|
    if Ops.get_string(section, "original_name", "") == "linux" ||
        Ops.get_string(section, "original_name", "") == "failsafe"
      if Builtins.search(
          Ops.get_string(section, "image", ""),
          "dummy_image"
        ) != nil &&
          Builtins.search(
            Ops.get_string(section, "initrd", ""),
            "dummy_initrd"
          ) != nil
        Builtins.y2milestone("Removed dummy boot section: %1", section)
        next false
      else
        next true
      end
    end
    true
  end

  nil
end

- (Object) Reset

Reset bootloader settings



240
241
242
# File '../../src/modules/Bootloader.rb', line 240

def Reset
  ResetEx(true)
end

- (Object) ResetEx(init)

Reset bootloader settings settings should be done

Parameters:

  • init (Boolean)

    boolean true if basic initialization of system-dependent



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File '../../src/modules/Bootloader.rb', line 222

def ResetEx(init)
  return if Mode.autoinst
  Builtins.y2milestone("Reseting configuration")
  BootCommon.was_proposed = false
  BootCommon.was_read = false
  BootCommon.loader_device = ""
  #	BootCommon::setLoaderType (nil);
  BootCommon.changed = false
  BootCommon.location_changed = false
  #	BootCommon::other_bl = $[];
  BootCommon.files_edited = false
  BootCommon.write_settings = {}
  blReset(init)

  nil
end

Resolve a single symlink in key image_key in section map s

Parameters:

  • section (Hash{String => Object})

    map map of section to change

  • image_key

    string key in section that contains the link

Returns:

  • section map of the changed section



932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# File '../../src/modules/Bootloader.rb', line 932

def ResolveSymlink(section, key)
  section = deep_copy(section)
  # The "-m" is needed in case the link is an absolute link, so that it does
  # not fail to resolve when the root partition is mounted in
  # Installation::destdir.
  readlink_cmd = Ops.add("/usr/bin/readlink -n -m ", Installation.destdir)
  out = {}
  newval = ""

  # FIXME: find out why we need WFM::Execute() here (as olh used it above)
  out = Convert.to_map(
    WFM.Execute(
      path(".local.bash_output"),
      Ops.add(readlink_cmd, Ops.get_string(section, key, ""))
    )
  )
  if Ops.get_integer(out, "exit", 0) == 0 &&
      Ops.get_string(out, "stdout", "") != ""
    newval = Builtins.substring(
      Ops.get_string(out, "stdout", ""),
      Builtins.size(Installation.destdir)
    )
    Builtins.y2milestone(
      "section %1: converting old %2 parameter from %3 to %4",
      Ops.get_string(section, "name", ""),
      key,
      Ops.get_string(section, key, ""),
      newval
    )
    Ops.set(section, key, newval)
  else
    Builtins.y2error(
      "section %1: failed to remap %2 parameter",
      Ops.get_string(section, "name", ""),
      key
    )
  end

  deep_copy(section)
end

- (Object) ResolveSymlinksInSections

Resolve symlinks in kernel and initrd paths, for existing linux, xen and failsafe sections FIXME: this is the plan B solution, try to solve plan A in BootCommon.ycp:CreateLinuxSection() (line 435)



977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File '../../src/modules/Bootloader.rb', line 977

def ResolveSymlinksInSections
  Builtins.y2milestone("sections before remapping: %1", BootCommon.sections)

  # change only linux, failsafe and xen sections
  BootCommon.sections = Builtins.maplist(BootCommon.sections) do |s|
    # skip sections that are not linux, xen or failsafe,
    # or that are not of type "image" (or "xen" <- needed?)
    if !Builtins.contains(
        ["linux", "xen", "failsafe"],
        Ops.get_string(s, "original_name", "")
      ) ||
        !Builtins.contains(["image", "xen"], Ops.get_string(s, "type", ""))
      Builtins.y2milestone(
        "section %1: not linux, xen or failsafe, skipping kernel and initrd remapping",
        Ops.get_string(s, "name", "")
      )
      next deep_copy(s)
    end
    # first, resolve kernel link name
    if Builtins.haskey(s, "image")
      # also skip sections that start with a grub device name
      # "(hd0,7)/boot/vmlinuz", and are not on the default (currently
      # mounted) boot partition
      if !Builtins.regexpmatch(Ops.get_string(s, "image", ""), "^(hd.*)")
        s = ResolveSymlink(s, "image")
      else
        Builtins.y2milestone(
          "section %1: skipping remapping kernel symlink on other partition: %2",
          Ops.get_string(s, "name", ""),
          Ops.get_string(s, "image", "")
        )
      end
    end
    # resolve initrd link name, but skip if it is on a non-default boot
    # partition (see above)
    if Builtins.haskey(s, "initrd")
      if !Builtins.regexpmatch(Ops.get_string(s, "initrd", ""), "^(hd.*)")
        s = ResolveSymlink(s, "initrd")
      else
        Builtins.y2milestone(
          "section %1: skipping remapping initrd symlink on other partition: %2",
          Ops.get_string(s, "name", ""),
          Ops.get_string(s, "initrd", "")
        )
      end
    end
    deep_copy(s)
  end

  Builtins.y2milestone("sections after remapping: %1", BootCommon.sections)

  nil
end

- (Boolean) RunDelayedUpdates

Set section to boot on next reboot

Parameters:

  • section

    string section to boot

Returns:

  • (Boolean)

    true on success



1283
1284
1285
1286
1287
# File '../../src/modules/Bootloader.rb', line 1283

def RunDelayedUpdates
  # perl-BL delayed section removal
  BootCommon.RunDelayedUpdates
  nil
end

- (Object) setBootDevice(device)

Set device containing /boot directory

Parameters:

  • device (String)

    string boot device



1273
1274
1275
1276
1277
1278
# File '../../src/modules/Bootloader.rb', line 1273

def setBootDevice(device)
  ReadOrProposeIfNeeded()
  BootStorage.BootPartitionDevice = device

  nil
end

- (Boolean) setKernelParam(section, key, value)

set kernel parameter to menu.lst

Parameters:

  • section (String)

    string section title, use DEFAULT for default section

  • key (String)

    string parameter key

  • value (String)

    string value, “false” to remove key, "true" to add key without value

Returns:

  • (Boolean)

    true on success



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
# File '../../src/modules/Bootloader.rb', line 1168

def setKernelParam(section, key, value)
  if !Mode.config && key == "vga" && (Arch.s390 || Arch.ppc)
    Builtins.y2warning(
      "Kernel of this architecture does not support the vga parameter"
    )
    return true
  end

  ReadOrProposeIfNeeded()

  if section == "DEFAULT"
    section = getDefaultSection
  elsif section == "LINUX_DEFAULT"
    section = getProposedDefaultSection
  end
  return false if section == nil
  sectnum = -1
  index = -1
  Builtins.foreach(BootCommon.sections) do |s|
    index = Ops.add(index, 1)
    sectnum = index if Ops.get_string(s, "name", "") == section
  end
  return false if sectnum == -1
  slabel = ""
  return false if (key == "vga" || key == "root") && value == "true"
  if Builtins.contains(["root", "vga"], key)
    if value != "false"
      if key == "vga"
        Ops.set(BootCommon.sections, [sectnum, "vgamode"], value)
      else
        Ops.set(BootCommon.sections, [sectnum, key], value)
      end
      # added flag that section was modified bnc #432651
      Ops.set(BootCommon.sections, [sectnum, "__changed"], true)
    else
      if key == "vga"
        Ops.set(
          BootCommon.sections,
          sectnum,
          Builtins.remove(
            Ops.get(BootCommon.sections, sectnum, {}),
            "vgamode"
          )
        )
      else
        Ops.set(
          BootCommon.sections,
          sectnum,
          Builtins.remove(Ops.get(BootCommon.sections, sectnum, {}), key)
        )
      end
    end
  else
    line = Ops.get_string(BootCommon.sections, [sectnum, "append"], "")
    line = BootCommon.setKernelParamToLine(line, key, value)
    Ops.set(BootCommon.sections, [sectnum, "append"], line)
    # added flag that section was modified bnc #432651
    Ops.set(BootCommon.sections, [sectnum, "__changed"], true)
  end
  BootCommon.changed = true
  ret = true
  ret
end

- (Object) setLoaderType(bootloader)

Set type of bootloader Just a wrapper to BootCommon::setLoaderType

Parameters:

  • bootloader (String)

    string type of bootloader



1242
1243
1244
1245
1246
# File '../../src/modules/Bootloader.rb', line 1242

def setLoaderType(bootloader)
  BootCommon.setLoaderType(bootloader)

  nil
end

- (Object) setRootDevice(device)

Set root fs device

Parameters:

  • device (String)

    string root device



1257
1258
1259
1260
1261
1262
# File '../../src/modules/Bootloader.rb', line 1257

def setRootDevice(device)
  ReadOrProposeIfNeeded()
  BootStorage.RootPartitionDevice = device

  nil
end

- (Object) SetWriteMode(settings)

Set settings how to write bootloader

Parameters:

  • settings (Hash{String => Object})

    map of settings



916
917
918
919
920
921
922
923
924
# File '../../src/modules/Bootloader.rb', line 916

def SetWriteMode(settings)
  settings = deep_copy(settings)
  Builtins.y2milestone("Setting mode for writing: %1", settings)
  Builtins.foreach(settings) do |k, v|
    Ops.set(BootCommon.write_settings, k, v)
  end

  nil
end

- (Object) Summary

Display bootloader summary

Returns:

  • a list of summary lines



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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File '../../src/modules/Bootloader.rb', line 264

def Summary
  ret = []

  # F#300779 - Install diskless client (NFS-root)
  # kokso: additional warning that root partition is nfs type -> bootloader will not be installed

  device = BootCommon.getBootDisk
  if device == "/dev/nfs"
    ret = Builtins.add(
      ret,
      _(
        "The boot partition is of type NFS. Bootloader cannot be installed."
      )
    )
    Builtins.y2milestone(
      "Bootloader::Summary() -> Boot partition is nfs type, bootloader will not be installed."
    )
    return deep_copy(ret)
  end
  # F#300779 - end

  ret = blSummary
  # check if default section was changed or not
  main_section = getProposedDefaultSection

  return deep_copy(ret) if main_section == nil

  return deep_copy(ret) if getLoaderType == "none"

  sectnum = BootCommon.Section2Index(main_section)

  return deep_copy(ret) if sectnum == -1

  if Ops.get_boolean(BootCommon.sections, [sectnum, "__changed"], false)
    return deep_copy(ret)
  end

  filtered_cmdline = Builtins.filterchars(
    Kernel.GetCmdLine,
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
  )

  if Ops.greater_than(Builtins.size(filtered_cmdline), 0)
    ret = Builtins.add(
      ret,
      Builtins.sformat(
        # part of summary, %1 is a part of kernel command line
        _("Added Kernel Parameters: %1"),
        Kernel.GetCmdLine
      )
    )
  end
  deep_copy(ret)
end

- (Boolean) testAbort

Check whether abort was pressed

Returns:

  • (Boolean)

    true if abort was pressed



77
78
79
80
# File '../../src/modules/Bootloader.rb', line 77

def testAbort
  return false if @test_abort == nil
  @test_abort.call
end

- (Boolean) Update(iv, uv)

Update the whole configuration

Parameters:

  • iv (Hash{String => Object})

    a map representing the installed (original) version

  • uv (Hash{String => Object})

    a map representing the version the system is upgraded to

Returns:

  • (Boolean)

    true on success



343
344
345
346
347
348
349
# File '../../src/modules/Bootloader.rb', line 343

def Update(iv, uv)
  iv = deep_copy(iv)
  uv = deep_copy(uv)
  BootCommon.installed_version = deep_copy(iv)
  BootCommon.update_version = deep_copy(uv)
  Write() # write also reads the configuration and updates it
end

- (Hash{String => Object}) updateAppend(section)

Function update append -> add console to append

Parameters:

  • map (string, any)

    boot section

Returns:

  • (Hash{String => Object})

    updated boot section



1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
# File '../../src/modules/Bootloader.rb', line 1356

def updateAppend(section)
  section = deep_copy(section)
  ret = deep_copy(section)
  if Ops.get_string(section, "append", "") != "" &&
      Ops.get_string(section, "console", "") != ""
    updated_append = BootCommon.UpdateSerialConsole(
      Ops.get_string(section, "append", ""),
      Ops.get_string(section, "console", "")
    )
    Ops.set(ret, "append", updated_append) if updated_append != nil
  end
  deep_copy(ret)
end

- (Object) UpdateConfiguration

Update read settings to new version of configuration files



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File '../../src/modules/Bootloader.rb', line 320

def UpdateConfiguration
  # first run bootloader-specific update function
  blUpdate

  # remove no more needed modules from MODULES_LOADED_ON_BOOT
  mlob = Convert.to_string(
    SCR.Read(path(".sysconfig.kernel.MODULES_LOADED_ON_BOOT"))
  )
  mod_list = Builtins.splitstring(mlob, " ")
  mod_list = Builtins.filter(mod_list) do |s|
    s != "" && s != "cdrom" && s != "ide-cd" && s != "ide-scsi"
  end
  mlob = Builtins.mergestring(mod_list, " ")
  SCR.Write(path(".sysconfig.kernel.MODULES_LOADED_ON_BOOT"), mlob)
  SCR.Write(path(".sysconfig.kernel"), nil)

  nil
end

- (Boolean) UpdateGfxMenu

Update the language of GFX menu according to currently selected language

Returns:

  • (Boolean)

    true on success



1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
# File '../../src/modules/Bootloader.rb', line 1335

def UpdateGfxMenu
  return true if getLoaderType != "lilo" && getLoaderType != "grub"

  ret = BootCommon.UpdateGfxMenuContents
  return true if !Mode.normal
  if getLoaderType == "lilo"
    # This is extreme boolshit, Bootloader::Library has to be called
    bl_command = "/sbin/lilo >> /var/log/YaST2/y2log_bootloader 2>&1"
    command_ret = 0 == SCR.Execute(path(".target.bash"), bl_command)
    if !command_ret
      Builtins.y2error("Execution of installation command failed")
      return false
    end
  end
  ret
end

- (Boolean) Write

Write bootloader settings to disk

Returns:

  • (Boolean)

    true on success



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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
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
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
# File '../../src/modules/Bootloader.rb', line 360

def Write
  ret = true

  # proposing anything is irrelevant during update, this forces reading
  # if settings weren't read before
  if Mode.update
    BootCommon.was_proposed = false
    BootCommon.changed = true
    BootCommon.location_changed = true
    BootCommon.getLoaderType(!@repeating_write)
  end

  if @repeating_write
    BootCommon.was_read = true
  else
    ReadOrProposeIfNeeded()
  end

  if Ops.get_boolean(BootCommon.write_settings, "save_all", false)
    BootCommon.save_all = true
  end
  if BootCommon.save_all
    BootCommon.changed = true
    BootCommon.location_changed = true
    Initrd.changed = true
  end

  Builtins.y2milestone("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"),
      " ",
      2,
      stages,
      titles,
      ""
    )
    Progress.NextStage
  else
    Progress.Title(Ops.get(titles, 0, ""))
  end

  params_to_save = {}

  new_vga = getKernelParam(getDefaultSection, "vgamode")
  if new_vga != @old_vga && new_vga != "false" && new_vga != "" &&
      new_vga != "ask"
    Initrd.setSplash(new_vga)
    Ops.set(params_to_save, "vgamode", new_vga) if Stage.initial
  end

  # Initialize device mapper and LVM in target system
  if Stage.initial || Mode.update
    # FIXME: should be handled by partitioner
    out = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        "test -f /sbin/devmap_mknod.sh && /sbin/devmap_mknod.sh;" +
          "test -f /sbin/vgscan && /sbin/vgscan --mknodes"
      )
    )
    if Ops.get_integer(out, "exit", 0) != 0
      Builtins.y2error("Failed to initialize device mapper")
    end
    Builtins.y2milestone(
      "Device mapper and LVM initialization output: %1",
      out
    )
  end

  # save initrd
  if (Initrd.changed || !Mode.normal) &&
      !Ops.get_boolean(
        BootCommon.write_settings,
        "forbid_save_initrd",
        false
      )
    vga = getKernelParam(getDefaultSection, "vgamode")
    if vga != "false" && vga != "" && vga != "ask"
      Initrd.setSplash(vga)
      Ops.set(params_to_save, "vgamode", new_vga) if Stage.initial
    end
    ret = Initrd.Write
    BootCommon.changed = true
  end
  Builtins.y2error("Error occurred while creating initrd") if !ret

  BootCommon.changed = true if Mode.commandline

  if !(BootCommon.changed ||
      Ops.get_boolean(
        BootCommon.write_settings,
        "initrd_changed_externally",
        false
      ))
    Builtins.y2milestone("No bootloader cfg. file saving needed, exiting") 
    #	    return true;
  end

  if Mode.normal
    Progress.NextStage
  else
    Progress.NextStep if !@repeating_write
    Progress.Title(Ops.get(titles, 1, ""))
  end

  # Write settings to /etc/sysconfig/bootloader
  Builtins.y2milestone("Saving configuration files")
  lt = getLoaderType

  SCR.Write(path(".sysconfig.bootloader.LOADER_TYPE"), lt)
  SCR.Write(path(".sysconfig.bootloader"), nil)


  Ops.set(
    params_to_save,
    "additional_failsafe_params",
    BootCommon.GetAdditionalFailsafeParams
  )
  Ops.set(params_to_save, "installation_kernel_params", Kernel.GetCmdLine)
  if Stage.initial
    SCR.Write(
      path(".target.ycp"),
      "/var/lib/YaST2/bootloader.ycp",
      params_to_save
    )
  end

  return ret if getLoaderType == "none"

  #F#300779 - Install diskless client (NFS-root)
  #kokso: bootloader will not be installed
  device = BootCommon.getBootDisk

  if device == "/dev/nfs"
    Builtins.y2milestone(
      "Bootloader::Write() -> Boot partition is nfs type, bootloader will not be installed."
    )
    return ret
  end

  #F#300779 -end

  # update graphics menu where possible
  UpdateGfxMenu()

  # save bootloader settings
  reinit = !(Mode.update || Mode.normal)
  Builtins.y2milestone(
    "Reinitialize bootloader library before saving: %1",
    reinit
  )
  ret = blSave(true, reinit, true) && ret

  if !ret
    Builtins.y2error("Error before configuration files saving finished")
  end

  if Mode.normal
    Progress.NextStage
  else
    Progress.NextStep if !@repeating_write
    Progress.Title(Ops.get(titles, 2, ""))
  end

  # call bootloader executable
  Builtins.y2milestone("Calling bootloader executable")
  ret = ret && blWrite
  # FATE#305557: Enable SELinux for 11.2
  createSELinuxDir
  handleSELinuxPAM
  if !ret
    Builtins.y2error("Installing bootloader failed")
    if writeErrorPopup
      @repeating_write = true
      res = Convert.to_map(
        WFM.call(
          "bootloader_proposal",
          ["AskUser", { "has_next" => false }]
        )
      )
      return Write() if Ops.get(res, "workflow_sequence") == :next
    end
  else
    if BootCommon.InstallingToFloppy
      BootCommon.updateTimeoutPopupForFloppy(
        BootCommon.getLoaderName(getLoaderType, :summary)
      )
    end
  end

  ret
end

- (Boolean) WriteInstallation

Write bootloader settings during installation

Returns:

  • (Boolean)

    true on success



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
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
634
635
636
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
# File '../../src/modules/Bootloader.rb', line 577

def WriteInstallation
  Builtins.y2milestone(
    "Writing bootloader configuration during installation"
  )
  ret = true

  if !Mode.live_installation
    # bnc#449785 - Installing of GRUB fails when using live installer from a USB stick
    # read current settings...
    ret = blRead(true, false)
    # delete duplicated sections
    DelDuplicatedSections()
  else
    # resolve sim links for image and initrd
    # bnc #393030 - live-CD kernel install/remove leaves broken system
    ResolveSymlinksInSections()
  end
  if Ops.get_boolean(BootCommon.write_settings, "save_all", false)
    BootCommon.save_all = true
  end
  if BootCommon.save_all
    BootCommon.changed = true
    BootCommon.location_changed = true
    Initrd.changed = true
  end

  params_to_save = {}

  new_vga = getKernelParam(getDefaultSection, "vgamode")
  if new_vga != @old_vga && new_vga != "false" && new_vga != ""
    Initrd.setSplash(new_vga)
    Ops.set(params_to_save, "vgamode", new_vga) if Stage.initial
  end


  # save initrd
  if (Initrd.changed || !Mode.normal) &&
      !Ops.get_boolean(
        BootCommon.write_settings,
        "forbid_save_initrd",
        false
      )
    vga = getKernelParam(getDefaultSection, "vgamode")
    if vga != "false" && vga != ""
      Initrd.setSplash(vga)
      Ops.set(params_to_save, "vgamode", new_vga) if Stage.initial
    end
    ret = Initrd.Write
    BootCommon.changed = true
  end

  Builtins.y2error("Error occurred while creating initrd") if !ret

  Ops.set(
    params_to_save,
    "additional_failsafe_params",
    BootCommon.GetAdditionalFailsafeParams
  )
  Ops.set(params_to_save, "installation_kernel_params", Kernel.GetCmdLine)

  if Stage.initial
    SCR.Write(
      path(".target.ycp"),
      "/var/lib/YaST2/bootloader.ycp",
      params_to_save
    )
  end

  return ret if getLoaderType == "none"

  # F#300779 - Install diskless client (NFS-root)
  # kokso: bootloader will not be installed
  device = BootCommon.getBootDisk

  if device == "/dev/nfs"
    Builtins.y2milestone(
      "Bootloader::Write() -> Boot partition is nfs type, bootloader will not be installed."
    )
    return ret
  end

  # F#300779 -end

  # update graphics menu where possible
  UpdateGfxMenu()

  # save bootloader settings
  reinit = !(Mode.update || Mode.normal)
  Builtins.y2milestone(
    "Reinitialize bootloader library before saving: %1",
    reinit
  )


  ret = blSave(true, reinit, true) && ret

  if !ret
    Builtins.y2error("Error before configuration files saving finished")
  end


  # call bootloader executable
  Builtins.y2milestone("Calling bootloader executable")
  ret = ret && blWrite
  # FATE#305557: Enable SELinux for 11.2
  createSELinuxDir
  handleSELinuxPAM
  if !ret
    Builtins.y2error("Installing bootloader failed")
    if writeErrorPopup
      @repeating_write = true
      res = Convert.to_map(
        WFM.call(
          "bootloader_proposal",
          ["AskUser", { "has_next" => false }]
        )
      )
      return Write() if Ops.get(res, "workflow_sequence") == :next
    end
  else
    if BootCommon.InstallingToFloppy
      BootCommon.updateTimeoutPopupForFloppy(
        BootCommon.getLoaderName(getLoaderType, :summary)
      )
    end
  end
  ret
end