Class: Yast::KernelClass

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

Constant Summary collapse

MODULES_CONF_FILE =

default configuration file for Kernel modules loaded on boot

"yast.conf".freeze
MODULES_DIR =

directory where configuration for Kernel modules loaded on boot is stored

"/etc/modules-load.d/".freeze
MODULES_SCR =

SCR path for reading/writing Kernel modules

Path.new(".kernel_modules_to_load")
PAE_LIMIT =

specifies limit of memory which can be addressed without pae on 32-bit system

3_221_225_472

Instance Method Summary collapse

Instance Method Details

#AddCmdLine(name, arg) ⇒ Object

AddCmdLine () add "name=args" to kernel boot parameters add just "name" if args = ""

Parameters:

  • name (String)

    of parameter

  • string

    args of parameter

See Also:

  • #cmdLine

154
155
156
157
158
159
160
# File 'library/system/src/modules/Kernel.rb', line 154

def AddCmdLine(name, arg)
  ParseInstallationKernelCmdline() if !@cmdline_parsed
  @cmdLine = Ops.add(Ops.add(@cmdLine, " "), name)
  @cmdLine = Ops.add(Ops.add(@cmdLine, "="), arg) if arg != ""
  Builtins.y2milestone("cmdLine '%1'", HidePasswords(@cmdLine))
  nil
end

#AddModuleToLoad(name) ⇒ Object

Add a kernel module to the list of modules to load after boot

Parameters:

  • string

    module name


479
480
481
482
483
# File 'library/system/src/modules/Kernel.rb', line 479

def AddModuleToLoad(name)
  Builtins.y2milestone("Adding module to be loaded at boot: %1", name)

  @modules_to_load[MODULES_CONF_FILE] << name unless module_to_be_loaded?(name)
end

#ComputePackageString

Compute kernel package

Returns:

  • (String)

    selected kernel


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

def ComputePackage
  packages = GetPackages()
  the_kernel = Ops.get(packages, 0, "")
  Builtins.y2milestone("Selecting '%1' as kernel package", the_kernel)

  # Check for provided kernel packages in installed system
  if Mode.normal || Mode.repair
    while the_kernel != "" && !Pkg.PkgInstalled(the_kernel)
      the_kernel = Ops.get(@fallbacks, the_kernel, "")
      Builtins.y2milestone("Not provided, falling back to '%1'", the_kernel)
    end
  else
    while the_kernel != "" && !Pkg.PkgAvailable(the_kernel)
      the_kernel = Ops.get(@fallbacks, the_kernel, "")
      Builtins.y2milestone(
        "Not available, falling back to '%1'",
        the_kernel
      )
    end
  end

  if the_kernel != ""
    @final_kernel = the_kernel
  else
    Builtins.y2warning(
      "%1 not available, using kernel-default",
      @kernel_packages
    )

    @final_kernel = "kernel-default"
  end
  @final_kernel
end

#ComputePackagesArray

Compute kernel packages

Returns:

  • (Array)

    of selected kernel packages


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

def ComputePackages
  kernel = ComputePackage()

  ret = ComputePackagesForBase(kernel, true)

  if Ops.greater_than(Builtins.size(@kernel_packages), 1)
    # get the extra packages
    extra_pkgs = Builtins.remove(@kernel_packages, 0)

    # add available extra packages
    Builtins.foreach(extra_pkgs) do |pkg|
      if Pkg.IsAvailable(pkg)
        ret = Builtins.add(ret, pkg)
        Builtins.y2milestone("Added extra kernel package: %1", pkg)
      else
        Builtins.y2warning(
          "Extra kernel package '%1' is not available",
          pkg
        )
      end
    end
  end

  Builtins.y2milestone("Computed kernel packages: %1", ret)

  deep_copy(ret)
end

#ComputePackagesForBase(base, _check_avail) ⇒ Object

Compute kernel package for the specified base kernel package

Parameters:

  • base (String)

    string the base kernel package name (eg. kernel-default)

  • check_avail (Boolean)

    boolean if true, additional packages are checked for for being available on the medias before adding to the list

Returns:

  • a list of all kernel packages (including the base package) that are to be installed together with the base package


412
413
414
415
416
417
418
# File 'library/system/src/modules/Kernel.rb', line 412

def ComputePackagesForBase(base, _check_avail)
  # Note: kernel-*-nongpl packages have been dropped, use base only
  ret = [base]

  Builtins.y2milestone("Packages for base %1: %2", base, ret)
  deep_copy(ret)
