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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 869 - (show annotations) (download) (as text)
Thu Sep 1 17:05:13 2005 UTC (13 years, 2 months ago) by agaffney
File MIME type: text/x-python
File size: 28045 byte(s)
switch to 3 tries for mkfs instead of looping waiting for dev node to exist

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.63 2005/09/01 17:05:13 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 exitstatus != 0:
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":
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'] == 'fat32':
339 cmdname = 'mkfs.vfat -F 32'
340 elif newpart['type'] == 'ntfs':
341 cmdname = 'mkntfs'
342 # All of these types need a -f as they
343 # ask for confirmation of format
344 elif newpart['type'] in ('xfs','jfs','reiserfs'):
345 cmdname = 'mkfs.%s -f' % (newpart['type'])
346 # add common partition stuff here
347 elif newpart['type'] in ('ext2','ext3'):
348 cmdname = 'mkfs.%s' % (newpart['type'])
349 else: # this should catch everything else
350 raise GLIException("PartitionFormatError", 'fatal', 'partition',"Unknown partition type "+newpart['type'])
351
352 # force a stat of the device so that it
353 # is created on demand. (At least if I
354 # recall how udev works... - robbat2).
355 # sleep a bit first
356 time.sleep(1)
357 # now sleep until it exists
358 # while not GLIUtility.is_file(devnode):
359 # self._logger.log("Waiting for device node "+devnode+" to exist...")
360 # time.sleep(1)
361 # one bit of extra sleep is needed, as there is a blip still
362 # time.sleep(1)
363
364 tries = 0
365 while tries < 3:
366 # now the actual command
367 cmd = "%s %s %s" % (cmdname,newpart['mkfsopts'],devnode)
368 self._logger.log(" Formatting partition %s as %s with: %s" % (str(part),newpart['type'],cmd))
369 # If logging is not done, then you get errors:
370 # PartitionFormatError :FATAL: partition: could't create ext2 filesystem on /dev/hda1
371 #if GLIUtility.spawn(cmd):
372 #if GLIUtility.spawn(cmd,append_log=True,logfile='/var/log/install-mkfs.log'):
373 ret = GLIUtility.spawn(cmd, logfile=self._compile_logfile, append_log=True)
374 if not GLIUtility.exitsuccess(ret):
375 tries += 1
376 self._logger("Try %d failed formatting partition %s...waiting 2 seconds" % (tries, devnode))
377 time.sleep(2)
378 else:
379 break
380 if tries == 3:
381 raise GLIException("PartitionFormatError", 'fatal', 'partition', errormsg)
382 start = end + 1
383
384 def _configure_grub(self):
385 build_mode = self._install_profile.get_kernel_build_method()
386 boot_device = ""
387 boot_minor = ""
388 root_device = ""
389 root_minor = ""
390 grub_root_minor = ""
391 grub_boot_minor = ""
392 grub_boot_drive = ""
393 grub_root_drive = ""
394 minornum = 0
395 #Assign root to the root mount point to make lines more readable
396 root = self._chroot_dir
397 file_name2 = root + "/boot/grub/device.map"
398 file_name3 = root + "/boot/grub/kernel_name"
399 file_name4 = root + "/boot/grub/initrd_name"
400 foundboot = False
401 parts = self._install_profile.get_partition_tables()
402 for device in parts:
403 tmp_partitions = parts[device].get_install_profile_structure()
404 for partition in tmp_partitions:
405 mountpoint = tmp_partitions[partition]['mountpoint']
406 if (mountpoint == "/boot"):
407 foundboot = True
408 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
409 boot_minor = str(int(tmp_partitions[partition]['minor']))
410 grub_boot_minor = str(int(tmp_partitions[partition]['minor']) - 1)
411 boot_device = device
412 if mountpoint == "/":
413 root_minor = str(int(tmp_partitions[partition]['minor']))
414 grub_root_minor = str(int(tmp_partitions[partition]['minor']) - 1)
415 root_device = device
416 if GLIUtility.is_file(root+file_name2):
417 exitstatus = GLIUtility.spawn("rm "+root+file_name2)
418 if not GLIUtility.exitsuccess(exitstatus):
419 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Could not delete the old device map for grub.")
420 exitstatus1 = GLIUtility.spawn("echo quit | "+ root+"/sbin/grub --device-map="+file_name2)
421 if not GLIUtility.exitsuccess(exitstatus1):
422 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error making the new device map.")
423 exitstatus2 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
424 if not GLIUtility.exitsuccess(exitstatus2):
425 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error listing the kernels in /boot")
426 if build_mode == "genkernel" or self._install_profile.get_kernel_source_pkg() == "livecd-kernel":
427 exitstatus3 = GLIUtility.spawn("ls "+root+"/boot/init* > "+file_name4)
428 else:
429 exitstatus3 = GLIUtility.spawn("touch "+file_name4)
430 if not GLIUtility.exitsuccess(exitstatus3):
431 raise GLIException("BootloaderError", 'fatal', '_configure_grub', "Error either listing the initrds or touching "+file_name4)
432 self._logger.log("Bootloader: the three information gathering commands have been run")
433 """
434 read the device map. sample looks like this:
435 (fd0) /dev/floppy/0
436 (hd0) /dev/ide/host2/bus0/target0/lun0/disc
437 (hd1) /dev/ide/host0/bus0/target0/lun0/disc
438 (hd2) /dev/ide/host0/bus0/target1/lun0/disc
439 """
440
441 # Search for the key
442 f = open(file_name2) #open the device map
443 file = f.readlines()
444 f.close()
445 for i in range(len(file)):
446 if file[i][6:-1] == boot_device:
447 #eurika we found the drivenum
448 grub_boot_drive = file[i][1:4]
449 if file[i][6:-1] == root_device:
450 grub_root_drive = file[i][1:4]
451 if (not grub_root_drive) or (not grub_boot_drive):
452 raise GLIException("BootloaderError", 'fatal', '_configure_grub',"Couldn't find the drive num in the list from the device.map")
453
454 g = open(file_name3)
455 h = open(file_name4)
456 initrd_name = h.readlines()
457 kernel_name = g.readlines()
458 g.close()
459 h.close()
460 if not kernel_name[0]:
461 raise GLIException("BootloaderError", 'fatal', '_configure_grub',"Error: We have no kernel in /boot to put in the grub.conf file!")
462 kernel_name = map(string.strip, kernel_name)
463 initrd_name = map(string.strip, initrd_name)
464 for i in range(len(kernel_name)):
465 grub_kernel_name = kernel_name[i].split(root)[1]
466 for i in range(len(initrd_name)):
467 grub_initrd_name = initrd_name[i].split(root)[1]
468 #-------------------------------------------------------------
469 #OK, now that we have all the info, let's build that grub.conf
470 newgrubconf = ""
471 newgrubconf += "default 0\ntimeout 30\n"
472 if self._install_profile.get_bootloader_kernel_args(): bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
473 else: bootloader_kernel_args = ""
474 if foundboot: #we have a /boot
475 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/grub/splash.xpm.gz\n"
476 else: #we have / and /boot needs to be included
477 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/boot/grub/splash.xpm.gz\n"
478
479 newgrubconf += "title=Gentoo Linux\n"
480 newgrubconf += "root (" + grub_boot_drive + "," + grub_boot_minor + ")\n"
481 if build_mode != "genkernel" and self._install_profile.get_kernel_source_pkg() != "livecd-kernel": #using CUSTOM kernel
482 if foundboot:
483 newgrubconf += "kernel " + grub_kernel_name[5:] + " root="+root_device+root_minor+"\n"
484 else:
485 newgrubconf += "kernel /boot"+ grub_kernel_name[5:] + " root="+root_device+root_minor+"\n"
486 else: #using genkernel so it has an initrd.
487 if foundboot:
488 newgrubconf += "kernel " + grub_kernel_name[5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
489 newgrubconf += root_device + root_minor + " " + bootloader_kernel_args + "\n"
490 newgrubconf += "initrd " + grub_initrd_name[5:] + "\n"
491 else:
492 newgrubconf += "kernel /boot" + grub_kernel_name[5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
493 newgrubconf += root_device + root_minor + " " + bootloader_kernel_args + "\n"
494 newgrubconf += "initrd /boot" + grub_initrd_name[5:] + "\n"
495
496 #-------------------------------------------------------------
497 #OK, now that the file is built. Install grub.
498 #cp /proc/mounts /etc/mtab
499 #grub-install --root-directory=/boot /dev/hda
500 #shutil.copy("/proc/mounts",root +"/etc/mtab")
501 grubinstallstring = "echo -en 'root ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
502 if not self._install_profile.get_boot_loader_mbr():
503 grubinstallstring +="setup ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
504 else:
505 grubinstallstring +="setup ("+grub_boot_drive+")\n"
506 grubinstallstring += "quit\n' | "+root+"/sbin/grub"
507 #print grubinstallstring
508 exitstatus = GLIUtility.spawn(grubinstallstring)
509 if exitstatus != 0:
510 raise GLIException("GrubInstallError", 'fatal', '_configure_grub', "Could not install grub!")
511 self._logger.log("Bootloader: grub has been installed!")
512 #now make the grub.conf file
513 file_name = root + "/boot/grub/grub.conf"
514 try:
515 shutil.move(file_name, file_name + ".OLDdefault")
516 except:
517 pass
518 f = open(file_name, 'w')
519 f.writelines(newgrubconf)
520 f.close()
521 self._logger.log("Grub installed and configured.")
522
523 def _configure_lilo(self):
524 boot_device = ""
525 boot_minor = ""
526 root_device = ""
527 root_minor = ""
528 minornum = 0
529 #Assign root to the root mount point to make lines more readable
530 root = self._chroot_dir
531 file_name3 = root + "/boot/kernel_name"
532 foundboot = False
533 parts = self._install_profile.get_partition_tables()
534 for device in parts:
535 tmp_partitions = parts[device].get_install_profile_structure()
536 for partition in tmp_partitions:
537 mountpoint = tmp_partitions[partition]['mountpoint']
538 if (mountpoint == "/boot"):
539 foundboot = True
540 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
541 boot_minor = str(int(tmp_partitions[partition]['minor']))
542 boot_device = device
543 if mountpoint == "/":
544 root_minor = str(int(tmp_partitions[partition]['minor']))
545 root_device = device
546 exitstatus0 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
547 if (exitstatus0 != 0):
548 raise GLIException("BootloaderError", 'fatal', '_configure_lilo', "Could not list kernels in /boot or no kernels found.")
549 if build_mode == "genkernel" or self._install_profile.get_kernel_source_pkg() == "livecd-kernel":
550 exitstatus1 = GLIUtility.spawn("ls "+root+"/boot/init* >> "+file_name3)
551 if (exitstatus1 != 0):
552 raise GLIException("BootloaderError", 'fatal', '_configure_lilo', "Could not list initrds in /boot")
553 g = open(file_name3)
554 kernel_name = g.readlines()
555 g.close()
556 if not kernel_name[0]:
557 raise GLIException("BootloaderError", 'fatal', '_configure_lilo',"Error: We have no kernel in /boot to put in the grub.conf file!")
558 kernel_name = map(string.strip, kernel_name)
559 kernel_name[0] = kernel_name[0].split(root)[1]
560 kernel_name[1] = kernel_name[1].split(root)[1]
561 if self._install_profile.get_bootloader_kernel_args(): bootloader_kernel_args = self._install_profile.get_bootloader_kernel_args()
562 else: bootloader_kernel_args = ""
563 #-------------------------------------------------------------
564 #time to build the lilo.conf
565 newliloconf = ""
566 if self._install_profile.get_boot_loader_mbr():
567 newliloconf += "boot="+boot_device+" # Install LILO in the MBR \n"
568 else:
569 newliloconf += "boot="+boot_device+boot_minor+" # Install LILO in the MBR \n"
570 newliloconf += "prompt # Give the user the chance to select another section\n"
571 newliloconf += "timeout=50 # Wait 5 (five) seconds before booting the default section\n"
572 newliloconf += "default=gentoo # When the timeout has passed, boot the \"gentoo\" section\n"
573 newliloconf += "# Only if you use framebuffer. Otherwise remove the following line:\n"
574 if not self._install_profile.get_kernel_bootsplash():
575 newliloconf += "#"
576 newliloconf += "vga=788 # Framebuffer setting. Adjust to your own will\n"
577 newliloconf += "image=/boot"+kernel_name[0][5:]+" \n"
578 newliloconf += " label=gentoo \n read-only \n"
579 if build_mode != "genkernel" and self._install_profile.get_kernel_source_pkg() != "livecd-kernel":
580 newliloconf += " root="+root_device+root_minor+" \n"
581 if bootloader_kernel_args:
582 newliloconf += " append=\""+bootloader_kernel_args+"\" \n"
583 else:
584 newliloconf += " root=/dev/ram0 \n"
585 newliloconf += " append=\"init=/linuxrc ramdisk=8192 real_root="+root_device+root_minor + " " + bootloader_kernel_args + "\" \n"
586 newliloconf += " initrd=/boot"+kernel_name[1][5:] + "\n\n"
587 newliloconf = self._lilo_add_windows(newliloconf)
588 #now make the lilo.conf file
589 file_name = root + "/etc/lilo.conf"
590 try:
591 shutil.move(file_name, file_name + ".OLDdefault")
592 except:
593 pass
594 f = open(file_name, 'w')
595 f.writelines(newliloconf)
596 f.close()
597 #-------------------------------------------------------------
598 #OK, now that the file is built. Install lilo.
599 exitstatus = GLIUtility.spawn("/sbin/lilo",chroot=self._chroot_dir)
600 if exitstatus != 0:
601 raise GLIException("LiloInstallError", 'fatal', '_configure_lilo', "Running lilo failed!")
602 self._logger.log("Lilo installed, configured, and run.")
603
604 def _lilo_add_windows(self, newliloconf):
605 parts = self._install_profile.get_partition_tables()
606 for device in parts:
607 tmp_partitions = parts[device].get_install_profile_structure()
608 for partition in tmp_partitions:
609 if (tmp_partitions[partition]['type'] == "vfat") or (tmp_partitions[partition]['type'] == "ntfs"):
610 newliloconf += "other="+device+str(int(tmp_partitions[partition]['minor']))+"\n"
611 newliloconf += "label=Windows_P"+str(int(tmp_partitions[partition]['minor']))+"\n\n"
612 return newliloconf

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20