Class: Yast::InitrdClass

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

Instance Method Summary (collapse)

Instance Method Details

- (String) AdditionalParameters

Get additional parameters for mkinitrd

Returns:

  • (String)

    additional mkinitrd parameters



459
460
461
# File '../../src/modules/Initrd.rb', line 459

def AdditionalParameters
  @additional_parameters
end

- (Object) AddModule(modname, modargs)

add module to ramdisk

Parameters:

  • modname (String)

    name of module

  • modargs (String)

    arguments to be passes to module



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
242
# File '../../src/modules/Initrd.rb', line 197

def AddModule(modname, modargs)
  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

- (Object) errorWithLogPopup(header, log)

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

Parameters:

  • header (String)

    string error header

  • log (String)

    string logfile contents



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File '../../src/modules/Initrd.rb', line 299

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))
  r = UI.UserInput
  UI.CloseDialog

  nil
end

- (Hash) Export

Export settigs to variable

Returns:

  • (Hash)

    of initrd settings



246
247
248
249
250
251
# File '../../src/modules/Initrd.rb', line 246

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

- (Object) getModulesToSkip

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

Returns:

  • a list of modules



117
118
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
# File '../../src/modules/Initrd.rb', line 117

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

- (Object) Import(settings)

import settings of initrd

Parameters:

  • settings (Hash)

    map of initrd settings



255
256
257
258
259
260
261
262
263
264
265
266
# File '../../src/modules/Initrd.rb', line 255

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

- (Array) ListModules

List modules included in initrd

Returns:

  • (Array)

    of strings with modulenames



189
190
191
192
# File '../../src/modules/Initrd.rb', line 189

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

- (Object) main



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

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

- (Object) Read

read seettings from sysconfig

Returns:

  • true on success



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

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

- (Object) RemoveModule(modname)

remove module from list of initrd modules

Parameters:

  • modname (String)

    string name of module to remove



270
271
272
273
274
275
276
277
278
279
# File '../../src/modules/Initrd.rb', line 270

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

- (Object) Reset

reset settings to empty list of modules



148
149
150
151
152
153
154
155
156
157
158
# File '../../src/modules/Initrd.rb', line 148

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

  nil
end

- (Object) SetAdditionalParameters(params)

Set additional parameters for mkinitrd

Parameters:

  • params (String)

    string additional mkinitrd parameters



465
466
467
468
469
# File '../../src/modules/Initrd.rb', line 465

def SetAdditionalParameters(params)
  @additional_parameters = params

  nil
end

- (Object) setSplash(vga)

Set the -s parameter of mkinitrd

Parameters:

  • vga (String)

    string the vga kernel parameter



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

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

- (Object) Update

Update read settings to new version of configuration files



282
283
284
285
286
287
288
289
290
291
292
293
# File '../../src/modules/Initrd.rb', line 282

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

- (Object) VgaModes



415
416
417
418
419
420
421
422
423
424
425
426
# File '../../src/modules/Initrd.rb', line 415

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

- (Object) Write

write settings to sysconfig, rebuild initrd images

Returns:

  • true on success



325
326
327
328
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
# File '../../src/modules/Initrd.rb', line 325

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"
  )
  mods = Builtins.mergestring(ListModules(), " ")
  Builtins.y2milestone("Writing modules %1", mods)
  SCR.Write(path(".sysconfig.kernel.INITRD_MODULES"), mods)
  SCR.Write(path(".sysconfig.kernel"), nil)
  # 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