Class: Yast::InitrdClass

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

Instance Method Summary collapse

Instance Method Details

#AdditionalParametersString

Get additional parameters for mkinitrd



465
466
467
# File 'library/system/src/modules/Initrd.rb', line 465

def AdditionalParameters
  @additional_parameters
end

#AddModule(modname, modargs) ⇒ Object

add module to ramdisk



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
242
243
244
245
246
247
# File 'library/system/src/modules/Initrd.rb', line 199

def AddModule(modname, modargs)
  log.warn "Initrd.AddModule() is deprecated, do not use (sysconfig.kernel.INITRD_MODULES " \
    "is not written anymore, see bnc#895084)"

  if Stage.initial && Builtins.size(@modules) == 0
    tmp_mods = Convert.to_string(
      SCR.Read(path(".etc.install_inf.InitrdModules"))
    )
    if !tmp_mods.nil? && tmp_mods != ""
      @modules = Builtins.splitstring(tmp_mods, " ")
    end
    @was_read = true
  elsif !(@was_read || Mode.config)
    Read()
  end
  if !Builtins.contains(ListModules(), modname) ||
      modname == "aic7xxx" &&
          !Builtins.contains(ListModules(), "aic7xxx_old") ||
      modname == "aic7xxx_old" &&
          !Builtins.contains(ListModules(), "aic7xxx")
    if !Builtins.contains(getModulesToSkip, modname)
      @changed = true
      Ops.set(@modules_to_store, modname, true)
      Ops.set(@modules_settings, modname, Misc.SplitOptions(modargs, {}))
      if !Builtins.contains(@modules, modname)
        @modules = Builtins.add(@modules, modname)
        Builtins.y2milestone(
          "Module %1 added to initrd, now contains %2",
          modname,
          ListModules()
        )
      else
        Builtins.y2milestone(
          "Module %1 from initial list added to initrd, now contains %2",
          modname,
          ListModules()
        )
      end
    else
      Builtins.y2milestone(
        "Module %1 is in list of modules not to insert to initrd",
        modname
      )
    end
  else
    Builtins.y2milestone("Module %1 already present in initrd", modname)
  end
  nil
end

#errorWithLogPopup(header, log) ⇒ Object

Display error popup with log FIXME: this is copy-paste from ../routines/popups.ycp



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'library/system/src/modules/Initrd.rb', line 304

def errorWithLogPopup(header, log)
  log = "" if log.nil?
  text = RichText(Opt(:plainText), log)
  UI.OpenDialog(
    Opt(:decorated),
    VBox(
      HSpacing(75),
      # heading
      Heading(header),
      text, # e.g. `Richtext()
      ButtonBox(
        PushButton(Id(:ok_help), Opt(:default, :okButton), Label.OKButton)
      )
    )
  )

  UI.SetFocus(Id(:ok_help))
  UI.UserInput
  UI.CloseDialog

  nil
end

#ExportHash

Export settigs to variable



251
252
253
254
255
256
# File 'library/system/src/modules/Initrd.rb', line 251

def Export
  Read() if !(@was_read || Mode.config)
  { "list" => Builtins.filter(@modules) do |m|
    Ops.get(@modules_to_store, m, false)
  end, "settings" => @modules_settings }
end

#getModulesToSkipObject

Get the list of modules which don't belong to initrd Initialize the list if was not initialized before according to the architecture



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'library/system/src/modules/Initrd.rb', line 119

def getModulesToSkip
  if @modules_to_skip.nil?
    # usb and cdrom modules dont belong to initrd,
    # they're loaded by hotplug
    @modules_to_skip = [
      "input",
      "hid",
      "keybdev",
      "mousedev",
      "cdrom",
      "ide-cd",
      "sr_mod",
      "xfs_support",
      "xfs_dmapi",
      "ide-scsi"
    ]
    # some other modules don't belong to initrd on PPC
    if Arch.ppc
      ppc_modules_to_skip = ["reiserfs", "ext3", "jbd"]
      @modules_to_skip = Convert.convert(
        Builtins.merge(@modules_to_skip, ppc_modules_to_skip),
        from: "list",
        to:   "list <string>"
      )
    end
    # currently no disk controller modules are known to fail in initrd (bnc#719696), list removed
  end
  deep_copy(@modules_to_skip)
