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
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
213
214
215
216
217
218
|
#
# bootloader.py: anaconda bootloader shims
#
# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author(s): Erik Troan <ewt@redhat.com>
# Jeremy Katz <katzj@redhat.com>
#
import isys
import partedUtils
import os, sys
import iutil
import string
from flags import flags
from constants import *
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
import logging
log = logging.getLogger("anaconda")
import booty
import bootloaderInfo
def bootloaderSetupChoices(anaconda):
if anaconda.dir == DISPATCH_BACK:
rc = anaconda.intf.messageWindow(_("Warning"),
_("Your filesystems have already been activated. You "
"cannot go back past this point.\n\nWould you like to "
"continue with the installation?"),
type="custom", custom_icon=["error","error"],
custom_buttons=[_("_Exit installer"), _("_Continue")])
if rc == 0:
sys.exit(0)
return DISPATCH_FORWARD
if anaconda.id.ksdata and anaconda.id.ksdata.bootloader.driveorder:
anaconda.id.bootloader.updateDriveList(anaconda.id.ksdata.bootloader.driveorder)
else:
#We want the selected bootloader drive to be preferred
pref = anaconda.id.bootloader.drivelist[:1]
anaconda.id.bootloader.updateDriveList(pref)
if iutil.isEfi() and not anaconda.id.bootloader.device:
bootPart = None
partitions = anaconda.id.storage.partitions
for part in partitions:
if part.partedPartition.active and \
partedUtils.isEfiSystemPartition(part.partedPartition):
bootPart = part.name
break
if bootPart:
anaconda.id.bootloader.setDevice(bootPart)
# iSeries bootloader on upgrades
if iutil.getPPCMachine() == "iSeries" and not anaconda.id.bootloader.device:
bootPart = None
partitions = anaconda.id.storage.partitions
for part in partitions:
if part.partedPartition.active and \
part.partedPartition.getFlag(parted.PARTITION_PREP):
bootPart = part.name
break
if bootPart:
anaconda.id.bootloader.setDevice(bootPart)
choices = anaconda.id.storage.fsset.bootloaderChoices(anaconda.id.bootloader)
if not choices and iutil.getPPCMachine() != "iSeries":
anaconda.dispatch.skipStep("instbootloader")
else:
anaconda.dispatch.skipStep("instbootloader", skip = 0)
# FIXME: ...
anaconda.id.bootloader.images.setup(anaconda.id.storage)
if anaconda.id.bootloader.defaultDevice != None and choices:
keys = choices.keys()
# there are only two possible things that can be in the keys
# mbr and boot. boot is ALWAYS present. so if the dev isn't
# listed, it was mbr and we should nicely fall back to boot
if anaconda.id.bootloader.defaultDevice not in keys:
log.warning("MBR not suitable as boot device; installing to partition")
anaconda.id.bootloader.defaultDevice = "boot"
anaconda.id.bootloader.setDevice(choices[anaconda.id.bootloader.defaultDevice][0])
elif choices and iutil.isMactel() and choices.has_key("boot"): # haccckkkk
anaconda.id.bootloader.setDevice(choices["boot"][0])
elif choices and choices.has_key("mbr") and not \
(choices.has_key("boot") and choices["boot"][1] == N_("RAID Device")):
anaconda.id.bootloader.setDevice(choices["mbr"][0])
elif choices and choices.has_key("boot"):
anaconda.id.bootloader.setDevice(choices["boot"][0])
def writeBootloader(anaconda):
def dosync():
isys.sync()
isys.sync()
isys.sync()
justConfigFile = not flags.setupFilesystems
if anaconda.id.bootloader.defaultDevice == -1:
return
# now make the upgrade stuff work for kickstart too. ick.
if anaconda.isKickstart and anaconda.id.bootloader.doUpgradeOnly:
import checkbootloader
(bootType, theDev) = checkbootloader.getBootloaderTypeAndBoot(anaconda.rootPath)
anaconda.id.bootloader.doUpgradeonly = 1
if bootType == "GRUB":
anaconda.id.bootloader.useGrubVal = 1
anaconda.id.bootloader.setDevice(theDev)
else:
anaconda.id.bootloader.doUpgradeOnly = 0
# We don't need to let the user know if we're just doing the bootloader.
if not justConfigFile:
w = anaconda.intf.waitWindow(_("Bootloader"), _("Installing bootloader..."))
kernelList = []
otherList = []
rootDev = getattr(anaconda.id.rootDevice, "path", None)
defaultDev = anaconda.id.bootloader.images.getDefault()
kernelLabel = None
kernelLongLabel = None
for (dev, (label, longlabel, type)) in anaconda.id.bootloader.images.getImages().items():
if (dev == rootDev) or (rootDev is None and kernelLabel is None):
kernelLabel = label
kernelLongLabel = longlabel
elif dev == defaultDev:
otherList = [(label, longlabel, dev)] + otherList
else:
otherList.append((label, longlabel, dev))
if kernelLabel is None:
log.error("unable to find default image, bailing")
if not justConfigFile:
w.pop()
return
plainLabelUsed = 0
defkern = "kernel"
for (version, arch, nick) in \
anaconda.backend.kernelVersionList(anaconda.rootPath):
if plainLabelUsed:
kernelList.append(("%s-%s" %(kernelLabel, nick),
"%s-%s" %(kernelLongLabel, nick),
version))
else:
kernelList.append((kernelLabel, kernelLongLabel, version))
if nick != "base":
defkern = "kernel-%s" %(nick,)
plainLabelUsed = 1
f = open(anaconda.rootPath + "/etc/sysconfig/kernel", "w+")
f.write("# UPDATEDEFAULT specifies if new-kernel-pkg should make\n"
"# new kernels the default\n")
# only update the default if we're setting the default to linux (#156678)
if rootDev == defaultDev:
f.write("UPDATEDEFAULT=yes\n")
else:
f.write("UPDATEDEFAULT=no\n")
f.write("\n")
f.write("# DEFAULTKERNEL specifies the default kernel package type\n")
f.write("DEFAULTKERNEL=%s\n" %(defkern,))
f.close()
dosync()
try:
anaconda.id.bootloader.write(anaconda.rootPath, anaconda.id.storage,
anaconda.id.bootloader,
anaconda.id.instLanguage,
kernelList, otherList, defaultDev,
justConfigFile, anaconda.intf)
if not justConfigFile:
w.pop()
except bootloaderInfo.BootyNoKernelWarning:
if not justConfigFile:
w.pop()
if anaconda.intf:
anaconda.intf.messageWindow(_("Warning"),
_("No kernel packages were installed on your "
"system. Your boot loader configuration "
"will not be changed."))
dosync()
# return instance of the appropriate bootloader for our arch
def getBootloader():
return booty.getBootloader()
def hasWindows(bl):
foundWindows = False
for (k,v) in bl.images.getImages().iteritems():
if v[0].lower() == 'other' and v[2] in bootloaderInfo.dosFilesystems:
foundWindows = True
break
return foundWindows
|