Class: Yast::BootloaderClass

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

Constant Summary

BOOLEAN_MAPPING =
{ true => :present, false => :missing }
FLAVOR_KERNEL_LINE_MAP =
{
  :common    => "append",
  :xen_guest => "xen_append",
  :xen_host  => "xen_kernel_append"
}

Instance Method Summary (collapse)

Instance Method Details

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



80
81
82
# File 'src/modules/Bootloader.rb', line 80

def checkUsedStorage
  Storage.InitLibstorage(true) || !Mode.normal
end

- (Object) Export

Export bootloader settings to a map

Returns:

  • bootloader settings



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'src/modules/Bootloader.rb', line 86

def Export
  ReadOrProposeIfNeeded()
  # TODO: implement it using new way
  #      out = {
  #        "loader_type"     => getLoaderType,
  #        "initrd"          => Initrd.Export,
  #        "specific"        => blExport,
  #        "write_settings"  => BootCommon.write_settings,
  #        "loader_device"   => BootCommon.loader_device,
  #        "loader_location" => BootCommon.selected_location
  #      }
  #      log.info "Exporting settings: #{out}"
  #      out
  {}
end

- (String) getDefaultSection

return default section label

Returns:

  • (String)

    default section label



338
339
340
341
342
343
# File 'src/modules/Bootloader.rb', line 338

def getDefaultSection
  ReadOrProposeIfNeeded()

  ""
  # FIXME: use bootloader factory to get it
end

- (String) getLoaderType

Get currently used bootloader, detect if not set yet

Returns:

  • (String)

    botloader type



477
478
479
# File 'src/modules/Bootloader.rb', line 477

def getLoaderType
  ::Bootloader::BootloaderFactory.current.name
end

- (Boolean) Import(settings)

Import settings from a map

Parameters:

  • settings (Hash)

    map of bootloader settings

Returns:

  • (Boolean)

    true on success



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'src/modules/Bootloader.rb', line 105

def Import(settings)
  settings = deep_copy(settings)
  log.info "Importing settings: #{settings}"
  # TODO: implement it using new way
  #      Reset()
  #
  #      BootCommon.was_read = true
  #      BootCommon.was_proposed = true
  #      BootCommon.changed = true
  #      BootCommon.location_changed = true
  #
  #      settings["loader_type"] = nil if settings["loader_type"] == ""
  #      # if bootloader is not set, then propose it
  #      loader_type = settings["loader_type"] || BootCommon.getLoaderType(true)
  #      # Explitelly set it to ensure it is installed
  #      BootCommon.setLoaderType(loader_type)
  #
  #      # import loader_device and selected_location only for bootloaders
  #      # that have not phased them out yet
  #      BootCommon.loader_device = settings["loader_device"] || ""
  #      BootCommon.selected_location = settings["loader_location"] || "custom"
  #
  #      # FIXME: obsolete for grub (but inactive through the outer "if" now anyway):
  #      # for grub, always correct the bootloader device according to
  #      # selected_location (or fall back to value of loader_device)
  #      if Arch.i386 || Arch.x86_64
  #        BootCommon.loader_device = BootCommon.GetBootloaderDevice
  #      end
  #
  #      Initrd.Import(settings["initrd"] || {})
  #      ret = blImport(settings["specific"] || {})
  #      BootCommon.write_settings = settings["write_settings"] || {}
  #      ret
end

- (Object) kernel_param(flavor, key)

Gets value for given parameter in kernel parameters for given flavor.

Examples:

get crashkernel parameter to common kernel

Bootloader.kernel_param(:common, "crashkernel")
=> "256M@64B"

get cio_ignore parameter for xen_host kernel when missing

Bootloader.kernel_param(:xen_host, "cio_ignore")
=> :missing

get verbose parameter for xen_guest which is there

Bootloader.kernel_param(:xen_guest, "verbose")
=> :present

Parameters:

  • flavor (Symbol)

    flavor of kernel, for possible values see #modify_kernel_param

  • key (String)

    of parameter on kernel command line



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'src/modules/Bootloader.rb', line 370

