Class: Yast::BootGRUB2Class

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) BootGRUB2

Constructor



438
439
440
441
442
443
444
445
446
447
448
449
450
# File '../../src/modules/BootGRUB2.rb', line 438

def BootGRUB2
  Ops.set(
    BootCommon.bootloader_attribs,
    "grub2",
    {
      "required_packages" => ["grub2"],
      "loader_name"       => "GRUB2",
      "initializer"       => fun_ref(method(:Initializer), "void ()")
    }
  )

  nil
end

- (Object) Dialogs



391
392
393
394
395
396
397
398
399
400
401
402
403
# File '../../src/modules/BootGRUB2.rb', line 391

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])



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File '../../src/modules/BootGRUB2.rb', line 407

def GetFunctions
  {
    "read"    => fun_ref(method(:Read), "boolean (boolean, boolean)"),
    "reset"   => fun_ref(method(:Reset), "void (boolean)"),
    "propose" => fun_ref(method(:Propose), "void ()"),
    "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) Initializer

Initializer of GRUB bootloader



424
425
426
427
428
429
430
431
432
433
434
435
# File '../../src/modules/BootGRUB2.rb', line 424

def Initializer
  Builtins.y2milestone("Called GRUB2 initializer")
  BootCommon.current_bootloader_attribs = {
    "propose"            => false,
    "read"               => false,
    "scratch"            => false,
    "restore_mbr"        => false,
    "bootloader_on_disk" => false
  }

  nil
end

- (Object) main



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

def main
  Yast.import "UI"

  textdomain "bootloader"

  Yast.import "BootArch"
  Yast.import "BootCommon"
  Yast.import "BootStorage"
  Yast.import "Kernel"
  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "Storage"
  Yast.import "StorageDevices"
  Yast.import "Pkg"
  Yast.import "HTML"
  Yast.import "Initrd"
  Yast.import "Product"

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

- (Object) Propose

Propose bootloader settings



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File '../../src/modules/BootGRUB2.rb', line 157

def Propose
  if BootCommon.was_proposed
    # workaround autoyast config is Imported thus was_proposed always set 
    if Mode.autoinst
      Builtins.y2milestone(
        "autoinst mode we ignore meaningless was_proposed as it always set"
      )
    else
      Builtins.y2milestone(
        "calling Propose with was_proposed set is really bogus, clear it to force a re-propose"
      )
      return
    end
  end

  if BootCommon.globals == nil || Builtins.size(BootCommon.globals) == 0
    BootCommon.globals = StandardGlobals()
  else
    BootCommon.globals = Convert.convert(
      Builtins.union(BootCommon.globals, StandardGlobals()),
      :from => "map",
      :to   => "map <string, string>"
    )
  end

  grub_LocationProposal

  swap_sizes = BootCommon.getSwapPartitions
  swap_parts = Builtins.maplist(swap_sizes) { |name, size| name }
  swap_parts = Builtins.sort(swap_parts) do |a, b|
    Ops.greater_than(Ops.get(swap_sizes, a, 0), Ops.get(swap_sizes, b, 0))
  end

  largest_swap_part = Ops.get(swap_parts, 0, "")

  resume = BootArch.ResumeAvailable ? largest_swap_part : ""
  # try to use label or udev id for device name... FATE #302219
  if resume != "" && resume != nil
    resume = BootStorage.Dev2MountByDev(resume)
  end
  Ops.set(
    BootCommon.globals,
    "append",
    BootArch.DefaultKernelParams(resume)
  )
  Ops.set(
    BootCommon.globals,
    "append_failsafe",
    BootArch.FailsafeKernelParams
  )
  Ops.set(
    BootCommon.globals,
    "distributor",
    Ops.add(Ops.add(Product.short_name, " "), Product.version)
  )
  BootCommon.kernelCmdLine = Kernel.GetCmdLine

  Builtins.y2milestone("Proposed globals: %1", BootCommon.globals) 

  # Let grub2 scripts detects correct root= for us. :)
  # BootCommon::globals["root"] = BootStorage::Dev2MountByDev(BootStorage::RootPartitionDevice);

  # We don't set vga= if Grub2 gfxterm enabled, because the modesettings
  # will be delivered to kernel by Grub2's gfxpayload set to "keep"
  #if (BootArch::VgaAvailable () && Kernel::GetVgaType () != "")
  #{
  #    BootCommon::globals["vgamode"] = Kernel::GetVgaType ();
  #}

  nil
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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File '../../src/modules/BootGRUB2.rb', line 70

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 md_value != pB_md_value
      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
  end

  ret
end

- (Object) Reset(init)

Reset bootloader settings

Parameters:

  • init (Boolean)

    boolean true to repropose also device map



148
149
150
151
152
153
# File '../../src/modules/BootGRUB2.rb', line 148

def Reset(init)
  return if Mode.autoinst
  BootCommon.Reset(init)

  nil
end

- (Object) StandardGlobals

Propose global options of bootloader



54
55
56
57
58
59
60
61
62
63
# File '../../src/modules/BootGRUB2.rb', line 54

def StandardGlobals
  {
    "timeout"   => "8",
    "default"   => "0",
    "vgamode"   => "",
    "gfxmode"   => "auto",
    "terminal"  => "gfxterm",
    "os_prober" => "true"
  }
end

- (Object) Summary

Display bootloader summary

Returns:

  • a list of summary lines



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File '../../src/modules/BootGRUB2.rb', line 332

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

  if Ops.get(BootCommon.globals, "boot_boot", "") == "true"
    locations = Builtins.add(
      locations,
      Ops.add(BootStorage.BootPartitionDevice, _(" (\"/boot\")"))
    )
  end
  if Ops.get(BootCommon.globals, "boot_extended", "") == "true"
    locations = Builtins.add(
      locations,
      Ops.add(BootStorage.ExtendedPartitionDevice, _(" (extended)"))
    )
  end
  if Ops.get(BootCommon.globals, "boot_root", "") == "true"
    locations = Builtins.add(
      locations,
      Ops.add(BootStorage.RootPartitionDevice, _(" (\"/\")"))
    )
  end
  if Ops.get(BootCommon.globals, "boot_mbr", "") == "true"
    locations = Builtins.add(
      locations,
      Ops.add(BootCommon.mbrDisk, _(" (MBR)"))
    )
  end
  if Builtins.haskey(BootCommon.globals, "boot_custom")
    locations = Builtins.add(
      locations,
      Ops.get(BootCommon.globals, "boot_custom", "")
    )
  end
  if Ops.greater_than(Builtins.size(locations), 0)
    # FIXME: should we translate all devices to names and add MBR suffixes?
    result = Builtins.add(
      result,
      Builtins.sformat(
        _("Status Location: %1"),
        Builtins.mergestring(locations, ", ")
      )
    )
  end

  # it is necessary different summary for autoyast and installation
  # other mode than autoyast on running system
  result = Builtins.add(result, urlLocationSummary) if !Mode.config

  order_sum = BootCommon.DiskOrderSummary
  result = Builtins.add(result, order_sum) if order_sum != nil
  deep_copy(result)
end

- (Object) Update

Update read settings to new version of configuration files



115
116
117
118
119
120
121
122
123
# File '../../src/modules/BootGRUB2.rb', line 115

def Update
  Read(true, true)

  #we don't handle sections, grub2 section create them for us
  #BootCommon::UpdateSections ();
  BootCommon.UpdateGlobals

  nil
end

- (Object) urlLocationSummary

FATE#303643 Enable one-click changes in bootloader proposal



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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File '../../src/modules/BootGRUB2.rb', line 232

def urlLocationSummary
  Builtins.y2milestone("Prepare url summary for GRUB")
  ret = ""
  line = ""
  locations = []
  line = "<ul>\n<li>"
  if Ops.get(BootCommon.globals, "boot_mbr", "") == "true"
    line = Ops.add(
      Ops.add(
        line,
        _(
          "Boot from MBR is enabled (<a href=\"disable_boot_mbr\">disable</a>"
        )
      ),
      ")</li>\n"
    )
  else
    line = Ops.add(
      Ops.add(
        line,
        _(
          "Boot from MBR is disabled (<a href=\"enable_boot_mbr\">enable</a>"
        )
      ),
      ")</li>\n"
    )
  end
  locations = Builtins.add(locations, line)
  line = "<li>"

  set_boot_boot = false
  if Ops.get(BootCommon.globals, "boot_boot", "") == "true" &&
      BootStorage.BootPartitionDevice != BootStorage.RootPartitionDevice
    set_boot_boot = true
    line = Ops.add(
      Ops.add(
        line,
        _(
          "Boot from /boot partition is enabled (<a href=\"disable_boot_boot\">disable</a>"
        )
      ),
      ")</li></ul>"
    )
  elsif Ops.get(BootCommon.globals, "boot_boot", "") == "false" &&
      BootStorage.BootPartitionDevice != BootStorage.RootPartitionDevice
    set_boot_boot = true
    line = Ops.add(
      Ops.add(
        line,
        _(
          "Boot from /boot partition is disabled (<a href=\"enable_boot_boot\">enable</a>"
        )
      ),
      ")</li></ul>"
    )
  end
  if line != "<li>"
    locations = Builtins.add(locations, line)
    line = "<li>"
  end
  if Ops.get(BootCommon.globals, "boot_root", "") == "true" &&
      !set_boot_boot
    line = Ops.add(
      Ops.add(
        line,
        _(
          "Boot from \"/\" partition is enabled (<a href=\"disable_boot_root\">disable</a>"
        )
      ),
      ")</li></ul>"
    )
  elsif Ops.get(BootCommon.globals, "boot_root", "") == "false" &&
      !set_boot_boot
    line = Ops.add(
      Ops.add(
        line,
        _(
          "Boot from \"/\" partition is disabled (<a href=\"enable_boot_root\">enable</a>"
        )
      ),
      ")</li></ul>"
    )
  end
  locations = Builtins.add(locations, line) if !set_boot_boot

  if Ops.greater_than(Builtins.size(locations), 0)
    # FIXME: should we translate all devices to names and add MBR suffixes?
    ret = Builtins.sformat(
      _("Change Location: %1"),
      Builtins.mergestring(locations, " ")
    )
  end

  ret
end

- (Boolean) Write

Write bootloader settings to disk

Returns:

  • (Boolean)

    true on success



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File '../../src/modules/BootGRUB2.rb', line 126

def Write
  ret = BootCommon.UpdateBootloader

  #TODO: InstallingToFloppy ..
  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

  ret
end