Class: Yast::BootGRUB2Class

Inherits:
GRUB2Base
  • Object
show all
Defined in:
src/modules/BootGRUB2.rb

Instance Method Summary (collapse)

Methods inherited from GRUB2Base

#Initializer, #Reset, #Save, #StandardGlobals, #Update, #pmbr_setup

Instance Method Details

- (Object) BootGRUB2

Constructor



329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'src/modules/BootGRUB2.rb', line 329

def BootGRUB2
  Ops.set(
    BootCommon.bootloader_attribs,
    "grub2",
    {
      # we need syslinux to have generic mbr bnc#885496
      "required_packages" => ["grub2", "syslinux"],
      "loader_name"       => "GRUB2",
      "initializer"       => fun_ref(method(:Initializer), "void ()")
    }
  )

  nil
end

- (Object) Dialogs



295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'src/modules/BootGRUB2.rb', line 295

def Dialogs
  Builtins.y2milestone("Called GRUB2 Dialogs")
  {
    "installation" => fun_ref(
      method(:Grub2InstallDetailsDialog),
      "symbol ()"
    ),
    "loader"       => fun_ref(
      method(:Grub2LoaderDetailsDialog),
      "symbol ()"
    )
  }
end

- (Object) GetFunctions

Return map of provided functions

Returns:

  • a map of functions (eg. $[“write”:BootGRUB2::Write])



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'src/modules/BootGRUB2.rb', line 311

def GetFunctions
  {
    "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 ()"),
    "widgets" => fun_ref(
      method(:grub2Widgets),
      "map <string, map <string, any>> ()"
    ),
    "dialogs" => fun_ref(method(:Dialogs), "map <string, symbol ()> ()"),
    "write"   => fun_ref(method(:Write), "boolean ()")
  }
end

- (Object) main



31
32
33
34
35
36
37
38
39
40
# File 'src/modules/BootGRUB2.rb', line 31

def main
  super

  textdomain "bootloader"

  # includes
  # for shared some routines with grub
  Yast.include self, "bootloader/grub2/misc.rb"
  BootGRUB2()
end

- (Object) prep_partitions



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'src/modules/BootGRUB2.rb', line 169

def prep_partitions
  target_map = Storage.GetTargetMap

  partitions = target_map.reduce([]) do |parts, pair|
    parts.concat(pair[1]["partitions"] || [])
  end

  prep_partitions = partitions.select do |partition|
    [0x41, 0x108].include? partition["fsid"]
  end

  y2milestone "detected prep partitions #{prep_partitions.inspect}"
  prep_partitions.map { |p| p["device"] }
end

- (Object) Propose



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
167
# File 'src/modules/BootGRUB2.rb', line 134

def Propose
  super

  # do not repropose, only in autoinst mode to allow propose missing parts
  if !BootCommon.was_proposed || Mode.autoinst || Mode.autoupgrade
    case Arch.architecture
    when "i386", "x86_64"
      grub_LocationProposal
      # pass vga if available (bnc#896300)
      if !Kernel.GetVgaType.empty?
        BootCommon.globals["vgamode"]= Kernel.GetVgaType
      end
    when /ppc/
      partition = prep_partitions.first
      if partition
        BootCommon.globals["boot_custom"] = partition
      else
        # handle diskless setup, in such case do not write boot code anywhere (bnc#874466)
        # we need to detect what is mount on /boot and if it is nfs, then just
        # skip this proposal. In other case if it is not nfs, then it is error and raise exception
        BootCommon.DetectDisks
        if BootCommon.getBootDisk == "/dev/nfs"
          return
        else
          raise "there is no prep partition"
        end
      end
    when /s390/
      Builtins.y2milestone "no partition needed for grub2 on s390"
    else
      raise "unsuported architecture #{Arch.architecture}"
    end
  end
end

- (Boolean) Read(reread, avoid_reading_device_map)

Read settings from disk internal data

Parameters:

  • reread (Boolean)

    boolean true to force reread settings from system

  • avoid_reading_device_map (Boolean)

    do not read new device map from file, use

Returns:

  • (Boolean)

    true on success



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

def Read(reread, avoid_reading_device_map)
  BootCommon.InitializeLibrary(reread, "grub2")
  BootCommon.ReadFiles(avoid_reading_device_map) if reread
  # TODO: check if necessary for grub2
  grub_DetectDisks
  ret = BootCommon.Read(false, avoid_reading_device_map)

  # TODO: check if necessary for grub2
  # refresh device map if not read
  if BootStorage.device_mapping == nil ||
      Builtins.size(BootStorage.device_mapping) == 0
    BootStorage.ProposeDeviceMap
  end

  if Mode.normal
    md_value = BootStorage.addMDSettingsToGlobals
    pB_md_value = Ops.get(BootCommon.globals, "boot_md_mbr", "")
    if pB_md_value != ""
      disks = Builtins.splitstring(pB_md_value, ",")
      disks = Builtins.filter(disks) { |v| v != "" }
      if Builtins.size(disks) == 2
        BootCommon.enable_md_array_redundancy = true
        md_value = ""
      end
      Builtins.y2milestone(
        "disks from md array (perl Bootloader): %1",
        disks
      )
    end
    if md_value != ""
      BootCommon.enable_md_array_redundancy = false
      Ops.set(BootCommon.globals, "boot_md_mbr", md_value)
      Builtins.y2milestone(
        "Add md array to globals: %1",
        BootCommon.globals
      )
    end
  end

  @orig_globals ||= deep_copy(BootCommon.globals)
  ret
