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

#mainObject



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

def main
  Yast.import "UI"

  Yast.import "Arch"
  Yast.import "Label"
  Yast.import "Misc"
  Yast.import "Mode"
  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
  # 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

Returns:

  • true on success



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'library/system/src/modules/Initrd.rb', line 110

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

#VgaModesObject



214
215
216
217
218
219
220
221
222
223
224
225
# File 'library/system/src/modules/Initrd.rb', line 214

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

Returns:

  • true on success



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

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?

  if SCR.Execute(
    path(".target.bash"),
    Builtins.sformat(
      "/usr/bin/dracut --force --regenerate-all >> %1 2>&1",
      File.join(Directory.logdir, "y2logmkinitrd").shellescape
    )
  ) != 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