Class: Yast::BootLILOClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) BootLILO

Constructor



372
373
374
375
376
377
378
379
380
381
382
383
384
# File '../../src/modules/BootLILO.rb', line 372

def BootLILO
  Ops.set(
    BootCommon.bootloader_attribs,
    "lilo",
    {
      "required_packages" => ["lilo"],
      "loader_name"       => "LILO",
      "initializer"       => fun_ref(method(:Initializer), "void ()")
    }
  )

  nil
end

- (Object) CreateGlobals

Propose global options of bootloader modifies internal structures



115
116
117
118
119
120
121
122
123
124
# File '../../src/modules/BootLILO.rb', line 115

def CreateGlobals
  BootCommon.globals = {
    "default" => Ops.get_string(BootCommon.sections, [0, "name"], ""),
    "timeout" => "8",
    "gfxmenu" => "/boot/message",
    "prompt"  => "1"
  }

  nil
end

- (Object) CreateSections

Propose sections to bootloader menu modifies internal sreuctures



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 '../../src/modules/BootLILO.rb', line 74

def CreateSections
  out = [BootCommon.CreateLinuxSection("linux")]
  others = Storage.GetForeignPrimary
  if others != nil && Ops.greater_than(Builtins.size(others), 0)
    Builtins.foreach(others) do |o|
      parts = Builtins.splitstring(o, " ")
      while Ops.get(parts, 0, " ") == ""
        parts = Builtins.remove(parts, 0)
      end
      dev = Ops.get(parts, 0, "")
      parts = Builtins.remove(parts, 0)
      label = Builtins.mergestring(parts, " ")
      # don't add rewritten location (#19990)
      if dev != "" && label != "" && dev != BootCommon.loader_device &&
          (BootCommon.AddFirmwareToBootloader(BootCommon.mbrDisk) ||
            label != "Vendor diagnostics")
        m = {
          "name"          => BootCommon.translateSectionTitle(
            removeBlanks(label)
          ),
          "original_name" => label,
          "type"          => "chainloader",
          "chainloader"   => dev,
          "__auto"        => true,
          "__changed"     => true,
          "__devs"        => [dev]
        }
        out = Builtins.add(out, m)
      end
    end
  end
  out = Builtins.add(out, BootCommon.CreateLinuxSection("failsafe"))
  out = Builtins.add(out, BootCommon.CreateLinuxSection("memtest86"))
  out = Builtins.filter(out) { |s| s != {} && s != nil }
  BootCommon.sections = deep_copy(out)

  nil
end

- (Object) Dialogs



299
300
301
# File '../../src/modules/BootLILO.rb', line 299

def Dialogs
  {}
end

- (Boolean) FlagOnetimeBoot(section)

Set section to boot on next reboot

Parameters:

  • section (String)

    string section to boot

Returns:

  • (Boolean)

    true on success



306
307
308
309
310
311
312
313
314
315
# File '../../src/modules/BootLILO.rb', line 306

def FlagOnetimeBoot(section)
  result = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Builtins.sformat("/sbin/lilo -R \"%1\"", section)
    )
  )
  Builtins.y2milestone("lilo returned %1", result)
  Ops.get_integer(result, "exit", -1) == 0
end

- (String) getDeviceOfRaid(device)

If device is part of RAID (md), then return first of its members otherwise return the same as argument

Parameters:

  • device (String)

    string device of the RAID

Returns:

  • (String)

    first member of the RAID



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

def getDeviceOfRaid(device)
  # get list of all partitions (not marked to be deleted)
  tm = Storage.GetTargetMap
  partitions = []

  Builtins.foreach(tm) do |dev, disk|
    if Storage.IsRealDisk(disk)
      l = Builtins.filter(Ops.get_list(disk, "partitions", [])) do |p|
        Ops.get_boolean(p, "delete", false) == false
      end
      partitions = Convert.convert(
        Builtins.merge(partitions, l),
        :from => "list",
        :to   => "list <map>"
      )
    end
  end

  # filter partitions to relevant list according to raid name
  md_list = Builtins.filter(partitions) do |e|
    Ops.get_string(e, "used_by_device", "") == device
  end
  # get the devices
  dev_list = Builtins.maplist(md_list) do |e|
    Ops.get_string(e, "device", "")
  end
  dev_list = Builtins.filter(dev_list) { |d| d != "" }
  if Ops.greater_than(Builtins.size(dev_list), 0)
    dev_list = Builtins.sort(dev_list)
    return Ops.get(dev_list, 0, "")
  end
  device