end

#GetBinaryString

Het the name of kernel binary under /boot

Returns:

  • (String)

    the name of the kernel binary


353
354
355
356
# File 'library/system/src/modules/Kernel.rb', line 353

def GetBinary
  ProbeKernel() if !@kernel_probed
  @binary
end

#GetCmdLineString

Get the kernel command line

Returns:

  • (String)

    the command line


201
202
203
204
# File 'library/system/src/modules/Kernel.rb', line 201

def GetCmdLine
  ParseInstallationKernelCmdline() if !@cmdline_parsed
  @cmdLine
end

#GetFinalKernelObject


401
402
403
404
# File 'library/system/src/modules/Kernel.rb', line 401

def GetFinalKernel
  ComputePackage() if @final_kernel == ""
  @final_kernel
end

#GetInformAboutKernelChangeObject

Get inform_about_kernel_change.


542
543
544
# File 'library/system/src/modules/Kernel.rb', line 542

def GetInformAboutKernelChange
  @inform_about_kernel_change
end

#GetPackagesObject

Get the list of kernel packages

Returns:

  • a list of kernel packages


360
361
362
363
# File 'library/system/src/modules/Kernel.rb', line 360

def GetPackages
  ProbeKernel() if !@kernel_probed
  deep_copy(@kernel_packages)
end

#GetVgaTypeString

Get the vga= kernel parameter

Returns:

  • (String)

    the vga= kernel parameter


194
195
196
197
# File 'library/system/src/modules/Kernel.rb', line 194

def GetVgaType
  ParseInstallationKernelCmdline() if !@cmdline_parsed
  @vgaType
end

#HidePasswords(in_) ⇒ String

Hide passwords in command line option string

Parameters:

  • in (String)

    input string

Returns:


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 'library/system/src/modules/Kernel.rb', line 119

def HidePasswords(in_)
  ret = ""

  if !in_.nil?
    parts = Builtins.splitstring(in_, " ")

    first = true
    Builtins.foreach(parts) do |p|
      cmdopt = p
      if Builtins.regexpmatch(p, "^INST_PASSWORD=")
        cmdopt = "INST_PASSWORD=******"
      elsif Builtins.regexpmatch(p, "^FTPPASSWORD=")
        cmdopt = "FTPPASSWORD=********"
      end
      if first
        first = false
      else
        ret = Ops.add(ret, " ")
      end
      ret = Ops.add(ret, cmdopt)
    end
  else
    ret = nil
  end

  ret
end

#InformAboutKernelChangeObject

Display popup about new kernel that was installed


547
548
549
550
551
552
553
# File 'library/system/src/modules/Kernel.rb', line 547

def InformAboutKernelChange
  if GetInformAboutKernelChange()
    # inform the user that he/she has to reboot to activate new kernel
    Popup.Message(_("Reboot your system\nto activate the new kernel.\n"))
  end
  @inform_about_kernel_change
end

#IsGraphicalDesktopObject

Simple check any graphical desktop was selected


207
208
209
210
211
212
# File 'library/system/src/modules/Kernel.rb', line 207

def IsGraphicalDesktop
  # Get patterns set for installation during desktop selection
  # (see DefaultDesktop::packages_proposal_ID_patterns for the first argument)
  pt = PackagesProposal.GetResolvables("DefaultDesktopPatterns", :pattern)
  Builtins.contains(pt, "x11")
end

#mainObject


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/Kernel.rb', line 50

def main
  Yast.import "Pkg"

  Yast.import "Arch"
  Yast.import "Mode"
  Yast.import "Linuxrc"
  Yast.import "PackagesProposal"
  Yast.import "Popup"
  Yast.import "Stage"
  Yast.import "FileUtils"

  textdomain "base"

  # kernel packages and binary

  @kernel_probed = false

  # the name of the kernel binary below '/boot'.
  @binary = "vmlinuz"

  # a list kernels to be installed.
  @kernel_packages = []

  # the final kernel to be installed after verification and
  # availability checking
  @final_kernel = ""

  # kernel commandline

  @cmdline_parsed = false

  # string the kernel vga paramter
  @vgaType = ""

  # if "suse_update" given in cmdline
  @suse_update = false

  # string the kernel command line
  # Don't write it directly, @see: AddCmdLine()
  @cmdLine = ""

  # modules loaded on boot

  # Kernel modules configured to be loaded on boot
  @modules_to_load = nil
  @modules_to_load_old = nil

  # kernel was reinstalled

  #  A flag to indicate if a popup informing about the kernel change should be displayed
  @inform_about_kernel_change = false

  # other variables

  # fallback map for kernel
  @fallbacks = {
    "kernel-pae"       => "kernel-default",
    "kernel-desktop"   => "kernel-default",
    # fallback for PPC (#302246)
    "kernel-iseries64" => "kernel-ppc64"
  }