end

#Import(settings) ⇒ Object

import settings of initrd



260
261
262
263
264
265
266
267
268
269
270
271
# File 'library/system/src/modules/Initrd.rb', line 260

def Import(settings)
  settings = deep_copy(settings)
  Read() if !Mode.config # to set modules that were read
  # and not add them to the list
  @modules = Ops.get_list(settings, "list", [])
  @modules_settings = Ops.get_map(settings, "settings", {})
  Builtins.foreach(@modules) { |m| Ops.set(@modules_to_store, m, true) }
  @was_read = true
  @changed = true

  nil
end

#ListModulesArray

List modules included in initrd



191
192
193
194
# File 'library/system/src/modules/Initrd.rb', line 191

def ListModules
  Read() if !(@was_read || Mode.config)
  Builtins.filter(@modules) { |m| Ops.get(@modules_to_store, m, false) }
end

#mainObject



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
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
# File 'library/system/src/modules/Initrd.rb', line 44

def main
  Yast.import "UI"

  Yast.import "Arch"
  Yast.import "Label"
  Yast.import "Misc"
  Yast.import "Mode"
  Yast.import "Report"
  Yast.import "Stage"
  Yast.import "Directory"

  textdomain "base"

  # module variables

  # List of modules for Initrd
  @modules = []
  # For each of modules - true if should be inserted to initrd, false
  # otherwise. Used to keep order from first-stage installation
  @modules_to_store = {}
  # List of modules that were in sysconfig file when reading settings
  @read_modules = []
  # map of settings for modules for being contained in initrd
  @modules_settings = {}
  # true if settings were changed and initrd needs to be rebuilt,
  # false otherwise
  @changed = false
  # true if settings were already read, flase otherwise
  @was_read = false
  # parametr for mkinitrd because of splash screen
  # used for choosing right size of splash
  @splash = ""
  # Additional parameters for mkinitrd
  @additional_parameters = ""
  # List of modules which should be not added/removed to/from initrd
  @modules_to_skip = nil

  # List of fallback vga modes to be used when hwinfo --framebuffer
  # doesn't return any value
  @known_modes = [
    { "color" => 8, "height" => 200, "mode" => 816, "width" => 320 },
    { "color" => 16, "height" => 200, "mode" => 782, "width" => 320 },
    { "color" => 24, "height" => 200, "mode" => 783, "width" => 320 },
    { "color" => 8, "height" => 240, "mode" => 820, "width" => 320 },
    { "color" => 16, "height" => 240, "mode" => 821, "width" => 320 },
    { "color" => 24, "height" => 240, "mode" => 822, "width" => 320 },
    { "color" => 8, "height" => 400, "mode" => 817, "width" => 320 },
    { "color" => 16, "height" => 400, "mode" => 818, "width" => 320 },
    { "color" => 24, "height" => 400, "mode" => 819, "width" => 320 },
    { "color" => 8, "height" => 400, "mode" => 768, "width" => 640 },
    { "color" => 16, "height" => 400, "mode" => 829, "width" => 640 },
    { "color" => 24, "height" => 400, "mode" => 830, "width" => 640 },
    { "color" => 8, "height" => 480, "mode" => 769, "width" => 640 },
    { "color" => 16, "height" => 480, "mode" => 785, "width" => 640 },
    { "color" => 24, "height" => 480, "mode" => 786, "width" => 640 },
    { "color" => 8, "height" => 600, "mode" => 771, "width" => 800 },
    { "color" => 16, "height" => 600, "mode" => 788, "width" => 800 },
    { "color" => 24, "height" => 600, "mode" => 789, "width" => 800 },
    { "color" => 8, "height" => 768, "mode" => 773, "width" => 1024 },
    { "color" => 16, "height" => 768, "mode" => 791, "width" => 1024 },
    { "color" => 24, "height" => 768, "mode" => 792, "width" => 1024 },
    { "color" => 8, "height" => 1024, "mode" => 775, "width" => 1280 },
    { "color" => 16, "height" => 1024, "mode" => 794, "width" => 1280 },
    { "color" => 24, "height" => 1024, "mode" => 795, "width" => 1280 },
    { "color" => 8, "height" => 1200, "mode" => 837, "width" => 1600 },
    { "color" => 16, "height" => 1200, "mode" => 838, "width" => 1600 }
  ]