end

- (Object) GetFunctions

Return map of provided functions

Returns:

  • a map of functions (eg. $[“write”:BootLILO::Write])



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

def GetFunctions
  {
    "dialogs"         => fun_ref(
      method(:Dialogs),
      "map <string, symbol ()> ()"
    ),
    "read"            => fun_ref(
      method(:Read),
      "boolean (boolean, boolean)"
    ),
    "propose"         => fun_ref(method(:Propose), "void ()"),
    "save"            => fun_ref(
      method(:Save),
      "boolean (boolean, boolean, boolean)"
    ),
    "summary"         => fun_ref(
      BootCommon.method(:i386Summary),
      "list <string> ()"
    ),
    "update"          => fun_ref(method(:Update), "void ()"),
    "write"           => fun_ref(method(:Write), "boolean ()"),
    "flagonetimeboot" => fun_ref(
      method(:FlagOnetimeBoot),
      "boolean (string)"
    ),
    "widgets"         => {}, # is not supported now
    "section_types"   => fun_ref(
      method(:lilo_section_types),
      "list <string> ()"
    )
  }
end

- (Object) Initializer

Initializer of LILO bootloader



358
359
360
361
362
363
364
365
366
367
368
369
# File '../../src/modules/BootLILO.rb', line 358

def Initializer
  Builtins.y2milestone("Called LILO initializer")
  BootCommon.current_bootloader_attribs = {
    "propose"            => true,
    "read"               => true,
    "scratch"            => true,
    "restore_mbr"        => true,
    "bootloader_on_disk" => true
  }

  nil
end

- (Object) lilo_section_types



318
319
320
# File '../../src/modules/BootLILO.rb', line 318

def lilo_section_types
  ["image", "other"]
end

- (Object) main



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File '../../src/modules/BootLILO.rb', line 24

def main
  Yast.import "UI"

  textdomain "bootloader"

  Yast.import "Arch"
  Yast.import "BootCommon"
  Yast.import "BootStorage"
  Yast.import "Kernel"
  Yast.import "Mode"
  Yast.import "Pkg"
  Yast.import "String"
  Yast.import "Storage"
  Yast.import "Stage"


  Yast.include self, "bootloader/routines/popups.rb"
  BootLILO()
end

- (Object) Propose

Propose bootloader settings



129
130
131
132
133
134
135
136
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
# File '../../src/modules/BootLILO.rb', line 129

def Propose
  Builtins.y2debug(
    "Started propose: Glob: %1, Sec: %2",
    BootCommon.globals,
    BootCommon.sections
  )
  BootCommon.i386LocationProposal

  if BootCommon.sections == nil || Builtins.size(BootCommon.sections) == 0
    CreateSections()
    BootCommon.kernelCmdLine = Kernel.GetCmdLine
  else
    if Mode.autoinst
      # TODO whatever will be needed
      Builtins.y2debug("nothing to to in AI mode if sections exist")
    else
      BootCommon.FixSections(fun_ref(method(:CreateSections), "void ()"))
    end
  end
  if BootCommon.globals == nil || Builtins.size(BootCommon.globals) == 0
    CreateGlobals()
  else
    if Mode.autoinst
      # TODO whatever will be needed
      Builtins.y2debug("nothing to to in AI mode if globals are defined")
    else
      BootCommon.FixGlobals
    end
  end

  Builtins.y2milestone("Proposed sections: %1", BootCommon.sections)
  Builtins.y2milestone("Proposed globals: %1", BootCommon.globals)

  nil
end

- (Boolean) Read(reread, avoid_reading_device_map)

Read settings from disk internal data

Parameters:

  • reread (Boolean)

    boolean true to force reread settings from system

  • avoid_reading_device_map (Boolean)

    do not read new device map from file, use

Returns:

  • (Boolean)

    true on success



170
171
172
173
174
175
176
177
# File '../../src/modules/BootLILO.rb', line 170

