1 |
gordonr |
1.1 |
# |
2 |
|
|
# bootloader.py: anaconda bootloader shims |
3 |
|
|
# |
4 |
|
|
# Erik Troan <ewt@redhat.com> |
5 |
|
|
# Jeremy Katz <katzj@redhat.com> |
6 |
|
|
# |
7 |
|
|
# Copyright 2001-2002 Red Hat, Inc. |
8 |
|
|
# |
9 |
|
|
# This software may be freely redistributed under the terms of the GNU |
10 |
|
|
# library public license. |
11 |
|
|
# |
12 |
|
|
# You should have received a copy of the GNU Library Public License |
13 |
|
|
# along with this program; if not, write to the Free Software |
14 |
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 |
|
|
# |
16 |
|
|
|
17 |
|
|
import isys |
18 |
|
|
import partitioning |
19 |
|
|
import partedUtils |
20 |
|
|
import os |
21 |
|
|
import crypt |
22 |
|
|
import whrandom |
23 |
|
|
import language |
24 |
|
|
import iutil |
25 |
|
|
import string |
26 |
|
|
from flags import flags |
27 |
|
|
from constants import * |
28 |
|
|
|
29 |
|
|
from rhpl.log import log |
30 |
|
|
from rhpl.translate import _ |
31 |
|
|
|
32 |
|
|
from booty import * |
33 |
|
|
from bootloaderInfo import * |
34 |
|
|
from fsset import * |
35 |
|
|
|
36 |
|
|
showLilo = 0 |
37 |
|
|
try: |
38 |
|
|
f = open("/proc/cmdline", "r") |
39 |
|
|
if f.read().find("lilo") != -1: |
40 |
|
|
showLilo = 1 |
41 |
|
|
except: |
42 |
|
|
pass |
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
def bootloaderSetupChoices(dispatch, bl, fsset, diskSet, dir): |
47 |
|
|
if dir == DISPATCH_BACK: |
48 |
|
|
return |
49 |
|
|
|
50 |
|
|
# iSeries bootloader on upgrades |
51 |
|
|
if iutil.getPPCMachine() == "iSeries" and not bl.device: |
52 |
|
|
drives = diskSet.disks.keys() |
53 |
|
|
drives.sort() |
54 |
|
|
bootPart = None |
55 |
|
|
for drive in drives: |
56 |
|
|
disk = diskSet.disks[drive] |
57 |
|
|
part = disk.next_partition() |
58 |
|
|
while part: |
59 |
|
|
if part.is_active() and part.native_type == 0x41: |
60 |
|
|
bootPart = partedUtils.get_partition_name(part) |
61 |
|
|
break |
62 |
|
|
part = disk.next_partition(part) |
63 |
|
|
if bootPart: |
64 |
|
|
break |
65 |
|
|
if bootPart: |
66 |
|
|
bl.setDevice(bootPart) |
67 |
|
|
dev = Device() |
68 |
|
|
dev.device = bootPart |
69 |
|
|
fsset.add(FileSystemSetEntry(dev, None, fileSystemTypeGet("PPC PReP Boot"))) |
70 |
|
|
|
71 |
|
|
choices = fsset.bootloaderChoices(diskSet, bl) |
72 |
|
|
if not choices and iutil.getPPCMachine() != "iSeries": |
73 |
|
|
dispatch.skipStep("instbootloader") |
74 |
|
|
else: |
75 |
|
|
dispatch.skipStep("instbootloader", skip = 0) |
76 |
|
|
|
77 |
|
|
bl.images.setup(diskSet, fsset) |
78 |
|
|
|
79 |
|
|
if bl.defaultDevice != None and choices: |
80 |
|
|
keys = choices.keys() |
81 |
|
|
# there are only two possible things that can be in the keys |
82 |
|
|
# mbr and boot. boot is ALWAYS present. so if the dev isn't |
83 |
|
|
# listed, it was mbr and we should nicely fall back to boot |
84 |
|
|
if bl.defaultDevice not in keys: |
85 |
|
|
log("MBR not suitable as boot device; installing to partition") |
86 |
|
|
bl.defaultDevice = "boot" |
87 |
|
|
bl.setDevice(choices[bl.defaultDevice][0]) |
88 |
|
|
elif choices and choices.has_key("mbr"): |
89 |
|
|
bl.setDevice(choices["mbr"][0]) |
90 |
|
|
elif choices and choices.has_key("boot"): |
91 |
|
|
bl.setDevice(choices["boot"][0]) |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
bootDev = fsset.getEntryByMountPoint("/") |
95 |
|
|
if not bootDev: |
96 |
|
|
bootDev = fsset.getEntryByMountPoint("/boot") |
97 |
|
|
part = partedUtils.get_partition_by_name(diskSet.disks, |
98 |
|
|
bootDev.device.getDevice()) |
99 |
|
|
if part and partedUtils.end_sector_to_cyl(part.geom.dev, |
100 |
|
|
part.geom.end) >= 1024: |
101 |
|
|
bl.above1024 = 1 |
102 |
|
|
|
103 |
|
|
|
104 |
|
|
def writeBootloader(intf, instRoot, fsset, bl, langs, comps): |
105 |
|
|
def dosync(): |
106 |
|
|
isys.sync() |
107 |
|
|
isys.sync() |
108 |
|
|
isys.sync() |
109 |
|
|
|
110 |
|
|
justConfigFile = not flags.setupFilesystems |
111 |
|
|
|
112 |
|
|
if bl.defaultDevice == -1: |
113 |
|
|
return |
114 |
|
|
|
115 |
|
|
# now make the upgrade stuff work for kickstart too. ick. |
116 |
|
|
if bl.kickstart == 1 and bl.doUpgradeOnly == 1: |
117 |
|
|
import checkbootloader |
118 |
|
|
(bootType, theDev) = checkbootloader.getBootloaderTypeAndBoot(instRoot) |
119 |
|
|
|
120 |
|
|
bl.doUpgradeonly = 1 |
121 |
|
|
if bootType == "GRUB": |
122 |
|
|
bl.useGrubVal = 1 |
123 |
|
|
bl.setDevice(theDev) |
124 |
|
|
elif bootType == "LILO": |
125 |
|
|
bl.useGrubVal = 0 |
126 |
|
|
bl.setDevice(theDev) |
127 |
|
|
else: |
128 |
|
|
bl.doUpgradeOnly = 0 |
129 |
|
|
|
130 |
|
|
# We don't need to let the user know if we're just doing the bootloader. |
131 |
|
|
if not justConfigFile: |
132 |
|
|
w = intf.waitWindow(_("Bootloader"), _("Installing bootloader...")) |
133 |
|
|
|
134 |
|
|
kernelList = [] |
135 |
|
|
otherList = [] |
136 |
|
|
rootDev = fsset.getEntryByMountPoint('/').device.getDevice() |
137 |
|
|
defaultDev = bl.images.getDefault() |
138 |
|
|
|
139 |
|
|
kernelLabel = None |
140 |
|
|
kernelLongLabel = None |
141 |
|
|
|
142 |
|
|
for (dev, (label, longlabel, type)) in bl.images.getImages().items(): |
143 |
|
|
if dev == rootDev: |
144 |
|
|
kernelLabel = label |
145 |
|
|
kernelLongLabel = longlabel |
146 |
|
|
elif dev == defaultDev: |
147 |
|
|
otherList = [(label, longlabel, dev)] + otherList |
148 |
|
|
else: |
149 |
|
|
otherList.append((label, longlabel, dev)) |
150 |
|
|
|
151 |
|
|
if kernelLabel is None: |
152 |
|
|
log("unable to find default image, bailing") |
153 |
|
|
if not justConfigFile: |
154 |
|
|
w.pop() |
155 |
|
|
return |
156 |
|
|
|
157 |
|
|
plainLabelUsed = 0 |
158 |
|
|
defkern = "kernel" |
159 |
|
|
for (version, nick) in comps.kernelVersionList(): |
160 |
|
|
if plainLabelUsed: |
161 |
|
|
kernelList.append(("%s-%s" %(kernelLabel, nick), |
162 |
|
|
"%s-%s" %(kernelLongLabel, nick), |
163 |
|
|
version)) |
164 |
|
|
else: |
165 |
|
|
kernelList.append((kernelLabel, kernelLongLabel, version)) |
166 |
|
|
if nick != "up": |
167 |
|
|
defkern = "kernel-%s" %(nick,) |
168 |
|
|
plainLabelUsed = 1 |
169 |
|
|
|
170 |
|
|
f = open(instRoot + "/etc/sysconfig/kernel", "w+") |
171 |
|
|
f.write("# UPDATEDEFAULT specifies if new-kernel-pkg should make\n" |
172 |
|
|
"# new kernels the default\n") |
173 |
|
|
f.write("UPDATEDEFAULT=yes\n") |
174 |
|
|
f.write("\n") |
175 |
|
|
f.write("# DEFAULTKERNEL specifies the default kernel package type\n") |
176 |
|
|
f.write("DEFAULTKERNEL=%s\n" %(defkern,)) |
177 |
|
|
f.close() |
178 |
|
|
|
179 |
|
|
dosync() |
180 |
|
|
try: |
181 |
|
|
bl.write(instRoot, fsset, bl, langs, kernelList, otherList, defaultDev, |
182 |
|
|
justConfigFile, intf) |
183 |
|
|
if not justConfigFile: |
184 |
|
|
w.pop() |
185 |
|
|
except BootyNoKernelWarning: |
186 |
|
|
if not justConfigFile: |
187 |
|
|
w.pop() |
188 |
|
|
# if intf: |
189 |
|
|
# intf.messageWindow(_("Warning"), |
190 |
|
|
# _("No kernel packages were installed on your " |
191 |
|
|
# "system. Your boot loader configuration " |
192 |
|
|
# "will not be changed.")) |
193 |
|
|
dosync() |
194 |
|
|
|
195 |
|
|
# note that this function no longer actually creates an initrd. |
196 |
|
|
# the kernel's %post does this now |
197 |
|
|
def makeInitrd (kernelTag, instRoot): |
198 |
|
|
if iutil.getArch() == 'ia64': |
199 |
|
|
initrd = "/boot/efi/initrd%s.img" % (kernelTag, ) |
200 |
|
|
else: |
201 |
|
|
initrd = "/boot/initrd%s.img" % (kernelTag, ) |
202 |
|
|
|
203 |
|
|
return initrd |
204 |
|
|
|
205 |
|
|
# return instance of the appropriate bootloader for our arch |
206 |
|
|
def getBootloader(): |
207 |
|
|
import booty |
208 |
|
|
return booty.getBootloader() |