/
grub2base.rb
164 lines (138 loc) · 4.31 KB
/
grub2base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
110
111
112
113
114
115
116
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# encoding: utf-8
require "yast"
module Yast
class GRUB2Base < Module
def main
Yast.import "UI"
textdomain "bootloader"
Yast.import "BootArch"
Yast.import "BootCommon"
Yast.import "BootStorage"
Yast.import "Kernel"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "Storage"
Yast.import "StorageDevices"
Yast.import "Pkg"
Yast.import "HTML"
Yast.import "Initrd"
Yast.import "Product"
# includes
# for simplified widgets than other
Yast.include self, "bootloader/grub2/dialogs.rb"
end
# general functions
# Propose global options of bootloader
def StandardGlobals
{
"timeout" => "8",
"default" => "0",
"vgamode" => "",
"gfxmode" => "auto",
"terminal" => "gfxterm",
"os_prober" => "true"
}
end
# Update read settings to new version of configuration files
def Update
Read(true, true)
#we don't handle sections, grub2 section create them for us
#BootCommon::UpdateSections ();
BootCommon.UpdateGlobals
nil
end
# Reset bootloader settings
# @param [Boolean] init boolean true to repropose also device map
def Reset(init)
return if Mode.autoinst
BootCommon.Reset(init)
nil
end
def Dialogs
Builtins.y2milestone("Called GRUB2 Dialogs")
{
"installation" => fun_ref(
method(:Grub2InstallDetailsDialog),
"symbol ()"
),
"loader" => fun_ref(
method(:Grub2LoaderDetailsDialog),
"symbol ()"
)
}
end
def Propose
if BootCommon.was_proposed
# workaround autoyast config is Imported thus was_proposed always set
if Mode.autoinst
Builtins.y2milestone(
"autoinst mode we ignore meaningless was_proposed as it always set"
)
else
Builtins.y2milestone(
"calling Propose with was_proposed set is really bogus, clear it to force a re-propose"
)
return
end
end
if BootCommon.globals == nil || Builtins.size(BootCommon.globals) == 0
BootCommon.globals = StandardGlobals()
else
BootCommon.globals = Convert.convert(
Builtins.union(BootCommon.globals, StandardGlobals()),
:from => "map",
:to => "map <string, string>"
)
end
swap_sizes = BootCommon.getSwapPartitions
swap_parts = Builtins.maplist(swap_sizes) { |name, size| name }
swap_parts = Builtins.sort(swap_parts) do |a, b|
Ops.greater_than(Ops.get(swap_sizes, a, 0), Ops.get(swap_sizes, b, 0))
end
largest_swap_part = Ops.get(swap_parts, 0, "")
resume = BootArch.ResumeAvailable ? largest_swap_part : ""
# try to use label or udev id for device name... FATE #302219
if resume != "" && resume != nil
resume = BootStorage.Dev2MountByDev(resume)
end
Ops.set(
BootCommon.globals,
"append",
BootArch.DefaultKernelParams(resume)
)
Ops.set(
BootCommon.globals,
"append_failsafe",
BootArch.FailsafeKernelParams
)
Ops.set(
BootCommon.globals,
"distributor",
Ops.add(Ops.add(Product.short_name, " "), Product.version)
)
BootCommon.kernelCmdLine = Kernel.GetCmdLine
Builtins.y2milestone("Proposed globals: %1", BootCommon.globals)
# Let grub2 scripts detects correct root= for us. :)
# BootCommon::globals["root"] = BootStorage::Dev2MountByDev(BootStorage::RootPartitionDevice);
# We don't set vga= if Grub2 gfxterm enabled, because the modesettings
# will be delivered to kernel by Grub2's gfxpayload set to "keep"
#if (BootArch::VgaAvailable () && Kernel::GetVgaType () != "")
#{
# BootCommon::globals["vgamode"] = Kernel::GetVgaType ();
#}
nil
end
# Initializer of GRUB bootloader
def Initializer
Builtins.y2milestone("Called GRUB2 initializer")
BootCommon.current_bootloader_attribs = {
"propose" => false,
"read" => false,
"scratch" => false,
"restore_mbr" => false,
"bootloader_on_disk" => false
}
nil
end
end
end