def kernel_param(flavor, key)
  if flavor == :recovery
    log.warn "Using deprecated recovery flavor"
    return :missing
  end

  ReadOrProposeIfNeeded() # ensure we have some data

  current_bl = ::Bootloader::BootloaderFactory.current
  # currently only grub2 bootloader supported
  return :missing unless current_bl.respond_to?(:grub_default)
  grub_default = current_bl.grub_default
  params = case flavor
           when :common then grub_default.kernel_params
           when :xen_guest then grub_default.xen_kernel_params
           when :xen_host then grub_default.xen_hypervisor_params
           else raise ArgumentError, "Unknown flavor #{flavor}"
           end

  res = params.parameter(key)

  BOOLEAN_MAPPING[res] || res
end

- (Object) main



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

def main
  Yast.import "UI"

  textdomain "bootloader"

  Yast.import "Arch"
  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 "StorageDevices"
  Yast.import "Directory"

  # 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

  # old vga value handling function

  # old value of vga parameter of default bootloader section
  @old_vga = nil

  # general functions

  @test_abort = nil
end

- (Boolean) modify_kernel_params(*args)

Modify kernel parameters for installed kernels according to values

Examples:

add crashkernel parameter to common kernel and xen guest

Bootloader.modify_kernel_params(:common, :xen_guest, "crashkernel" => "256M@64M")

same as before just with array passing

targets = [:common, :xen_guest]
Bootloader.modify_kernel_params(targets, "crashkernel" => "256M@64M")

remove cio_ignore parameter for common kernel only

Bootloader.modify_kernel_params("cio_ignore" => :missing)

add cio_ignore parameter for xen host kernel

Bootloader.modify_kernel_params(:xen_host, "cio_ignore" => :present)

Parameters:

  • args (Array)

    parameters to modify. Last parameter is hash with keys and its values, keys are strings and values are :present, :missing or string value. Other parameters specify which kernel flavors are affected. Known values are: - :common for non-specific flavor - :recovery DEPRECATED: no longer use - :xen_guest for xen guest kernels - :xen_host for xen host kernels

Returns:

  • (Boolean)

    true if params were modified; false otherwise.



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

def modify_kernel_params(*args)
  current_bl = ::Bootloader::BootloaderFactory.current
  # currently only grub2 bootloader supported
  return :missing unless current_bl.respond_to?(:grub_default)
  grub_default = current_bl.grub_default

  values = args.pop
  if !values.is_a? Hash
    raise ArgumentError, "Missing parameters to modify #{args.inspect}"
  end
  args = [:common] if args.empty? # by default change common kernels only
  args = args.first if args.first.is_a? Array # support array like syntax

  if args.include?(:recovery)
    args.delete(:recovery)
    log.warn "recovery flavor is deprecated and not set"
  end

  remap_values = BOOLEAN_MAPPING.invert
  values.each_key do |key|
    values[key] = remap_values[values[key]] if remap_values.key?(values[key])
  end

  params = args.map do |flavor|
    case flavor
    when :common then grub_default.kernel_params
    when :xen_guest then grub_default.xen_kernel_params
    when :xen_host then grub_default.xen_hypervisor_params
    else raise ArgumentError, "Unknown flavor #{flavor}"
    end
  end

  changed = false
  values.each do |key, value|
    params.each do |param|
      old_val = param.parameter(key)
      next if old_val == value

      changed = true
      # at first clean old entries
      matcher = CFA::Matcher.new(key: key)
      param.remove_parameter(matcher)

      case value
      when false then next # already done
      when true then param.add_parameter(key, value)
      when Array
        value.each { |val| param.add_parameter(key, val) }
      else
        param.add_parameter(key, value)
      end
    end
  end

  changed
end

- (Object) Propose

Propose bootloader settings



210
211
212
213
214
215
216
217
218
219
# File 'src/modules/Bootloader.rb', line 210

def Propose
  log.info "Proposing configuration"
  # always have a current target map available in the log
  log.info "unfiltered target map: #{Storage.GetTargetMap.inspect}"
  ::Bootloader::BootloaderFactory.current.propose

  log.info "Proposed settings: #{Export()}"

  nil
end

- (Boolean) Read

Read settings from disk

Returns:

  • (Boolean)

    true on success



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

def Read
  log.info "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

  # While calling "yast clone_system" and while cloning bootloader
  # in the AutoYaST module, libStorage has to be set to "normal"
  # mode in order to read mountpoints correctly.
  # (bnc#950105)
  old_mode = Mode.mode
  if Mode.config
    Mode.SetMode("normal")
    StorageDevices.InitDone # Set StorageDevices flag disks_valid to true
  end

  BootStorage.detect_disks
  Mode.SetMode(old_mode) if old_mode == "autoinst_config"

  Progress.NextStage
  return false if testAbort

  ::Bootloader::BootloaderFactory.current.read

  Progress.Finish

  true
