/[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 224 Revision 225
1""" 1"""
2Gentoo Linux Installer 2Gentoo Linux Installer
3 3
4$Id: x86ArchitectureTemplate.py,v 1.7 2005/01/07 07:00:13 agaffney Exp $ 4$Id: x86ArchitectureTemplate.py,v 1.8 2005/01/08 09:35:01 agaffney 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"""
10 10
11import GLIUtility, string 11import GLIUtility, string
12from GLIArchitectureTemplate import ArchitectureTemplate 12from GLIArchitectureTemplate import ArchitectureTemplate
13from GLIException import * 13from GLIException import *
14 14import parted
15 15
16class x86ArchitectureTemplate(ArchitectureTemplate): 16class x86ArchitectureTemplate(ArchitectureTemplate):
17 def __init__(self,configuration=None, install_profile=None, client_controller=None): 17 def __init__(self,configuration=None, install_profile=None, client_controller=None):
18 ArchitectureTemplate.__init__(self, configuration, install_profile, client_controller) 18 ArchitectureTemplate.__init__(self, configuration, install_profile, client_controller)
19 self._architecture_name = 'x86' 19 self._architecture_name = 'x86'
20 # self._install_steps = [self.stage1, self.stage2, self.stage3] um, we ain't doin this this way anymore folks.
21 20
22 def install_bootloader(self): 21 def install_bootloader(self):
23 "Installs and configures bootloader" 22 "Installs and configures bootloader"
24 # 23 #
25 # THIS IS ARCHITECTURE DEPENDANT!!! 24 # THIS IS ARCHITECTURE DEPENDANT!!!
178 pass 177 pass
179 f = open(file_name, 'w') 178 f = open(file_name, 'w')
180 f.writelines(newgrubconf) 179 f.writelines(newgrubconf)
181 f.close() 180 f.close()
182 181
183 def _cylinders_to_sectors(self, minor, start, end, sectors_in_cylinder):
184 cylinders = int(end) - int(start) + 1
185 total_sectors = cylinders * int(sectors_in_cylinder)
186 start_sector = int(start) * sectors_in_cylinder
187 end_sector = start_sector + total_sectors - 1
188 if int(minor) == 1 and start_sector == 0: start_sector = 63
189 return (start_sector, end_sector)
190
191 def _sectors_to_megabytes(self, sectors, sector_bytes=512): 182 def _sectors_to_megabytes(self, sectors, sector_bytes=512):
192 return float((float(sectors) * sector_bytes)/ float(1024*1024)) 183 return float((float(sectors) * sector_bytes)/ float(1024*1024))
193 184
194 def _sectors_to_bytes(self, sectors, sector_bytes=512):
195 return (int(sectors) * sector_bytes)
196
197 def _run_parted_command(self, device, cmd):
198 parted_output = commands.getoutput("parted -s " + device + " " + cmd)
199 print "parted -s " + device + " " + cmd
200
201 def _add_partition(self, device, start, end, type, fs): 185 def _add_partition(self, disk, start, end, type, fs):
202 start = self._sectors_to_megabytes(start) 186 types = { 'primary': parted.PARTITION_PRIMARY, 'extended': parted.PARTITION_EXTENDED, 'logical': parted.PARTITION_LOGICAL }
203 end = self._sectors_to_megabytes(end) 187 fsTypes = {}
204 self._run_parted_command(device, "mkpart " + type + " " + fs + " " + str(start) + " " + str(end)) 188 fs_type = parted.file_system_type_get_next ()
205 if type == "ntfs": 189 while fs_type:
206 pass 190 fsTypes[fs_type.name] = fs_type
207 elif type == "ext2" or type == "ext3": 191 fs_type = parted.file_system_type_get_next (fs_type)
208 pass 192 fstype = None
209 else: 193 if fs: fstype = fsTypes[fs]
210 pass 194 newpart = disk.partition_new(types[type], fstype, start, end)
195 constraint = disk.dev.constraint_any()
196 disk.add_partition(newpart, constraint)
211 197
212 def do_partitioning(self): 198 def partition(self):
213 import GLIStorageDevice, parted, pprint 199 import GLIStorageDevice
200 import pprint
214 201
215 devices_old = {} 202 devices_old = {}
216 parts_old = {} 203 parts_old = {}
217 parts_new = self._install_profile.get_partition_tables() 204 parts_new = self._install_profile.get_partition_tables()
218 drives = GLIStorageDevice.detect_devices() 205 drives = GLIStorageDevice.detect_devices()
225 pp = pprint.PrettyPrinter(indent=4) 212 pp = pprint.PrettyPrinter(indent=4)
226 pp.pprint(parts_old) 213 pp.pprint(parts_old)
227 pp.pprint(parts_new) 214 pp.pprint(parts_new)
228 215
229 for dev in parts_old.keys(): 216 for dev in parts_old.keys():
217 if not parts_new.has_key(dev) or not parts_new[dev]:
218 print "Partition table for " + dev + " does not exist in install profile"
219 continue
220 table_changed = 1
221 for part in parts_old[dev]:
222 oldpart = parts_old[dev][part]
223 newpart = parts_new[dev][part]
224 if oldpart['type'] == newpart['type'] and oldpart['start'] == newpart['start'] and oldpart['end'] == newpart['end'] and newpart['format'] == False:
225 table_changed = 0
226 else:
227 table_changed = 1
228 break
229 if not table_changed:
230 print "Partition table for " + dev + " is unchanged"
231 continue
230 parts_active = [] 232 parts_active = []
231 parts_lba = [] 233 parts_lba = []
232 print "\nProcessing " + dev + "..." 234 print "\nProcessing " + dev + "..."
233 parted_dev = parted.PedDevice.get(dev) 235 parted_dev = parted.PedDevice.get(dev)
234 parted_disk = parted.PedDisk.new(parted_dev) 236 parted_disk = parted.PedDisk.new(parted_dev)
235 last_partition_touched = 0
236 sectors_in_cylinder = devices_old[dev]._sectors_in_cylinder
237 # First pass to delete old partitions that aren't resized 237 # First pass to delete old partitions that aren't resized
238 for part in parts_old[dev]: 238 for part in parts_old[dev]:
239 oldpart = parts_old[dev][part] 239 oldpart = parts_old[dev][part]
240 old_start, old_end = self._cylinders_to_sectors(part, oldpart['start'], oldpart['end'], sectors_in_cylinder)
241 matchingminor = 0 240 matchingminor = 0
242 for new_part in parts_new[dev]: 241 for new_part in parts_new[dev]:
243 tmppart = parts_new[dev][new_part] 242 tmppart = parts_new[dev][new_part]
244 new_start, new_end = self._cylinders_to_sectors(new_part, tmppart['start'], tmppart['end'], sectors_in_cylinder)
245 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) == int(oldpart['end']): 243 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) == int(oldpart['end']):
246 matchingminor = new_part 244 matchingminor = new_part
247 print " Deleting old minor " + str(part) + " to be recreated later" 245 print " Deleting old minor " + str(part) + " to be recreated later"
248 self._run_parted_command(dev, "rm " + str(part)) 246 parted_disk.delete_partition(parted_disk.get_partition(part))
249 break 247 break
250 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) != int(oldpart['end']): 248 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) != int(oldpart['end']):
251 matchingminor = new_part 249 matchingminor = new_part
252 print " Ignoring old minor " + str(part) + " to resize later" 250 print " Ignoring old minor " + str(part) + " to resize later"
253 break 251 break
254 if not matchingminor: 252 if not matchingminor:
255 print " No match found...deleting partition " + str(part) 253 print " No match found...deleting partition " + str(part)
256 self._run_parted_command(dev, "rm " + str(part)) 254 # This is broke for logical partitions
255 parted_disk.delete_partition(parted_disk.get_partition(part))
256
257 else: 257 else:
258 if parted_disk.get_partition(part).get_flag(1): # Active/boot 258 if parted_disk.get_partition(part).get_flag(1): # Active/boot
259 print " Partition " + str(part) + " was active...noted" 259 print " Partition " + str(part) + " was active...noted"
260 parts_active.append(int(matchingminor)) 260 parts_active.append(int(matchingminor))
261 if parted_disk.get_partition(part).get_flag(7): # LBA 261 if parted_disk.get_partition(part).get_flag(7): # LBA
262 print " Partition " + str(part) + " was LBA...noted" 262 print " Partition " + str(part) + " was LBA...noted"
263 parts_lba.append(int(matchingminor)) 263 parts_lba.append(int(matchingminor))
264 parted_disk.commit()
264 # Second pass to resize old partitions that need to be resized 265 # Second pass to resize old partitions that need to be resized
265 print " Second pass..." 266 print " Second pass..."
266 for part in parts_old[dev]: 267 for part in parts_old[dev]:
267 oldpart = parts_old[dev][part] 268 oldpart = parts_old[dev][part]
268 old_start, old_end = self._cylinders_to_sectors(part, oldpart['start'], oldpart['end'], sectors_in_cylinder)
269 for new_part in parts_new[dev]: 269 for new_part in parts_new[dev]:
270 tmppart = parts_new[dev][new_part] 270 tmppart = parts_new[dev][new_part]
271 new_start, new_end = self._cylinders_to_sectors(new_part, tmppart['start'], tmppart['end'], sectors_in_cylinder)
272 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) != int(oldpart['end']): 271 if int(tmppart['start']) == int(oldpart['start']) and tmppart['format'] == False and tmppart['type'] == oldpart['type'] and int(tmppart['end']) != int(oldpart['end']):
273 print " Resizing old minor " + str(part) + " from " + str(oldpart['start']) + "-" + str(oldpart['end'])+ " to " + str(tmppart['start']) + "-" + str(tmppart['end']) 272 print " Resizing old minor " + str(part) + " from " + str(oldpart['start']) + "-" + str(oldpart['end'])+ " to " + str(tmppart['start']) + "-" + str(tmppart['end'])
274 type = tmppart['type'] 273 type = tmppart['type']
275 device = dev 274 device = dev
276 minor = part 275 minor = part
277 start = int(new_start) 276 start = int(new_start)
278 end = int(new_end) 277 end = int(new_end)
279 if type == "ext2" or type == "ext3": 278 if type == "ext2" or type == "ext3":
280 total_sectors = end - start + 1 279 total_sectors = end - start + 1
281 commands.getstatus("resize2fs " + device + str(minor) + " " + str(total_sectors) + "s") 280# commands.getstatus("resize2fs " + device + str(minor) + " " + str(total_sectors) + "s")
282 print "resize2fs " + device + str(minor) + " " + str(total_sectors) + "s" 281# print "resize2fs " + device + str(minor) + " " + str(total_sectors) + "s"
283 elif type == "ntfs": 282 elif type == "ntfs":
284 total_sectors = end - start + 1 283 total_sectors = end - start + 1
285 total_bytes = int(self._sectors_to_bytes(total_sectors)) 284 total_bytes = int(total_sectors) * 512)
286 commands.getstatus("ntfsresize --size " + str(total_bytes) + " " + device + str(minor)) 285# commands.getstatus("ntfsresize --size " + str(total_bytes) + " " + device + str(minor))
287 print "ntfsresize --size " + str(total_bytes) + " " + device + str(minor) 286# print "ntfsresize --size " + str(total_bytes) + " " + device + str(minor)
288 else: 287 else:
289 start = float(self._sectors_to_megabytes(start)) 288 start = float(self._sectors_to_megabytes(start))
290 end = float(self._sectors_to_megabytes(end)) 289 end = float(self._sectors_to_megabytes(end))
291 self._run_parted_command(device, "resize " + str(minor) + " " + str(start) + " " + str(end)) 290# self._run_parted_command(device, "resize " + str(minor) + " " + str(start) + " " + str(end))
292 print " Deleting old minor " + str(part) + " to be recreated in 3rd pass" 291 print " Deleting old minor " + str(part) + " to be recreated in 3rd pass"
293 self._run_parted_command(dev, "rm " + str(part)) 292# self._run_parted_command(dev, "rm " + str(part))
293 parted_disk.delete_partition(parted_disk.get_partition(part))
294 break 294 break
295 parted_disk.commit()
295 # Third pass to create new partition table 296 # Third pass to create new partition table
296 print " Third pass..." 297 print " Third pass..."
297 for part in parts_new[dev]: 298 for part in parts_new[dev]:
298 newpart = parts_new[dev][part] 299 newpart = parts_new[dev][part]
299 new_start, new_end = self._cylinders_to_sectors(part, newpart['start'], newpart['end'], sectors_in_cylinder) 300 new_start, new_end = newpart['start'], newpart['end']
300 if newpart['type'] == "extended": 301 if newpart['type'] == "extended":
301 print " Adding extended partition from " + str(newpart['start']) + " to " + str(newpart['end']) 302 print " Adding extended partition from " + str(newpart['start']) + " to " + str(newpart['end'])
302 self._add_partition(dev, new_start, new_end, "extended", "") 303 self._add_partition(parted_disk, new_start, new_end, "extended", "")
303 elif int(part) < 5: 304 elif int(part) < 5:
304 print " Adding primary partition from " + str(newpart['start']) + " to " + str(newpart['end']) 305 print " Adding primary partition from " + str(newpart['start']) + " to " + str(newpart['end'])
305 self._add_partition(dev, new_start, new_end, "primary", newpart['type']) 306 self._add_partition(parted_disk, new_start, new_end, "primary", newpart['type'])
306 elif int(part) > 4: 307 elif int(part) > 4:
307 print " Adding logical partition from " + str(newpart['start']) + " to " + str(newpart['end']) 308 print " Adding logical partition from " + str(newpart['start']) + " to " + str(newpart['end'])
308 self._add_partition(dev, new_start, new_end, "logical", newpart['type']) 309 self._add_partition(parted_disk, new_start, new_end, "logical", newpart['type'])
309 if int(part) in parts_active and not newpart['format']: 310 if int(part) in parts_active and not newpart['format']:
310 print " Partition was previously active...setting" 311 print " Partition was previously active...setting"
311 self._run_parted_command(dev, "set " + str(part) + " boot on") 312 parted_disk.get_partition(part).set_flag(1)
312 if int(part) in parts_lba and not newpart['format']: 313 if int(part) in parts_lba and not newpart['format']:
313 print " Partition was previously LBA...setting" 314 print " Partition was previously LBA...setting"
314 self._run_parted_command(dev, "set " + str(part) + " lba on") 315 parted_disk.get_partition(part).set_flag(7)
316 parted_disk.commit()
317

Legend:
Removed from v.224  
changed lines
  Added in v.225

  ViewVC Help
Powered by ViewVC 1.1.20