/[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 545 - (hide annotations) (download) (as text)
Mon May 2 14:45:32 2005 UTC (13 years, 6 months ago) by agaffney
Original Path: trunk/src/templates/x86ArchitectureTemplate.py
File MIME type: text/x-python
File size: 24175 byte(s)
remove duff import

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

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20