Class: Yast::KernelClass

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

Constant Summary

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


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

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



588
589
590
591
592
# File 'library/system/src/modules/Kernel.rb', line 588

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



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'library/system/src/modules/Kernel.rb', line 476

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



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'library/system/src/modules/Kernel.rb', line 531

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



521
522
523
524
525
526
527
# File 'library/system/src/modules/Kernel.rb', line 521

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

#ExtractCmdlineParameters(line) ⇒ void

This method returns an undefined value.

Filters out yast2 specific boot parameters and sets Parameters to the important cmdline parts.

Parameters:

  • cmdline

    string



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

def ExtractCmdlineParameters(line)
  # discard \n
  line = Builtins.deletechars(line, "\n")

  # list of parameters to be discarded (yast internals)

  discardlist = []

  cmdlist = []

  parse_index = 0
  in_quotes = false
  after_backslash = false
  current_param = ""
  while Ops.less_than(parse_index, Builtins.size(line))
    current_char = Builtins.substring(line, parse_index, 1)
    in_quotes = !in_quotes if current_char == "\"" && !after_backslash
    if current_char == " " && !in_quotes
      cmdlist = Builtins.add(cmdlist, current_param)
      current_param = ""
    else
      current_param = Ops.add(current_param, current_char)
    end
    after_backslash = current_char == "\\"
    parse_index = Ops.add(parse_index, 1)
  end
  cmdlist = Builtins.add(cmdlist, current_param)

  #	this is wrong because of eg. >>o="p a r a m"<<, see bugzilla 26147
  #	list cmdlist = splitstring (line, " ");

  # some systems (pseries) can autodetect the serial console
  if Builtins.contains(cmdlist, "AUTOCONSOLE")
    discardlist = Builtins.add(discardlist, "console")
    discardlist = Builtins.add(discardlist, "AUTOCONSOLE")
  end

  # add special key filtering for s390
  # bnc#462276 Extraneous parameters in /etc/zipl.conf from the installer
  if Arch.s390
    discardlist = Builtins.add(discardlist, "User")
    discardlist = Builtins.add(discardlist, "init")
    discardlist = Builtins.add(discardlist, "ramdisk_size")
  end

  # get rid of live-installer-specific parameters
  if Mode.live_installation
    discardlist.push("initrd", "ramdisk_size", "ramdisk_blocksize", "liveinstall", "splash", "quiet", "lang")
  end

  # backdoor to re-enable update on UL/SLES
  if Builtins.contains(cmdlist, "suse_update")
    discardlist = Builtins.add(discardlist, "suse_update")
    @suse_update = true
  end

  Builtins.foreach(cmdlist) do |parameter|
    # split "key=value" to ["key", "value"]
    param_value_list = Builtins.splitstring(parameter, "=")
    key = Ops.get(param_value_list, 0, "")
    value = Ops.get(param_value_list, 1, "")
    # now only collect keys not in discardlist
    if Ops.greater_than(Builtins.size(param_value_list), 0)
      if !Builtins.contains(discardlist, key)
        if Ops.get(param_value_list, 0, "") == "vga"
          if Builtins.regexpmatch(value, "^(0x)?[0-9a-fA-F]+$") ||
              Builtins.contains(["normal", "ext", "ask"], value)
            @vgaType = value
          else
            Builtins.y2warning("Incorrect VGA kernel parameter: %1", value)
          end
        else
          AddCmdLine(key, value)
        end
      end
    end
  end

  nil
end

#GetBinaryString

Het the name of kernel binary under /boot

Returns:

  • (String)

    the name of the kernel binary



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

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

#GetCmdLineString

Get the kernel command line

Returns:

  • (String)

    the command line



299
300
301
302
# File 'library/system/src/modules/Kernel.rb', line 299

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

#GetFinalKernelObject



510
511
512
513
# File 'library/system/src/modules/Kernel.rb', line 510

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

#GetInformAboutKernelChangeObject

Get inform_about_kernel_change.



651
652
653
# File 'library/system/src/modules/Kernel.rb', line 651

def GetInformAboutKernelChange
  @inform_about_kernel_change
end

#GetPackagesObject

Get the list of kernel packages

Returns:

  • a list of kernel packages



469
470
471
472
# File 'library/system/src/modules/Kernel.rb', line 469

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

#GetSuSEUpdateBoolean

Check if suse_update kernel command line argument was passed

Returns:

  • (Boolean)

    true if it was



292
293
294
295
# File 'library/system/src/modules/Kernel.rb', line 292

def GetSuSEUpdate
  ParseInstallationKernelCmdline() if !@cmdline_parsed
  @suse_update
end

#GetVgaTypeString

Get the vga= kernel parameter

Returns:

  • (String)

    the vga= kernel parameter



276
277
278
279
# File 'library/system/src/modules/Kernel.rb', line 276

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

#HidePasswords(in_) ⇒ String

Hide passwords in command line option string

Parameters:

  • in (String)

    input string

Returns:



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

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



656
657
658
659
660
661
662
# File 'library/system/src/modules/Kernel.rb', line 656

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



314
315
316
317
318
319
# File 'library/system/src/modules/Kernel.rb', line 314

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



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

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



582
583
584
# File 'library/system/src/modules/Kernel.rb', line 582

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



571
572
573
574
575
# File 'library/system/src/modules/Kernel.rb', line 571

def modules_to_load
  read_modules_to_load if @modules_to_load.nil?

  @modules_to_load
end

#ParseInstallationKernelCmdlineObject



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'library/system/src/modules/Kernel.rb', line 250

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.



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
414
415
416
417
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
# File 'library/system/src/modules/Kernel.rb', line 328

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"), "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.ia64
    @kernel_packages = ["kernel-default"]
  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



596
597
598
599
600
601
602
603
604
605
# File 'library/system/src/modules/Kernel.rb', line 596

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



562
563
564
# File 'library/system/src/modules/Kernel.rb', line 562

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



610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
# File 'library/system/src/modules/Kernel.rb', line 610

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

#SetCmdLine(new_cmd_line) ⇒ Object

Set the kernel command line FIXME: is heer because of bootloader module, should be removed



306
307
308
309
310
311
# File 'library/system/src/modules/Kernel.rb', line 306

def SetCmdLine(new_cmd_line)
  ParseInstallationKernelCmdline() if !@cmdline_parsed
  @cmdLine = new_cmd_line

  nil
end

#SetInformAboutKernelChange(b) ⇒ Object

Set inform_about_kernel_change.



644
645
646
647
648
# File 'library/system/src/modules/Kernel.rb', line 644

def SetInformAboutKernelChange(b)
  @inform_about_kernel_change = b

  nil
end

#SetPackages(custom_kernels) ⇒ Object

Set a custom kernel.

Parameters:

  • custom_kernels

    a list of kernel packages



449
450
451
452
453
454
455
456
# File 'library/system/src/modules/Kernel.rb', line 449

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

#SetVgaType(new_vga) ⇒ Object

Set the vga= kernel argument FIXME: is heer because of bootloader module, should be removed



283
284
285
286
287
288
# File 'library/system/src/modules/Kernel.rb', line 283

def SetVgaType(new_vga)
  ParseInstallationKernelCmdline() if !@cmdline_parsed
  @vgaType = new_vga

  nil
end