end

#ReadObject

read seettings from sysconfig



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'library/system/src/modules/Initrd.rb', line 164

def Read
  Reset()
  @was_read = true
  return true if Stage.initial && !Mode.update # nothing to read

  # test for missing files - probably an error - should never occur
  if SCR.Read(path(".target.size"), "/etc/sysconfig/kernel") == -1
    Builtins.y2error("sysconfig/kernel not found")
    return false
  end

  s_modnames = Convert.to_string(
    SCR.Read(path(".sysconfig.kernel.INITRD_MODULES"))
  )
  s_modnames = "" if s_modnames.nil?
  @modules = Builtins.splitstring(s_modnames, " ")
  @modules = Builtins.filter(@modules) { |m| m != "" }
  Builtins.foreach(@modules) do |m|
    Ops.set(@modules_settings, m, {})
    Ops.set(@modules_to_store, m, true)
  end
  @read_modules = deep_copy(@modules)
  true
end

#RemoveModule(modname) ⇒ Object

remove module from list of initrd modules



275
276
277
278
279
280
281
282
283
284
# File 'library/system/src/modules/Initrd.rb', line 275

def RemoveModule(modname)
  Read() if !(@was_read || Mode.config)
  @modules = Builtins.filter(@modules) { |k| k != modname }
  @modules_settings = Builtins.filter(@modules_settings) do |k, _v|
    k != modname
  end
  @changed = true

  nil
end

#ResetObject

reset settings to empty list of modules



150
151
152
153
154
155
156
157
158
159
160
# File 'library/system/src/modules/Initrd.rb', line 150

def Reset
  Builtins.y2milestone("Reseting initrd settings")
  @was_read = false
  @changed = false
  @modules = []
  @modules_to_store = {}
  @read_modules = []
  @modules_settings = {}

  nil
end

#SetAdditionalParameters(params) ⇒ Object

Set additional parameters for mkinitrd



471
472
473
474
475
# File 'library/system/src/modules/Initrd.rb', line 471

def SetAdditionalParameters(params)
  @additional_parameters = params

  nil
end

#setSplash(vga) ⇒ Object

Set the -s parameter of mkinitrd



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
# File 'library/system/src/modules/Initrd.rb', line 436

def setSplash(vga)
  if !Arch.s390
    @changed = true
    # bnc#292013 - Grub-tool does not recreate initrd if the vga-mode changed
    if vga == "normal"
      @splash = "off"
    else
      mode = Builtins.tointeger(vga)
      all_modes = VgaModes()
      Builtins.foreach(all_modes) do |m|
        if Ops.get_integer(m, "mode", 0) == mode &&
            Ops.get_integer(m, "height", 0) != 0 &&
            Ops.get_integer(m, "width", 0) != 0
          @splash = Builtins.sformat(
            "%2x%1",
            Ops.get_integer(m, "height", 0),
            Ops.get_integer(m, "width", 0)
          )
        end
      end
    end
    Builtins.y2milestone("Setting splash resolution to %1", @splash)
  end

  nil
end

#UpdateObject

Update read settings to new version of configuration files



287
288
289
290
291
292
293
294
295
296
297
298
# File 'library/system/src/modules/Initrd.rb', line 287

