/[gli]/trunk/src/templates/x86ArchitectureTemplate.py
Gentoo

Contents of /trunk/src/templates/x86ArchitectureTemplate.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 769 - (show annotations) (download) (as text)
Sat Jul 30 19:44:28 2005 UTC (15 years, 4 months ago) by codeman
File MIME type: text/x-python
File size: 26522 byte(s)
  fixed livecd-kernel bug in bootloader code.

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

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20