def Read(reread, avoid_reading_device_map)
  BootCommon.InitializeLibrary(reread, "lilo")
  BootCommon.ReadFiles(avoid_reading_device_map) if reread
  BootCommon.DetectDisks
  ret = BootCommon.Read(false, avoid_reading_device_map)
  BootCommon.loader_device = Ops.get(BootCommon.globals, "stage1_dev", "")
  ret
end

- (String) removeBlanks(original)

remove blanks from section name and replace them with _

Parameters:

  • original (String)

    string

Returns:

  • (String)

    fixed string



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File '../../src/modules/BootLILO.rb', line 47

def removeBlanks(original)
  # do not allow empty labels
  while Ops.greater_than(Builtins.size(original), 1) &&
      Builtins.substring(original, 0, 1) == " "
    original = Builtins.substring(original, 1)
  end
  while Ops.greater_than(Builtins.size(original), 1) &&
      Builtins.substring(
        original,
        Ops.subtract(Builtins.size(original), 1),
        1
      ) == " "
    original = Builtins.substring(
      original,
      0,
      Ops.subtract(Builtins.size(original), 1)
    )
  end
  if Ops.greater_than(Builtins.size(original), 15)
    original = Builtins.substring(original, 0, 15)
  end
  String.Replace(original, " ", "_")
end

- (Boolean) Save(clean, init, flush)

Save all bootloader configuration files to the cache of the PlugLib PlugLib must be initialized properly !!!

Parameters:

  • clean (Boolean)

    boolean true if settings should be cleaned up (checking their correctness, supposing all files are on the disk

  • init (Boolean)

    boolean true to init the library

  • flush (Boolean)

    boolean true to flush settings to the disk

Returns:

  • (Boolean)

    true if success



186
187
188
189
190
# File '../../src/modules/BootLILO.rb', line 186

def Save(clean, init, flush)
  Ops.set(BootCommon.globals, "stage1_dev", BootCommon.loader_device)
  ret = BootCommon.Save(clean, init, flush)
  ret
end

- (Object) Update

Update read settings to new version of configuration files



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File '../../src/modules/BootLILO.rb', line 194

def Update
  BootCommon.UpdateDeviceMap

  # During update, for libata device name migration ("/dev/hda1" ->
  # "/dev/sda1") and somesuch, we need to re-read and parse the rest of the
  # configuration file contents after internally updating the device map in
  # perl-Bootloader. This way, the device names are consistent with the
  # partitioning information we have set up in perl-Bootloader with
  # SetDiskInfo(), and device names in other config files can be translated
  # to Unix device names (#328448, this hits sections that are not
  # (re-)created by yast-Bootloader or later by perl-Bootloader anyway).
  BootCommon.SetDeviceMap(BootStorage.device_mapping)
  Read(true, true)

  BootCommon.UpdateSections
  BootCommon.UpdateGlobals
  BootCommon.loader_device = BootCommon.UpdateDevice(
    BootCommon.loader_device
  )

  nil
end

- (Boolean) Write

Write bootloader settings to disk

Returns:

  • (Boolean)

    true on success



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

def Write
  ret = BootCommon.UpdateBootloader
  BootCommon.updateMBR
  if BootCommon.InstallingToFloppy
    if !saveToFLoppyPopup
      Builtins.y2error("Preparing floppy disk failed.")
      ret = false
    end
  end

  # Should we create a backup copy of bootloader bootsector?
  if Stage.initial
    mp = Storage.GetMountPoints
    data = Ops.get_list(mp, "/boot", Ops.get_list(mp, "/", []))
    bpd = Ops.get_string(data, 0, "")
    # ???? FIXME ???? how about LVM/MD ????
    if bpd == BootStorage.BootPartitionDevice &&
        getDeviceOfRaid(BootStorage.BootPartitionDevice) !=
          BootStorage.BootPartitionDevice &&
        Builtins.contains(
          BootStorage.getPartitionList(:boot, "lilo"),
          BootStorage.BootPartitionDevice
        )
      Builtins.y2milestone("Creating backup copy to bootsector")
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat(
          "/sbin/lilo -b %1",
          BootStorage.BootPartitionDevice
        )
      )
    end
  end

  ret = ret && BootCommon.InitializeBootloader
  ret = false if ret == nil
  ret = ret && BootCommon.PostUpdateMBR
  ret
end