end

- (Object) ReadOrProposeIfNeeded

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



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'src/modules/Bootloader.rb', line 483

def ReadOrProposeIfNeeded
  current_bl = ::Bootloader::BootloaderFactory.current
  return if current_bl.read? || current_bl.proposed?

  if Mode.config
    log.info "Initialize libstorage in readonly mode" # bnc#942360
    Storage.InitLibstorage(true)
    log.info "Not reading settings in Mode::config ()"
    Propose()
  elsif Stage.initial && !Mode.update
    Propose()
  else
    progress_orig = Progress.set(false)
    Read()
    Progress.set(progress_orig)
  end
end

- (Object) Reset

Reset bootloader settings



201
202
203
204
205
206
207
# File 'src/modules/Bootloader.rb', line 201

def Reset
  return if Mode.autoinst
  log.info "Reseting configuration"
  # TODO: consider what to actually do in reset

  nil
end

- (Object) Summary

Display bootloader summary

Returns:

  • a list of summary lines



223
224
225
226
227
228
229
230
231
# File 'src/modules/Bootloader.rb', line 223

def Summary
  # kokso: additional warning that root partition is nfs type -> bootloader will not be installed
  if BootStorage.disk_with_boot_partition == "/dev/nfs"
    log.info "Bootloader::Summary() -> Boot partition is nfs type, bootloader will not be installed."
    return _("The boot partition is of type NFS. Bootloader cannot be installed.")
  end

  ::Bootloader::BootloaderFactory.current.summary
end

- (Boolean) testAbort

Check whether abort was pressed

Returns:

  • (Boolean)

    true if abort was pressed



69
70
71
72
73
# File 'src/modules/Bootloader.rb', line 69

def testAbort
  return false if Mode.commandline

  UI.PollInput == :abort
end

- (Boolean) Update

Update the whole configuration

Returns:

  • (Boolean)

    true on success



235
236
237
# File 'src/modules/Bootloader.rb', line 235

def Update
  Write() # write also reads the configuration and updates it
end

- (Boolean) Write

Write bootloader settings to disk

Returns:

  • (Boolean)

    true on success



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

def Write
  ReadOrProposeIfNeeded()

  mark_as_changed

  log.info "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")
  ]
  titles = [
    # progress step, text in dialog (short)
    _("Creating initrd..."),
    # progress step, text in dialog (short)
    _("Saving boot loader configuration...")
  ]
  # progress bar caption
  if Mode.normal
    # progress line
    Progress.New(
      _("Saving Boot Loader Configuration"),
      " ",
      stages.size,
      stages,
      titles,
      ""
    )
    Progress.NextStage
  else
    Progress.Title(titles[0])
  end

  params_to_save = {}
  ret = write_initrd(params_to_save)

  log.error "Error occurred while creating initrd" unless ret

  if Mode.normal
    Progress.NextStage
  else
    Progress.NextStep if !@repeating_write
    Progress.Title(titles[1])
  end

  ::Bootloader::BootloaderFactory.current.write

  true
end

- (Boolean) WriteInstallation

Write bootloader settings during installation

Returns:

  • (Boolean)

    true on success



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

def WriteInstallation
  log.info "Writing bootloader configuration during installation"

  mark_as_changed

  params_to_save = {}
  ret = write_initrd(params_to_save)

  log.error "Error occurred while creating initrd" unless ret

  write_sysconfig
  write_proposed_params(params_to_save)

  return ret if getLoaderType == "none"

  # F#300779 - Install diskless client (NFS-root)
  # kokso: bootloader will not be installed
  if BootStorage.disk_with_boot_partition == "/dev/nfs"
    log.info "Bootloader::Write() -> Boot partition is nfs type, bootloader will not be installed."
    return ret
  end

  # F#300779 -end

  # save bootloader settings
  reinit = !(Mode.update || Mode.normal)
  log.info "Reinitialize bootloader library before saving: #{reinit}"

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

  log.eror "Error before configuration files saving finished" unless ret

  # call bootloader executable
  log.info "Calling bootloader executable"
  ret &&= blWrite
  ret = handle_failed_write unless ret

  ret
end