def Update
  # add other required changes here
  @modules = Builtins.filter(@modules) do |m|
    !Builtins.contains(getModulesToSkip, m)
  end
  @modules_settings = Builtins.filter(@modules_settings) do |k, _v|
    !Builtins.contains(getModulesToSkip, k)
  end
  @changed = true

  nil
end

#VgaModesObject



421
422
423
424
425
426
427
428
429
430
431
432
# File 'library/system/src/modules/Initrd.rb', line 421

def VgaModes
  all_modes = Convert.convert(
    SCR.Read(path(".probe.framebuffer")),
    from: "any",
    to:   "list <map>"
  )
  if all_modes.nil? || Builtins.size(all_modes) == 0
    Builtins.y2warning("Probing VGA modes failed, using fallback list")
    all_modes = deep_copy(@known_modes)
  end
  deep_copy(all_modes)
end

#WriteObject

write settings to sysconfig, rebuild initrd images



329
330
331
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
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
# File 'library/system/src/modules/Initrd.rb', line 329

def Write
  Read() if !(@was_read || Mode.config)
  Update() if Mode.update
  Builtins.y2milestone(
    "Initrd::Write called, changed: %1, list: %2",
    @changed,
    ListModules()
  )
  # check whether it is neccessary to write initrd
  return true if !@changed && Mode.normal

  modules_written = false

  Builtins.foreach(@modules_settings) do |modname, optmap|
    next if !Ops.is_map?(optmap)
    if Ops.greater_than(Builtins.size(Convert.to_map(optmap)), 0)
      # write options to /etc/modules.conf
      p = Builtins.add(path(".modules.options"), modname)
      SCR.Write(p, Convert.to_map(optmap))
      modules_written = true
    end
  end

  SCR.Write(path(".modules"), nil) if modules_written

  # check modules that could be added during module's run (bug 26717)
  if SCR.Read(path(".target.size"), "/etc/sysconfig/kernel") != -1
    s_modnames = Convert.to_string(
      SCR.Read(path(".sysconfig.kernel.INITRD_MODULES"))
    )
    s_modnames = "" if s_modnames.nil?
    s_modules = Builtins.splitstring(s_modnames, " ")
    s_modules = Builtins.filter(s_modules) do |m|
      !Builtins.contains(@read_modules, m)
    end
    s_modules = Builtins.filter(s_modules) do |m|
      !Builtins.contains(@modules, m)
    end
    Builtins.y2milestone(
      "Modules %1 were added to initrd not using Initrd module",
      s_modules
    )
    Builtins.foreach(s_modules) { |m| AddModule(m, "") }
  end

  # save sysconfig
  SCR.Execute(
    path(".target.bash"),
    "/usr/bin/touch /etc/sysconfig/bootloader"
  )

  # FIXME: the modules are not written, remove them completely,
  # for now just log them without any change
  mods = Builtins.mergestring(ListModules(), " ")
  log.warn "Ignoring configured kernel modules: #{mods}" unless mods.empty?

  # recreate initrd
  param = ""
  if @splash != "" && !@splash.nil? &&
      Ops.less_than(
        0,
        Convert.to_integer(
          SCR.Read(
            path(".target.size"),
            "/lib/mkinitrd/scripts/setup-splash.sh"
          )
        )
      )
    param = Builtins.sformat("-s %1", @splash)
  end
  if SCR.Execute(
    path(".target.bash"),
    Builtins.sformat(
      "/sbin/mkinitrd %1 %2 >> %3 2>&1",
      param,
      @additional_parameters,
      Ops.add(Directory.logdir, "/y2logmkinitrd")
    )
  ) != 0
    log = Convert.to_string(
      SCR.Read(
        path(".target.string"),
        Ops.add(Directory.logdir, "/y2logmkinitrd")
      )
    )
    # error report
    errorWithLogPopup(_("An error occurred during initrd creation."), log)
  end
  @changed = false
  true
end