end

- (Object) Summary

Display bootloader summary

Returns:

  • a list of summary lines



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

def Summary
  result = [
    Builtins.sformat(
      _("Boot Loader Type: %1"),
      BootCommon.getLoaderName(BootCommon.getLoaderType(false), :summary)
    )
  ]
  locations = []

  if BootCommon.globals["boot_boot"] == "true"
    locations << BootStorage.BootPartitionDevice + " (\"/boot\")"
  end
  if BootCommon.globals["boot_extended"] == "true"
    # TRANSLATORS: extended is here for extended partition. Keep translation short.
    locations << BootStorage.ExtendedPartitionDevice + _(" (extended)")
  end
  if BootCommon.globals["boot_root"] == "true"
    locations << BootStorage.RootPartitionDevice + " (\"/\")"
  end
  if BootCommon.globals["boot_mbr"] == "true"
    # TRANSLATORS: MBR is acronym for Master Boot Record, if nothing locally specific
    # is used in your language, then keep it as it is.
    locations << BootCommon.mbrDisk + _(" (MBR)")
  end
  if BootCommon.globals["boot_custom"] && !BootCommon.globals["boot_custom"].empty?
    locations << BootCommon.globals["boot_custom"]
  end
  if !locations.empty?
    result << Builtins.sformat(
        _("Status Location: %1"),
        locations.join(", ")
      )
  end

  # it is necessary different summary for autoyast and installation
  # other mode than autoyast on running system
  # both ppc and s390 have special devices for stage1 so it do not make sense
  # allow change of location to MBR or boot partition (bnc#879107)
  if !Arch.ppc && !Arch.s390 && !Mode.config
    result << urlLocationSummary
  end

  order_sum = BootCommon.DiskOrderSummary
  result << order_sum if order_sum

  return result
end

- (Object) urlLocationSummary

FATE#303643 Enable one-click changes in bootloader proposal



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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'src/modules/BootGRUB2.rb', line 187

def urlLocationSummary
  Builtins.y2milestone("Prepare url summary for GRUB2")
  line = "<ul>\n<li>"
  if BootCommon.globals["boot_mbr"] == "true"
    line << _(
      "Install bootcode into MBR (<a href=\"disable_boot_mbr\">do not install</a>)"
    )
  else
    line << _(
      "Do not install bootcode into MBR (<a href=\"enable_boot_mbr\">install</a>)"
    )
  end
  line << "</li>\n"

  # do not allow to switch on boot from partition that do not support it
  if BootStorage.can_boot_from_partition
    line << "<li>"

    # check for separated boot partition, use root otherwise
    if BootStorage.BootPartitionDevice != BootStorage.RootPartitionDevice
      if BootCommon.globals["boot_boot"] == "true"
        line << _(
          "Install bootcode into /boot partition (<a href=\"disable_boot_boot\">do not install</a>)"
        )
      else
        line << _(
          "Do not install bootcode into /boot partition (<a href=\"enable_boot_boot\">install</a>)"
        )
      end
    else
      if BootCommon.globals["boot_root"] == "true"
        line << _(
          "Install bootcode into \"/\" partition (<a href=\"disable_boot_root\">do not install</a>)"
        )
      else
        line << _(
          "Do not install bootcode into \"/\" partition (<a href=\"enable_boot_root\">install</a>)"
        )
      end
    end
    line << "</li>"
  end

  if ["boot_root", "boot_boot", "boot_mbr"].none? { |loc| BootCommon.globals[loc] == "true" }
      # no location chosen, so warn user that it is problem unless he is sure
      msg = _("Warning: No location for bootloader stage1 selected." \
        "Unless you know what you are doing please select above location.")
      line << "<li>" << HTML.Colorize(msg, "red") << "</li>"
  end

  line << "</ul>"

  # TRANSLATORS: title for list of location proposals
  return _("Change Location: %s") % line
end

- (Boolean) Write

Write bootloader settings to disk

Returns:

  • (Boolean)

    true on success



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

def Write
  ret = BootCommon.UpdateBootloader

  if @orig_globals
    location = ["boot_mbr", "boot_boot", "boot_root", "boot_extended", "boot_custom", "boot_custom", "activate", "generic_mbr"]
    location.each do |i|
       BootCommon.location_changed = true if @orig_globals[i] != BootCommon.globals[i]
    end
  else
    # there is no original, so we do not read config, but propose it
    BootCommon.location_changed = true
  end

  if BootCommon.location_changed
    # bnc #461613 - Unable to boot after making changes to boot loader
    # bnc #357290 - module rewrites grub generic code when leaving with no changes, which may corrupt grub
    grub_updateMBR

    grub_ret = BootCommon.InitializeBootloader
    grub_ret = false if grub_ret == nil

    Builtins.y2milestone("GRUB return value: %1", grub_ret)
    ret = ret && grub_ret
    ret = ret && BootCommon.PostUpdateMBR
  end

  # something with PMBR needed
  if BootCommon.pmbr_action
    boot_devices = BootCommon.GetBootloaderDevices
    boot_discs = boot_devices.map {|d| Storage.GetDisk(Storage.GetTargetMap, d)}
    boot_discs.uniq!
    gpt_disks = boot_discs.select {|d| d["label"] == "gpt" }
    gpt_disks_devices = gpt_disks.map {|d| d["device"] }

    pmbr_setup(BootCommon.pmbr_action, *gpt_disks_devices)
  end

  ret
end