/[gli]/branches/overhaul/src/templates/x86ArchitectureTemplate.py
Gentoo

Contents of /branches/overhaul/src/templates/x86ArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1113 - (show annotations) (download) (as text)
Mon Nov 28 01:42:22 2005 UTC (12 years, 9 months ago) by agaffney
Original Path: trunk/src/templates/x86ArchitectureTemplate.py
File MIME type: text/x-python
File size: 28934 byte(s)
  src/templates/x86ArchitectureTemplate.py:
  fix map() issue with grub code
  replace kernel_names and initrd_names loops with one-liners

1 """
2 # Copyright 1999-2005 Gentoo Foundation
3 # This source code is distributed under the terms of version 2 of the GNU
4 # General Public License as published by the Free Software Foundation, a copy
5 # of which can be found in the main directory of this project.
6 Gentoo Linux Installer
7
8 $Id: x86ArchitectureTemplate.py,v 1.87 2005/11/28 01:42:22 agaffney Exp $
9 Copyright 2004 Gentoo Technologies Inc.
10
11
12 This fills in x86 specific functions.
13 """
14
15 import GLIUtility, string, time
16 from GLIArchitectureTemplate import ArchitectureTemplate
17 from GLIException import *
18 import parted
19 import GLIStorageDevice
20
21 MEGABYTE = 1024 * 1024
22
23 class x86ArchitectureTemplate(ArchitectureTemplate):
24 def __init__(self,configuration=None, install_profile=None, client_controller=None):
25 ArchitectureTemplate.__init__(self, configuration, install_profile, client_controller)
26 self._architecture_name = 'x86'
27 self._kernel_bzimage = "arch/i386/boot/bzImage"
28
29 def install_bootloader(self):
30 "Installs and configures bootloader"
31 #
32 # THIS IS ARCHITECTURE DEPENDANT!!!
33 # This is the x86 way.. it uses grub
34
35 bootloader_pkg = self._install_profile.get_boot_loader_pkg()
36
37 # first install bootloader
38 if bootloader_pkg and bootloader_pkg.lower() != "none":
39 exitstatus = self._emerge(bootloader_pkg)
40 if not GLIUtility.exitsuccess(exitstatus):
41 raise GLIException("BootLoaderEmergeError", 'fatal', 'install_bootloader', "Could not emerge bootloader!")
42 else:
43 self._logger.log("Emerged the selected bootloader.")
44
45 # now configure said bootloader
46 # null boot-loader first
47 if bootloader_pkg.lower() == "none":
48 return
49 elif "grub" in bootloader_pkg: # this catches 'grub-static' as well as '=sys-boot/grub-0.95*'
50 self._configure_grub()
51 elif "lilo" in bootloader_pkg:
52 self._configure_lilo()
53 # probably should add in some more bootloaders
54 # dvhtool, raincoat, netboot, gnu-efi, cromwell, syslinux, psoload
55 else:
56 raise GLIException("BootLoaderError",'fatal','install_bootloader',"Don't know how to configure this bootloader: "+bootloader_pkg)
57
58 def _sectors_to_megabytes(self, sectors, sector_bytes=512):
59 return float((float(sectors) * sector_bytes)/ float(MEGABYTE))
60
61 def _add_partition(self, disk, start, end, type, fs):
62 types = { 'primary': parted.PARTITION_PRIMARY, 'extended': parted.PARTITION_EXTENDED, 'logical': parted.PARTITION_LOGICAL }
63 fsTypes = {}
64 fs_type = parted.file_system_type_get_next ()
65 while fs_type:
66 fsTypes[fs_type.name] = fs_type
67 fs_type = parted.file_system_type_get_next (fs_type)
68 fstype = None
69 if fs: fstype = fsTypes[fs]
70 newpart = disk.partition_new(types[type], fstype, start, end)
71 constraint = disk.dev.constraint_any()
72 disk.add_partition(newpart, constraint)
73
74 def partition(self):
75 parts_old = {}
76 tmp_parts_new = self._install_profile.get_partition_tables()
77 parts_new = {}
78 for device in tmp_parts_new:
79 parts_new[device] = tmp_parts_new[device].get_install_profile_structure()
80 detected_devices = GLIStorageDevice.detect_devices()
81 for device in detected_devices:
82 tmpdevice = GLIStorageDevice.Device(device)
83 tmpdevice.set_partitions_from_disk()
84 parts_old[device] = tmpdevice.get_install_profile_structure()
85
86 for device in parts_new.keys():
87 # Skip this device in parts_new if device isn't detected on current system
88 if not device in detected_devices:
89 self._logger.log("There is no physical device " + device + " detected to match the entry in the install profile...skipping")
90 continue
91
92 # Check to see if the old and new partition table structures are the same
93 table_changed = 0
94 for part in parts_new[device]:
95 if not part in parts_old[device]:
96 table_changed = 1
97 break
98 oldpart = parts_old[device][part]
99 newpart = parts_new[device][part]
100 if oldpart['type'] == newpart['type'] and oldpart['start'] == newpart['start'] and oldpart['end'] == newpart['end'] and newpart['format'] == False:
101 continue
102 else:
103 table_changed = 1
104 break
105 # Skip this device if they are they same
106 if not table_changed:
107 self._logger.log("Partition table for " + device + " is unchanged...skipping")
108 continue
109
110 # Create pyparted objects for this device
111 parted_dev = parted.PedDevice.get(device)
112 try:
113 parted_disk = parted.PedDisk.new(parted_dev)
114 except:
115 parted_disk = parted_dev.disk_new_fresh(parted.disk_type_get((tmp_parts_new[device].get_disklabel() or GLIStorageDevice.archinfo[self._architecture_name]['disklabel'])))
116 new_part_list = parts_new[device].keys()
117 new_part_list.sort()
118 device_sectors = parted_dev.length
119
120 # Iterate through new partitions and check for 'origminor' and 'format' == False
121 for part in parts_new[device].keys():
122 tmppart_new = parts_new[device][part]
123 if not tmppart_new['origminor'] or tmppart_new['format']: continue
124 tmppart_old = parts_old[device][tmppart_new['origminor']]
125 # This partition in parts_new corresponds with an existing partitions, so we save the start/end sector and flags
126 for flag in range(0, 10):
127 # The 10 is completely arbitrary. If flags seem to be missed, this number should be increased
128 parted_part = parted_disk.get_partition(part)
129 if not parted_part: break
130 if parted_part.is_flag_available(flag) and parted_part.get_flag(flag):
131 if not "flags" in tmppart_new: tmppart_new['flags'] = []
132 tmppart_new['flags'].append(flag)
133 if tmppart_old['mb'] == tmppart_new['mb']:
134 tmppart_new['start'] = tmppart_old['start']
135 tmppart_new['end'] = tmppart_old['end']
136 else:
137 tmppart_new['start'] = tmppart_old['start']
138 tmppart_new['end'] = 0
139
140 # if parts_new[dev][parts_new[dev].keys()[0]]['mb']:
141 # # Change MB/%/* into sectors
142 # total_sectors = parted_dev.length
143 # sector_size = parted_dev.sector_size
144 # total_mb = float(total_sectors * sector_size) / MEGABYTE
145 # start_sector = 0
146 # mb_left = total_mb
147 # for part in parts_new[dev]:
148 # tmppart = parts_new[dev][part]
149 # if tmppart['type'] == "extended": continue
150 # if tmppart['mb'][-1] == "%":
151 # tmppart['mb'] = float(tmppart['mb'][:-1]) / 100 * total_mb
152 # mb_left = mb_left - float(tmppart['mb'])
153 # partlist = parts_new.keys()
154 # partlist.sort()
155 # for part in partlist:
156 # if part > 4: continue
157 # tmppart = parts_new[dev][part]
158 # if tmppart['type'] == "extended":
159 # for part_log in partlist:
160 # if part < 5: continue
161 # tmppart_log = parts_new[dev][part_log]
162 # if not tmppart['start']:
163 # tmppart['start'] = start_sector
164 # if tmppart_log['mb'] == "*":
165 # tmppart_log['mb'] = mb_left
166 # part_bytes = long(tmppart_log['mb'] * MEGABYTE)
167 # part_sectors = round(part_bytes / sector_size)
168 # tmppart_log['start'] = start_sector
169 # tmppart_log['end'] = start_sector + part_sectors - 1
170 # tmppart['end'] = tmppart_log['end']
171 # start_sector = start_sector + part_sectors
172 # continue
173 # if tmppart['mb'] == "*":
174 # tmppart['mb'] = mb_left
175 # part_bytes = long(tmppart['mb'] * MEGABYTE)
176 # part_sectors = round(part_bytes / sector_size)
177 # tmppart['start'] = start_sector
178 # tmppart['end'] = start_sector + part_sectors - 1
179 # start_sector = start_sector + part_sectors
180 # else:
181
182 # First pass to delete old partitions that aren't resized
183 self._logger.log("partitioning: Processing " + device + "...")
184 for part in parts_old[device]:
185 oldpart = parts_old[device][part]
186 # Replace 'x86' with call function to get arch from CC
187 if (GLIStorageDevice.archinfo['x86']['extended'] and part > 4) or oldpart['type'] == "free": continue
188 delete = 0
189 if oldpart['type'] == "extended":
190 logical_to_resize = 0
191 for part_log in parts_old[device]:
192 if part_log < 5 or parts_old[device][part_log]['type'] == "free": continue
193 delete_log = 0
194 for new_part in parts_new[device]:
195 if new_part < 5: continue
196 tmppart = parts_new[device][new_part]
197 # This partition is unchanged in the new layout
198 if tmppart['origminor'] == part_log and tmppart['start'] and tmppart['end']:
199 self._logger.log(" Deleting old minor " + str(part_log) + " to be recreated later")
200 delete_log = 1
201 break
202 # This partition is resized with the data preserved in the new layout
203 if tmppart['origminor'] == part_log and tmppart['start'] and not tmppart['end']:
204 self._logger.log(" Ignoring old minor " + str(part_log) + " to resize later")
205 logical_to_resize = 1
206 break
207 if delete_log:
208 self._logger.log(" No match found...deleting partition " + str(part_log))
209 parted_disk.delete_partition(parted_disk.get_partition(part_log))
210 if not logical_to_resize:
211 self._logger.log(" Deleting extended partition with minor " + str(part))
212 parted_disk.delete_partition(parted_disk.get_partition(part))
213 continue
214 for new_part in parts_new[device]:
215 tmppart = parts_new[device][new_part]
216 if tmppart['origminor'] == part and tmppart['start'] and tmppart['end']:
217 self._logger.log(" Deleting old minor " + str(part) + " to be recreated later")
218 delete = 1
219 break
220 if tmppart['origminor'] == part and tmppart['start'] and not tmppart['end']:
221 self._logger.log(" Ignoring old minor " + str(part) + " to resize later")
222 break
223 if delete:
224 self._logger.log(" No match found...deleting partition " + str(part))
225 parted_disk.delete_partition(parted_disk.get_partition(part))
226 parted_disk.commit()
227
228 # Second pass to resize old partitions that need to be resized
229 self._logger.log("Partitioning: Second pass...")
230 for part in parts_old[device]:
231 oldpart = parts_old[device][part]
232 for new_part in parts_new[device]:
233 tmppart = parts_new[device][new_part]
234 if tmppart['origminor'] == part and tmppart['start'] and not tmppart['end']:
235 self._logger.log(" Resizing old minor " + str(part) + " from " + str(oldpart['start']) + "-" + str(oldpart['end'])+ " to " + str(tmppart['start']) + "-" + str(tmppart['end']))
236 type = tmppart['type']
237 minor = part
238 start = tmppart['start']
239 # Replace 512 with code to retrieve bytes per sector for device
240 end = start + (long(tmppart['mb']) * MEGABYTE / 512)
241 for i in new_part_list:
242 if i <= new_part: continue
243 if parts_new[device][i]['start'] and end >= parts_new[device][i]['start']:
244 end = parts_new[device][i]['start'] - 1
245 elif end >= device_sectors:
246 end = device_sectors - 1
247 break
248 if type == "ext2" or type == "ext3":
249 total_sectors = end - start + 1
250 ret = GLIUtility.spawn("resize2fs " + device + str(minor) + " " + str(total_sectors) + "s")
251 if ret: # Resize error
252 raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize " + device + str(minor))
253 elif type == "ntfs":
254 total_sectors = end - start + 1
255 total_bytes = long(total_sectors) * 512
256 ret = GLIUtility.spawn("ntfsresize --size " + str(total_bytes) + " " + device + str(minor))
257 if ret: # Resize error
258 raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize " + device + str(minor))
259 elif type == "linux-swap" or type == "fat32" or type == "fat16":
260 parted_fs = parted_disk.get_partition(part).geom.file_system_open()
261 resize_constraint = parted_fs.get_resize_constraint()
262 if end < (start + resize_constraint.min_size) or start != resize_constraint.start_range.start:
263 raise GLIException("PartitionError", 'fatal', 'partition', "New size specified for " + device + str(minor) + " is not within allowed boundaries")
264 new_geom = resize_constraint.start_range.duplicate()
265 new_geom.set_start(start)
266 new_geom.set_end(end)
267 try:
268 parted_fs.resize(new_geom)
269 except:
270 raise GLIException("PartitionResizeError", 'fatal', 'partition', "could not resize " + device + str(minor))
271 self._logger.log(" Deleting old minor " + str(part) + " to be recreated in 3rd pass")
272 parted_disk.delete_partition(parted_disk.get_partition(part))
273 break
274 parted_disk.delete_all()
275 parted_disk.commit()
276
277 # Third pass to create new partition table
278 self._logger.log("Partitioning: Third pass....creating partitions")
279 start = 0
280 end = 0
281 extended_start = 0
282 extended_end = 0
283 self._logger.log(" Drive has " + str(device_sectors) + " sectors")
284 # for part in parts_new[device]:
285 for part in new_part_list:
286 newpart = parts_new[device][part]
287 self._logger.log(" Partition " + str(part) + " has " + str(newpart['mb']) + "MB")
288 part_sectors = long(newpart['mb']) * MEGABYTE / 512
289 end = start + part_sectors
290 for i in new_part_list:
291 if i <= part: continue
292 if parts_new[device][i]['start'] and end >= parts_new[device][i]['start']:
293 end = parts_new[device][i]['start'] - 1
294 break
295 # cap to end of device
296 if end >= device_sectors:
297 end = device_sectors - 1
298 # now the actual creation
299 if newpart['type'] == "free":
300 # Nothing to be done for this type
301 pass
302 elif newpart['type'] == "extended":
303 self._logger.log(" Adding extended partition " + str(part) + " from " + str(start) + " to " + str(end))
304 self._add_partition(parted_disk, start, end, "extended", "")
305 extended_start = start
306 extended_end = end
307 elif part < 5 or not GLIStorageDevice.archinfo['x86']['extended']:
308 self._logger.log(" Adding primary partition " + str(part) + " from " + str(start) + " to " + str(end))
309 self._add_partition(parted_disk, start, end, "primary", newpart['type'])
310 elif GLIStorageDevice.archinfo['x86']['extended'] and part > 4:
311 if start >= extended_end:
312 start = extended_start + 1
313 end = start + part_sectors
314 if part == new_part_list[-1] and end > extended_end:
315 end = extended_end
316 self._logger.log(" Adding logical partition " + str(part) + " from " + str(start) + " to " + str(end))
317 self._add_partition(parted_disk, start, end, "logical", newpart['type'])
318 if "flags" in newpart:
319 for flag in newpart['flags']:
320 if parted_disk.get_partition(part).is_flag_available(flag):
321 parted_disk.get_partition(part).set_flag(flag, True)
322 # write to disk
323 parted_disk.commit()
324
325 # force rescan of partition table
326 # Should not be needed with current stuff
327 #ret = GLIUtility.spawn("partprobe "+device, logfile=self._compile_logfile, append_log=True)
328
329 # now format the partition
330 # extended and 'free' partitions should never be formatted
331 if newpart['format'] and newpart['type'] not in ('extended', 'free'):
332 devnode = device + str(int(part))
333 errormsg = "could't create %s filesystem on %s" % (newpart['type'],devnode)
334 # if you need a special command and
335 # some base options, place it here.
336 if newpart['type'] == 'linux-swap':
337 cmdname = 'mkswap'
338 elif newpart['type'] == 'fat16':
339 cmdname = 'mkfs.vfat -F 16'
340 elif newpart['type'] == 'fat32':
341 cmdname = 'mkfs.vfat -F 32'
342 elif newpart['type'] == 'ntfs':
343 cmdname = 'mkntfs'
344 # All of these types need a -f as they
345 # ask for confirmation of format
346 elif newpart['type'] in ('xfs','jfs','reiserfs'):
347 cmdname = 'mkfs.%s -f' % (newpart['type'])
348 # add common partition stuff here
349 elif newpart['type'] in ('ext2','ext3'):
350 cmdname = 'mkfs.%s' % (newpart['type'])
351 else: # this should catch everything else
352 raise GLIException("PartitionFormatError", 'fatal', 'partition',"Unknown partition type "+newpart['type'])
353
354 # force a stat of the device so that it
355 # is created on demand. (At least if I
356 # recall how udev works... - robbat2).
357 # sleep a bit first
358 time.sleep(1)
359 # now sleep until it exists
360 # while not GLIUtility.is_file(devnode):
361 # self._logger.log("Waiting for device node "+devnode+" to exist...")
362 # time.sleep(1)
363 # one bit of extra sleep is needed, as there is a blip still
364 # time.sleep(1)
365
366 tries = 0
367 while tries < 4:
368 # now the actual command
369 cmd = "%s %s %s" % (cmdname,newpart['mkfsopts'],devnode)
370 self._logger.log(" Formatting partition %s as %s with: %s" % (str(part),newpart['type'],cmd))
371 # If logging is not done, then you get errors:
372 # PartitionFormatError :FATAL: partition: could't create ext2 filesystem on /dev/hda1
373 #if GLIUtility.spawn(cmd):
374 #if GLIUtility.spawn(cmd,append_log=True,logfile='/var/log/install-mkfs.log'):
375 ret = GLIUtility.spawn(cmd, logfile=self._compile_logfile, append_log=True)
376 if not GLIUtility.exitsuccess(ret):
377 tries += 1
378 self._logger.log("Try %d failed formatting partition %s...waiting 5 seconds" % (tries, devnode))
379 time.sleep(5)
380 else:
381 break
382 if tries == 3:
383 raise GLIException("PartitionFormatError", 'fatal', 'partition', errormsg)
384 start = end + 1
385
386 def _configure_grub(self):
387 build_mode = self._install_profile.get_kernel_build_method()
388 boot_minor = ""
389 boot_device = ""
390 root_device = ""
391 root_minor = ""
392 mbr_device = ""
393 grub_root_minor = ""
394 grub_boot_minor = ""
395 grub_boot_drive = ""
396 grub_root_drive = ""
397 grub_mbr_drive = ""
398 minornum = 0
399 #Assign root to the root mount point to make lines more readable
400 root = self._chroot_dir
401
402
403 foundboot = False
404 parts = self._install_profile.get_partition_tables()
405 for device in parts:
406 tmp_partitions = parts[device].get_install_profile_structure()
407 for partition in tmp_partitions:
408 mountpoint = tmp_partitions[partition]['mountpoint']
409 if (mountpoint == "/boot"):
410 foundboot = True
411 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
412 boot_minor = str(int(tmp_partitions[partition]['minor']))
413 grub_boot_minor = str(int(tmp_partitions[partition]['minor']) - 1)
414 boot_device = device
415 mbr_device = device
416 if mountpoint == "/":
417 root_minor = str(int(tmp_partitions[partition]['minor']))
418 grub_root_minor = str(int(tmp_partitions[partition]['minor']) - 1)
419 root_device = device
420 #RESET the boot device if one is stored already
421 if self._install_profile.get_boot_device():
422 mbr_device = self._install_profile.get_boot_device()
423 self._logger.log("Found a mbr device: " + mbr_device)
424
425 exitstatus2, kernel_names = GLIUtility.spawn("ls -1 --color=no " + root + "/boot/kernel-*", return_output=True)
426 self._logger.log("Output of Kernel Names:\n"+kernel_names)
427 if not GLIUtility.exitsuccess(exitstatus2):
428 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error listing the kernels in /boot")
429 if build_mode == "genkernel" or self._install_profile.get_kernel_source_pkg() == "livecd-kernel":
430 exitstatus3, initrd_names = GLIUtility.spawn("ls -1 --color=no " + root + "/boot/init*", return_output=True)
431 self._logger.log("Output of Initrd Names:\n"+initrd_names)
432 if not GLIUtility.exitsuccess(exitstatus3):
433 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error listing the initrds")
434 self._logger.log("Bootloader: the three information gathering commands have been run")
435
436 grub_boot_drive = self._map_device_to_grub_device(boot_device)
437 grub_root_drive = self._map_device_to_grub_device(root_device)
438 grub_mbr_drive = self._map_device_to_grub_device(mbr_device)
439
440 if (not grub_root_drive) or (not grub_boot_drive):
441 raise GLIException("BootloaderError", 'fatal', '_configure_grub',"Couldn't find the drive num in the list from the device.map")
442
443 if not kernel_names[0]:
444 raise GLIException("BootloaderError", 'fatal', '_configure_grub',"Error: We have no kernel in /boot to put in the grub.conf file!")
445
446 #-------------------------------------------------------------
447 #OK, now that we have all the info, let's build that grub.conf
448 newgrubconf = ""
449 newgrubconf += "default 0\ntimeout 30\n"
450 if foundboot: #we have a /boot
451 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/grub/splash.xpm.gz\n"
452 else: #we have / and /boot needs to be included
453 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/boot/grub/splash.xpm.gz\n"
454 if self._install_profile.get_bootloader_kernel_args():
455 bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
456 else: bootloader_kernel_args = ""
457
458 kernel_names = map(string.strip, kernel_names.strip().split("\n"))
459 initrd_names = map(string.strip, initrd_names.strip().split("\n"))
460 grub_kernel_name = kernel_names[-1].split(root)[-1]
461 if initrd_names: grub_initrd_name = initrd_names[-1].split(root)[-1]
462 # for i in range(len(kernel_names)):
463 # grub_kernel_name = kernel_names[i].split(root)[-1]
464 # for i in range(len(initrd_names)): #this should be okay if blank.
465 # grub_initrd_name = initrd_names[i].split(root)[-1]
466 #i think this means take the last one it finds.. i.e. the newest.
467
468 newgrubconf += "title=Gentoo Linux\n"
469 newgrubconf += "root (" + grub_root_drive + "," + grub_root_minor + ")\n"
470 if build_mode != "genkernel" and self._install_profile.get_kernel_source_pkg() != "livecd-kernel": #using CUSTOM kernel
471 if foundboot:
472 newgrubconf += "kernel " + grub_kernel_name[5:] + " root="+root_device+root_minor+"\n"
473 else:
474 newgrubconf += "kernel /boot"+ grub_kernel_name[5:] + " root="+root_device+root_minor+"\n"
475 else: #using genkernel so it has an initrd.
476 if foundboot:
477 newgrubconf += "kernel " + grub_kernel_name[5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
478 newgrubconf += root_device + root_minor + " " + bootloader_kernel_args + "\n"
479 newgrubconf += "initrd " + grub_initrd_name[5:] + "\n"
480 else:
481 newgrubconf += "kernel /boot" + grub_kernel_name[5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
482 newgrubconf += root_device + root_minor + " " + bootloader_kernel_args + "\n"
483 newgrubconf += "initrd /boot" + grub_initrd_name[5:] + "\n"
484
485 #-------------------------------------------------------------
486 #OK, now that the file is built. Install grub.
487 #cp /proc/mounts /etc/mtab
488 #grub-install --root-directory=/boot /dev/hda
489 #shutil.copy("/proc/mounts",root +"/etc/mtab")
490 grubinstallstring = "echo -en 'root ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
491 if not self._install_profile.get_boot_loader_mbr():
492 grubinstallstring +="setup ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
493 else:
494 grubinstallstring +="setup ("+grub_mbr_drive+")\n"
495 grubinstallstring += "quit\n' | "+root+"/sbin/grub --batch --no-floppy"
496 if self._debug: self._logger.log("DEBUG: _configure_grub(): Grub install string: " + grubinstallstring)
497 exitstatus = GLIUtility.spawn(grubinstallstring, logfile=self._compile_logfile, append_log=True)
498 if not GLIUtility.exitsuccess(exitstatus):
499 raise GLIException("GrubInstallError", 'fatal', '_configure_grub', "Could not install grub!")
500 self._logger.log("Bootloader: grub has been installed!")
501 #now make the grub.conf file
502 file_name = root + "/boot/grub/grub.conf"
503 try:
504 shutil.move(file_name, file_name + ".OLDdefault")
505 except:
506 pass
507 f = open(file_name, 'w')
508 f.writelines(newgrubconf)
509 f.close()
510 self._logger.log("Grub installed and configured. Contents of grub.conf:\n"+newgrubconf)
511
512 def _configure_lilo(self):
513 build_mode = self._install_profile.get_kernel_build_method()
514 boot_device = ""
515 boot_minor = ""
516 root_device = ""
517 root_minor = ""
518 minornum = 0
519 #Assign root to the root mount point to make lines more readable
520 root = self._chroot_dir
521 file_name3 = root + "/boot/kernel_name"
522 foundboot = False
523 parts = self._install_profile.get_partition_tables()
524 for device in parts:
525 tmp_partitions = parts[device].get_install_profile_structure()
526 for partition in tmp_partitions:
527 mountpoint = tmp_partitions[partition]['mountpoint']
528 if (mountpoint == "/boot"):
529 foundboot = True
530 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
531 boot_minor = str(int(tmp_partitions[partition]['minor']))
532 boot_device = device
533 if mountpoint == "/":
534 root_minor = str(int(tmp_partitions[partition]['minor']))
535 root_device = device
536 exitstatus0 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
537 if (exitstatus0 != 0):
538 raise GLIException("BootloaderError", 'fatal', '_configure_lilo', "Could not list kernels in /boot or no kernels found.")
539 if build_mode == "genkernel" or self._install_profile.get_kernel_source_pkg() == "livecd-kernel":
540 exitstatus1 = GLIUtility.spawn("ls "+root+"/boot/init* >> "+file_name3)
541 if (exitstatus1 != 0):
542 raise GLIException("BootloaderError", 'fatal', '_configure_lilo', "Could not list initrds in /boot")
543 g = open(file_name3)
544 kernel_name = g.readlines()
545 g.close()
546 if not kernel_name[0]:
547 raise GLIException("BootloaderError", 'fatal', '_configure_lilo',"Error: We have no kernel in /boot to put in the grub.conf file!")
548 kernel_name = map(string.strip, kernel_name)
549 kernel_name[0] = kernel_name[0].split(root)[1]
550 kernel_name[1] = kernel_name[1].split(root)[1]
551 if self._install_profile.get_bootloader_kernel_args(): bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
552 else: bootloader_kernel_args = ""
553 #-------------------------------------------------------------
554 #time to build the lilo.conf
555 newliloconf = ""
556 if self._install_profile.get_boot_loader_mbr():
557 newliloconf += "boot="+boot_device+" # Install LILO in the MBR \n"
558 else:
559 newliloconf += "boot="+boot_device+boot_minor+" # Install LILO in the MBR \n"
560 newliloconf += "prompt # Give the user the chance to select another section\n"
561 newliloconf += "timeout=50 # Wait 5 (five) seconds before booting the default section\n"
562 newliloconf += "default=gentoo # When the timeout has passed, boot the \"gentoo\" section\n"
563 newliloconf += "# Only if you use framebuffer. Otherwise remove the following line:\n"
564 if not self._install_profile.get_kernel_bootsplash():
565 newliloconf += "#"
566 newliloconf += "vga=788 # Framebuffer setting. Adjust to your own will\n"
567 newliloconf += "image=/boot"+kernel_name[0][5:]+" \n"
568 newliloconf += " label=gentoo \n read-only \n"
569 if build_mode != "genkernel" and self._install_profile.get_kernel_source_pkg() != "livecd-kernel":
570 newliloconf += " root="+root_device+root_minor+" \n"
571 if bootloader_kernel_args:
572 newliloconf += " append=\""+bootloader_kernel_args+"\" \n"
573 else:
574 newliloconf += " root=/dev/ram0 \n"
575 newliloconf += " append=\"init=/linuxrc ramdisk=8192 real_root="+root_device+root_minor + " " + bootloader_kernel_args + "\" \n"
576 newliloconf += " initrd=/boot"+kernel_name[1][5:] + "\n\n"
577 newliloconf = self._lilo_add_windows(newliloconf)
578 #now make the lilo.conf file
579 file_name = root + "/etc/lilo.conf"
580 try:
581 shutil.move(file_name, file_name + ".OLDdefault")
582 except:
583 pass
584 f = open(file_name, 'w')
585 f.writelines(newliloconf)
586 f.close()
587 #-------------------------------------------------------------
588 #OK, now that the file is built. Install lilo.
589 exitstatus = GLIUtility.spawn("/sbin/lilo",chroot=self._chroot_dir)
590 if exitstatus != 0:
591 raise GLIException("LiloInstallError", 'fatal', '_configure_lilo', "Running lilo failed!")
592 self._logger.log("Lilo installed, configured, and run.")
593
594 def _lilo_add_windows(self, newliloconf):
595 parts = self._install_profile.get_partition_tables()
596 for device in parts:
597 tmp_partitions = parts[device].get_install_profile_structure()
598 for partition in tmp_partitions:
599 if (tmp_partitions[partition]['type'] == "vfat") or (tmp_partitions[partition]['type'] == "ntfs"):
600 newliloconf += "other="+device+str(int(tmp_partitions[partition]['minor']))+"\n"
601 newliloconf += "label=Windows_P"+str(int(tmp_partitions[partition]['minor']))+"\n\n"
602 return newliloconf
603
604 def _map_device_to_grub_device(self, device):
605 file_name = self._chroot_dir + "/boot/grub/glidevice.map"
606 #If we can't find it, make it. If we STILL can't find it. die.
607 if not GLIUtility.is_file(file_name):
608 exitstatus1 = GLIUtility.spawn("echo quit | "+ self._chroot_dir+"/sbin/grub --no-floppy --device-map="+file_name)
609 if not GLIUtility.is_file(file_name):
610 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error making the new device map.")
611 """
612 read the device map. sample looks like this:
613 (fd0) /dev/floppy/0
614 (hd0) /dev/sda
615 (hd1) /dev/hda
616 (hd2) /dev/hdb
617 """
618
619 # Search for the key
620 f = open(file_name) #open the device map
621 file = f.readlines()
622 f.close()
623 for i in range(len(file)):
624 if file[i][6:-1] == device:
625 return file[i][1:4]
626 raise GLIException("BootloaderError", 'fatal', '_map_device_to_grub_device', "ERROR, could not map"+device+" to anything in the device map")

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20