end

#module_to_be_loaded?(kernel_module) ⇒ Boolean

Returns whether the given kernel module is included in list of modules to be loaded on boot

Parameters:

Returns:

  • (Boolean)

    whether the given module is in the list


473
474
475
# File 'library/system/src/modules/Kernel.rb', line 473

def module_to_be_loaded?(kernel_module)
  modules_to_load.values.any? { |m| m.include?(kernel_module) }
end

#modules_to_loadHash

Returns hash of kernel modules to be loaded on boot

  • key is the config file
  • value is list of modules in that particular file

Returns:

  • (Hash)

    of modules


462
463
464
465
466
# File 'library/system/src/modules/Kernel.rb', line 462

def modules_to_load
  read_modules_to_load if @modules_to_load.nil?

  @modules_to_load
end

#ParseInstallationKernelCmdlinevoid

This method returns an undefined value.

Parse the installation-time kernel command line

  • the vga parameter is separated, see #GetVgaType
  • some specific parameters are ignored
  • the rest is passed on to @cmdLine for which #GetCmdLine is a reader

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

def ParseInstallationKernelCmdline
  @cmdline_parsed = true
  return if !(Stage.initial || Stage.cont)

  # live installation does not create /etc/install.inf (bsc#793065)
  tmp = if Mode.live_installation
    # not using dedicated agent in order to use the same parser for cmdline
    # independently on whether it comes from /proc/cmdline or /etc/install.inf
    Convert.to_string(SCR.Read(path(".target.string"), "/proc/cmdline"))
  else
    Convert.to_string(SCR.Read(path(".etc.install_inf.Cmdline")))
  end

  Builtins.y2milestone(
    "cmdline from install.inf is: %1",
    HidePasswords(tmp)
  )
  if !tmp.nil?
    # extract extra boot parameters given in installation
    ExtractCmdlineParameters(tmp)
  end

  nil
end

#ProbeKernelvoid

This method returns an undefined value.

select kernel depending on architecture and system type.


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
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
327
328
329
330
331
332
333
334
335
336
# File 'library/system/src/modules/Kernel.rb', line 221

