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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 234 Revision 235
1""" 1"""
2Gentoo Linux Installer 2Gentoo Linux Installer
3 3
4$Id: x86ArchitectureTemplate.py,v 1.12 2005/01/12 03:46:53 agaffney Exp $ 4$Id: x86ArchitectureTemplate.py,v 1.13 2005/01/14 06:31:08 codeman Exp $
5Copyright 2004 Gentoo Technologies Inc. 5Copyright 2004 Gentoo Technologies Inc.
6 6
7 7
8This fills in x86 specific functions. 8This fills in x86 specific functions.
9""" 9"""
29 if exitstatus != 0: 29 if exitstatus != 0:
30 raise GLIException("BootLoaderEmergeError", 'fatal', 'install_bootloader', "Could not emerge bootloader!") 30 raise GLIException("BootLoaderEmergeError", 'fatal', 'install_bootloader', "Could not emerge bootloader!")
31 else: 31 else:
32 pass 32 pass
33 33
34 boot_device = "" 34 if self._install_profile.get_boot_loader_pkg() == "grub":
35 boot_minor = "" 35 self._install_grub()
36 root_device = "" 36 elif self._install_profile.get_boot_loader_pkg() == "lilo":
37 root_minor = "" 37 self._install_lilo()
38 grub_root_minor = ""
39 grub_boot_minor = ""
40 grub_boot_drive = ""
41 grub_root_drive = ""
42 minornum = 0
43 #Assign root to the root mount point to make lines more readable
44 root = self._chroot_dir
45 file_name = root + "/boot/grub/bootdevice"
46 file_name1 = root + "/boot/grub/rootdevice"
47 file_name2 = root + "/boot/grub/device.map"
48 file_name3 = root + "/boot/grub/kernel_name"
49 foundboot = False
50 #partitions = self._install_profile.get_fstab()
51 parts = self._install_profile.get_partition_tables()
52 for device in parts:
53 #in parts['/dev/hda']
54 for partition in parts[device]:
55 #print parts[device][partition]
56 mountpoint = parts[device][partition]['mountpoint']
57 if (mountpoint == "/boot"):
58 foundboot = True
59 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
60 boot_minor = str(parts[device][partition]['minor'])
61 grub_boot_minor = str(parts[device][partition]['minor'] - 1)
62 boot_device = device
63 if mountpoint == "/":
64 root_minor = str(parts[device][partition]['minor'])
65 grub_root_minor = str(parts[device][partition]['minor'] - 1)
66 root_device = device
67
68
69 #for partition in partitions:
70 #if find a /boot then stop.. else we'll take a / and overwrite with a /boot if we find it too.
71 # if (partition == "/boot"):
72 #try to get the drive LETTER from /dev/hdc1 8th character
73 # boot_minor = partitions[partition][0][8]
74 # grub_boot_minor = str(int(boot_minor) - 1)
75 # boot_device = partitions[partition][0][0:8]
76 # foundboot = True
77 # if ( (partition == "/") and (not foundboot) ):
78 # boot_minor = partitions[partition][0][8]
79 # grub_boot_minor = str(int(boot_minor) - 1)
80 # boot_device = partitions[partition][0][0:8]
81 #Foundboot IS STILL FALSE
82 # if partition == "/":
83 # root_minor = partitions[partition][0][8]
84 # grub_root_minor = str(int(root_minor) - 1)
85 # root_device = partitions[partition][0][0:8]
86
87 exitstatus0 = GLIUtility.spawn("ls -l " + boot_device + " > " + file_name)
88 exitstatus1 = GLIUtility.spawn("ls -l " + root_device + " > " + file_name1)
89 exitstatus2 = GLIUtility.spawn("echo quit | "+ root+"/sbin/grub --device-map="+file_name2)
90 exitstatus3 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
91 exitstatus4 = GLIUtility.spawn("ls "+root+"/boot/initrd-* >> "+file_name3)
92 if (exitstatus0 != 0) or (exitstatus1 != 0) or (exitstatus2 != 0) or (exitstatus3 != 0) or (exitstatus4 != 0):
93 raise GLIException("BootloaderError", 'fatal', 'install_bootloader', "Error in one of THE FOUR run commands")
94
95 """
96 read the device map. sample looks like this:
97 (fd0) /dev/floppy/0
98 (hd0) /dev/ide/host2/bus0/target0/lun0/disc
99 (hd1) /dev/ide/host0/bus0/target0/lun0/disc
100 (hd2) /dev/ide/host0/bus0/target1/lun0/disc
101 """
102 e = open(file_name) #Looking for the boot device
103 ls_output = e.readlines()
104 e.close()
105 # looks like lr-xr-xr-x 1 root root 32 Oct 1 16:09 /dev/hda -> ide/host0/bus0/target0/lun0/disc
106 ls_output = ls_output[0].split(">")[-1]
107 ls_output = ls_output[1:]
108
109 eb = open(file_name1) #Looking for the root device
110 ls_outputb = eb.readlines()
111 eb.close()
112 ls_outputb = ls_outputb[0].split(">")[-1]
113 ls_outputb = ls_outputb[1:]
114
115 # Search for the key
116 f = open(file_name2)
117 file = f.readlines()
118 f.close()
119 for i in range(len(file)):
120 if file[i][11:] == ls_output:
121 #eurika we found the drivenum
122 grub_boot_drive = file[i][1:4]
123 if file[i][11:] == ls_outputb:
124 grub_root_drive = file[i][1:4]
125 if (not grub_root_drive) or (not grub_boot_drive):
126 raise GLIException("BootloaderError", 'fatal', 'install_bootloader',"Couldn't find the drive num in the list from the device.map")
127
128 g = open(file_name3)
129 kernel_name = g.readlines()
130 g.close()
131 if not kernel_name[0]:
132 raise GLIException("BootloaderError", 'fatal', 'install_bootloader',"Error: We have no kernel in /boot to put in the grub.conf file!")
133 kernel_name = map(string.strip, kernel_name)
134 kernel_name[0] = kernel_name[0].split(root)[1]
135 kernel_name[1] = kernel_name[1].split(root)[1]
136 #-------------------------------------------------------------
137 #OK, now that we have all the info, let's build that grub.conf
138 newgrubconf = ""
139 newgrubconf += "default 0\ntimeout 30\n"
140 if foundboot: #we have a /boot
141 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/grub/splash.xpm.gz\n"
142 else: #we have / and /boot needs to be included
143 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/boot/grub/splash.xpm.gz\n"
144
145 newgrubconf += "title=Gentoo Linux\n"
146 newgrubconf += "root (" + grub_boot_drive + "," + grub_boot_minor + ")\n"
147 if foundboot:
148 newgrubconf += "kernel " + kernel_name[0][5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
149 newgrubconf += root_device + root_minor + "\n"
150 newgrubconf += "initrd " + kernel_name[1][5:] + "\n"
151 else: 38 else:
152 newgrubconf += "kernel /boot" + kernel_name[0][5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=" 39 raise Exception("BootLoaderError",'fatal','install_bootloader',"Invalid bootloader selected:"+self._install_profile.get_boot_loader_pkg())
153 newgrubconf += root_device + root_minor + "\n"
154 newgrubconf += "initrd /boot" + kernel_name[1][5:] + "\n"
155
156 #-------------------------------------------------------------
157 #OK, now that the file is built. Install grub.
158 #cp /proc/mounts /etc/mtab
159 #grub-install --root-directory=/boot /dev/hda
160 #shutil.copy("/proc/mounts",root +"/etc/mtab")
161 grubinstallstring = "echo -en 'root ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
162 if not self._install_profile.get_boot_loader_mbr():
163 grubinstallstring +="setup ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
164 else:
165 grubinstallstring +="setup ("+grub_boot_drive+")\n"
166 grubinstallstring += "quit\n' | "+root+"/sbin/grub"
167 print grubinstallstring
168 exitstatus = GLIUtility.spawn(grubinstallstring,chroot=self._chroot_dir)
169 if exitstatus != 0:
170 raise GLIException("GrubInstallError", 'fatal', 'install_bootloader', "Could not install grub!")
171
172 #now make the grub.conf file
173 file_name = root + "/boot/grub/grub.conf"
174 try:
175 shutil.move(file_name, file_name + ".OLDdefault")
176 except:
177 pass
178 f = open(file_name, 'w')
179 f.writelines(newgrubconf)
180 f.close()
181 40
182 def _sectors_to_megabytes(self, sectors, sector_bytes=512): 41 def _sectors_to_megabytes(self, sectors, sector_bytes=512):
183 return float((float(sectors) * sector_bytes)/ float(1024*1024)) 42 return float((float(sectors) * sector_bytes)/ float(1024*1024))
184 43
185 def _add_partition(self, disk, start, end, type, fs): 44 def _add_partition(self, disk, start, end, type, fs):
355 parted_disk.get_partition(part).set_flag(1) 214 parted_disk.get_partition(part).set_flag(1)
356 if int(part) in parts_lba and not newpart['format']: 215 if int(part) in parts_lba and not newpart['format']:
357 print " Partition was previously LBA...setting" 216 print " Partition was previously LBA...setting"
358 parted_disk.get_partition(part).set_flag(7) 217 parted_disk.get_partition(part).set_flag(7)
359 parted_disk.commit() 218 parted_disk.commit()
219 def _install_grub(self):
220 boot_device = ""
221 boot_minor = ""
222 root_device = ""
223 root_minor = ""
224 grub_root_minor = ""
225 grub_boot_minor = ""
226 grub_boot_drive = ""
227 grub_root_drive = ""
228 minornum = 0
229 #Assign root to the root mount point to make lines more readable
230 root = self._chroot_dir
231 file_name = root + "/boot/grub/bootdevice"
232 file_name1 = root + "/boot/grub/rootdevice"
233 file_name2 = root + "/boot/grub/device.map"
234 file_name3 = root + "/boot/grub/kernel_name"
235 foundboot = False
236 parts = self._install_profile.get_partition_tables()
237 for device in parts:
238 for partition in parts[device]:
239 mountpoint = parts[device][partition]['mountpoint']
240 if (mountpoint == "/boot"):
241 foundboot = True
242 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
243 boot_minor = str(parts[device][partition]['minor'])
244 grub_boot_minor = str(parts[device][partition]['minor'] - 1)
245 boot_device = device
246 if mountpoint == "/":
247 root_minor = str(parts[device][partition]['minor'])
248 grub_root_minor = str(parts[device][partition]['minor'] - 1)
249 root_device = device
250
251
252 exitstatus0 = GLIUtility.spawn("ls -l " + boot_device + " > " + file_name)
253 exitstatus1 = GLIUtility.spawn("ls -l " + root_device + " > " + file_name1)
254 exitstatus2 = GLIUtility.spawn("echo quit | "+ root+"/sbin/grub --device-map="+file_name2)
255 exitstatus3 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
256 exitstatus4 = GLIUtility.spawn("ls "+root+"/boot/initrd-* >> "+file_name3)
257 if (exitstatus0 != 0) or (exitstatus1 != 0) or (exitstatus2 != 0) or (exitstatus3 != 0) or (exitstatus4 != 0):
258 raise GLIException("BootloaderError", 'fatal', '_install_grub', "Error in one of THE FOUR run commands")
259
260 """
261 read the device map. sample looks like this:
262 (fd0) /dev/floppy/0
263 (hd0) /dev/ide/host2/bus0/target0/lun0/disc
264 (hd1) /dev/ide/host0/bus0/target0/lun0/disc
265 (hd2) /dev/ide/host0/bus0/target1/lun0/disc
266 """
267 e = open(file_name) #Looking for the boot device
268 ls_output = e.readlines()
269 e.close()
270 # looks like lr-xr-xr-x 1 root root 32 Oct 1 16:09 /dev/hda -> ide/host0/bus0/target0/lun0/disc
271 ls_output = ls_output[0].split(">")[-1]
272 ls_output = ls_output[1:]
273
274 eb = open(file_name1) #Looking for the root device
275 ls_outputb = eb.readlines()
276 eb.close()
277 ls_outputb = ls_outputb[0].split(">")[-1]
278 ls_outputb = ls_outputb[1:]
279
280 # Search for the key
281 f = open(file_name2)
282 file = f.readlines()
283 f.close()
284 for i in range(len(file)):
285 if file[i][11:] == ls_output:
286 #eurika we found the drivenum
287 grub_boot_drive = file[i][1:4]
288 if file[i][11:] == ls_outputb:
289 grub_root_drive = file[i][1:4]
290 if (not grub_root_drive) or (not grub_boot_drive):
291 raise GLIException("BootloaderError", 'fatal', '_install_grub',"Couldn't find the drive num in the list from the device.map")
292
293 g = open(file_name3)
294 kernel_name = g.readlines()
295 g.close()
296 if not kernel_name[0]:
297 raise GLIException("BootloaderError", 'fatal', '_install_grub',"Error: We have no kernel in /boot to put in the grub.conf file!")
298 kernel_name = map(string.strip, kernel_name)
299 kernel_name[0] = kernel_name[0].split(root)[1]
300 kernel_name[1] = kernel_name[1].split(root)[1]
301 #-------------------------------------------------------------
302 #OK, now that we have all the info, let's build that grub.conf
303 newgrubconf = ""
304 newgrubconf += "default 0\ntimeout 30\n"
305 if foundboot: #we have a /boot
306 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/grub/splash.xpm.gz\n"
307 else: #we have / and /boot needs to be included
308 newgrubconf += "splashimage=(" + grub_boot_drive + "," + grub_boot_minor + ")/boot/grub/splash.xpm.gz\n"
360 309
310 newgrubconf += "title=Gentoo Linux\n"
311 newgrubconf += "root (" + grub_boot_drive + "," + grub_boot_minor + ")\n"
312 if foundboot:
313 newgrubconf += "kernel " + kernel_name[0][5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
314 newgrubconf += root_device + root_minor + "\n"
315 newgrubconf += "initrd " + kernel_name[1][5:] + "\n"
316 else:
317 newgrubconf += "kernel /boot" + kernel_name[0][5:] + " root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root="
318 newgrubconf += root_device + root_minor + "\n"
319 newgrubconf += "initrd /boot" + kernel_name[1][5:] + "\n"
320
321 #-------------------------------------------------------------
322 #OK, now that the file is built. Install grub.
323 #cp /proc/mounts /etc/mtab
324 #grub-install --root-directory=/boot /dev/hda
325 #shutil.copy("/proc/mounts",root +"/etc/mtab")
326 grubinstallstring = "echo -en 'root ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
327 if not self._install_profile.get_boot_loader_mbr():
328 grubinstallstring +="setup ("+grub_boot_drive + "," + grub_boot_minor + ")\n"
329 else:
330 grubinstallstring +="setup ("+grub_boot_drive+")\n"
331 grubinstallstring += "quit\n' | "+root+"/sbin/grub"
332 #print grubinstallstring
333 exitstatus = GLIUtility.spawn(grubinstallstring,chroot=self._chroot_dir)
334 if exitstatus != 0:
335 raise GLIException("GrubInstallError", 'fatal', '_install_grub', "Could not install grub!")
336
337 #now make the grub.conf file
338 file_name = root + "/boot/grub/grub.conf"
339 try:
340 shutil.move(file_name, file_name + ".OLDdefault")
341 except:
342 pass
343 f = open(file_name, 'w')
344 f.writelines(newgrubconf)
345 f.close()
346
347 def _install_lilo(self):
348 boot_device = ""
349 boot_minor = ""
350 root_device = ""
351 root_minor = ""
352 minornum = 0
353 #Assign root to the root mount point to make lines more readable
354 root = self._chroot_dir
355 file_name3 = root + "/boot/grub/kernel_name"
356 foundboot = False
357 parts = self._install_profile.get_partition_tables()
358 for device in parts:
359 for partition in parts[device]:
360 mountpoint = parts[device][partition]['mountpoint']
361 if (mountpoint == "/boot"):
362 foundboot = True
363 if (( (mountpoint == "/") and (not foundboot) ) or (mountpoint == "/boot")):
364 boot_minor = str(parts[device][partition]['minor'])
365 boot_device = device
366 if mountpoint == "/":
367 root_minor = str(parts[device][partition]['minor'])
368 root_device = device
369 exitstatus0 = GLIUtility.spawn("ls "+root+"/boot/kernel-* > "+file_name3)
370 exitstatus1 = GLIUtility.spawn("ls "+root+"/boot/initrd-* >> "+file_name3)
371 if (exitstatus0 != 0) or (exitstatus1 != 0):
372 raise GLIException("BootloaderError", 'fatal', '_install_lilo', "Error in one of THE TWO run commands")
373 g = open(file_name3)
374 kernel_name = g.readlines()
375 g.close()
376 if not kernel_name[0]:
377 raise GLIException("BootloaderError", 'fatal', '_install_lilo',"Error: We have no kernel in /boot to put in the grub.conf file!")
378 kernel_name = map(string.strip, kernel_name)
379 kernel_name[0] = kernel_name[0].split(root)[1]
380 kernel_name[1] = kernel_name[1].split(root)[1]
381 #-------------------------------------------------------------
382 #time to build the lilo.conf
383 newliloconf = ""
384 if self._install_profile.get_boot_loader_mbr():
385 newliloconf += "boot="+boot_device+" # Install LILO in the MBR \n"
386 else:
387 newliloconf += "boot="+boot_device+boot_minor" # Install LILO in the MBR \n"
388 newliloconf += "prompt # Give the user the chance to select another section\n"
389 newliloconf += "timeout=50 # Wait 5 (five) seconds before booting the default section\n"
390 newliloconf += "default=gentoo # When the timeout has passed, boot the \"gentoo\" section\n"
391 newliloconf += "# Only if you use framebuffer. Otherwise remove the following line:\n"
392 if not self._install_profile.get_kernel_bootsplash():
393 newliloconf += "#"
394 newliloconf += "vga=788 # Framebuffer setting. Adjust to your own will\n"
395 newliloconf += "image=/boot/"+kernel_name[0][5:]+" \n"
396 newliloconf += " label=gentoo \n read-only \n root=/dev/ram0 \n"
397 newliloconf += " append=\"init=/linuxrc ramdisk=8192 real_root="+root_device+root_minor+"\" \n"
398 newliloconf += " initrd=/boot/"+kernel_name[1][5:] + "\n"
399 #now make the lilo.conf file
400 file_name = root + "/etc/lilo.conf"
401 try:
402 shutil.move(file_name, file_name + ".OLDdefault")
403 except:
404 pass
405 f = open(file_name, 'w')
406 f.writelines(newliloconf)
407 f.close()
408 #-------------------------------------------------------------
409 #OK, now that the file is built. Install lilo.
410 exitstatus = GLIUtility.spawn("/sbin/lilo",chroot=self._chroot_dir)
411 if exitstatus != 0:
412 raise GLIException("LiloInstallError", 'fatal', '_install_lilo', "Running lilo failed!")

Legend:
Removed from v.234  
changed lines
  Added in v.235

  ViewVC Help
Powered by ViewVC 1.1.20