def ProbeKernel
  kernel_desktop_exists = (Mode.normal || Mode.repair) &&
    Pkg.PkgInstalled("kernel-desktop") ||
    Pkg.PkgAvailable("kernel-desktop")
  Builtins.y2milestone(
    "Desktop kernel available: %1",
    kernel_desktop_exists
  )

  @kernel_packages = ["kernel-default"]

  # add Xen paravirtualized drivers to a full virtualized host
  xen = Convert.to_boolean(SCR.Read(path(".probe.is_xen")))
  if xen.nil?
    Builtins.y2warning("XEN detection failed, assuming XEN is NOT running")
    xen = false
  end

  Builtins.y2milestone("Detected XEN: %1", xen)

  if Arch.is_uml
    Builtins.y2milestone("ProbeKernel: UML")
    @kernel_packages = ["kernel-um"]
  elsif Arch.is_xen
    # kernel-xen contains PAE kernel (since oS11.0)
    @kernel_packages = ["kernel-xen"]
  elsif Arch.i386
    # get flags from WFM /proc/cpuinfo (for pae and tsc tests below)

    cpuinfo_flags = Convert.to_string(
      SCR.Read(path(".proc.cpuinfo.value.\"0\".\"flags\""))
    ) # check only first processor
    cpuflags = []

    # bugzilla #303842
    if cpuinfo_flags
      cpuflags = cpuinfo_flags.empty? ? [] : cpuinfo_flags.split(" ")
    else
      Builtins.y2error("Cannot read cpuflags")
      Builtins.y2milestone(
        "Mounted: %1",
        SCR.Execute(path(".target.bash_output"), "/usr/bin/mount -l")
      )
    end

    # check for "roughly" >= 4GB memory (see bug #40729)
    memories = Convert.to_list(SCR.Read(path(".probe.memory")))
    memsize = Ops.get_integer(
      memories,
      [0, "resource", "phys_mem", 0, "range"],
      0
    )
    Builtins.y2milestone("Physical memory %1", memsize)

    # for memory > 4GB and PAE support we install kernel-pae,
    # PAE kernel is needed if NX flag exists as well (bnc#467328)
    if (Ops.greater_or_equal(memsize, PAE_LIMIT) ||
        Builtins.contains(cpuflags, "nx")) &&
        Builtins.contains(cpuflags, "pae")
      Builtins.y2milestone("Kernel switch: PAE detected")
      if kernel_desktop_exists && IsGraphicalDesktop()
        @kernel_packages = ["kernel-desktop"]

        # add PV drivers
        if xen
          Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-desktop")
          @kernel_packages = Builtins.add(
            @kernel_packages,
            "xen-kmp-desktop"
          )
        end
      else
        @kernel_packages = ["kernel-pae"]

        # add PV drivers
        if xen
          Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-pae")
          @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-pae")
        end
      end
    # add PV drivers
    elsif xen
      Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-default")
      @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-default")
    end
  elsif Arch.x86_64
    if kernel_desktop_exists && IsGraphicalDesktop()
      @kernel_packages = ["kernel-desktop"]
      if xen
        Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-desktop")
        @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-desktop")
      end
    elsif xen
      Builtins.y2milestone("Adding Xen PV drivers: xen-kmp-default")
      @kernel_packages = Builtins.add(@kernel_packages, "xen-kmp-default")
    end
  elsif Arch.ppc
    @binary = "vmlinux"

    @kernel_packages = if Arch.board_iseries
      ["kernel-iseries64"]
    elsif Arch.ppc32
      ["kernel-default"]
    else
      ["kernel-ppc64"]
    end
  elsif Arch.s390
    @kernel_packages = ["kernel-default"]
    @binary = "image"
  end

  @kernel_probed = true
  Builtins.y2milestone("ProbeKernel determined: %1", @kernel_packages)

  nil
end

#RemoveModuleToLoad(name) ⇒ Object

Remove a kernel module from the list of modules to load after boot

Parameters:

  • name (String)

    string the name of the module


487
488
489
490
491
492
493
494
495
496
# File 'library/system/src/modules/Kernel.rb', line 487

def RemoveModuleToLoad(name)
  modules_to_load

  return true unless module_to_be_loaded?(name)

  Builtins.y2milestone("Removing module to be loaded at boot: %1", name)
  @modules_to_load.each do |_key, val|
    val.delete(name)
  end
end

#reset_modules_to_loadObject

Resets the internal cache


453
454
455
# File 'library/system/src/modules/Kernel.rb', line 453

def reset_modules_to_load
  @modules_to_load = nil
end

#SaveModulesToLoadBoolean

SaveModuleToLoad () save the sysconfig variable to /etc/modules-load.d/*.conf configuration files

Returns:

  • (Boolean)

    true on success


501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'library/system/src/modules/Kernel.rb', line 501

def SaveModulesToLoad
  modules_to_load

  unless FileUtils.Exists(MODULES_DIR)
    log.warn "Directory #{MODULES_DIR} does not exist, creating"

    unless SCR::Execute(path(".target.mkdir"), MODULES_DIR)
      log.error "Cannot create directory #{MODULES_DIR}"
      return false
    end
  end

  success = true

  @modules_to_load.each do |file, modules|
    # The content hasn't changed
    next if modules.sort == @modules_to_load_old[file].sort

    if !register_modules_agent(file)
      Builtins.y2error("Cannot register new SCR agent for #{file_path} file")
      success = false
      next
    end

    SCR::Write(MODULES_SCR, modules)
    SCR.UnregisterAgent(MODULES_SCR)
  end

  success
end

#SetInformAboutKernelChange(value) ⇒ Object

Set inform_about_kernel_change.


535
536
537
538
539
# File 'library/system/src/modules/Kernel.rb', line 535

def SetInformAboutKernelChange(value)
  @inform_about_kernel_change = value

  nil
end

#SetPackages(custom_kernels) ⇒ Object

Set a custom kernel.

Parameters:

  • custom_kernels

    a list of kernel packages


340
341
342
343
344
345
346
347
# File 'library/system/src/modules/Kernel.rb', line 340

def SetPackages(custom_kernels)
  custom_kernels = deep_copy(custom_kernels)
  # probe to avoid later probing
  ProbeKernel() if !@kernel_probed
  @kernel_packages = deep_copy(custom_kernels)

  nil
end