/[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 219 Revision 220
1""" 1"""
2Gentoo Linux Installer 2Gentoo Linux Installer
3 3
4$Id: x86ArchitectureTemplate.py,v 1.6 2005/01/07 05:07:23 codeman Exp $ 4$Id: x86ArchitectureTemplate.py,v 1.7 2005/01/07 07:00:13 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"""
177 except: 177 except:
178 pass 178 pass
179 f = open(file_name, 'w') 179 f = open(file_name, 'w')
180 f.writelines(newgrubconf) 180 f.writelines(newgrubconf)
181 f.close() 181 f.close()
182
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):
192 return float((float(sectors) * sector_bytes)/ float(1024*1024))
193
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):
202 start = self._sectors_to_megabytes(start)
203 end = self._sectors_to_megabytes(end)
204 self._run_parted_command(device, "mkpart " + type + " " + fs + " " + str(start) + " " + str(end))
205 if type == "ntfs":
206 pass
207 elif type == "ext2" or type == "ext3":
208 pass
209 else:
210 pass
211
212 def do_partitioning(self):
213 import GLIStorageDevice, parted, pprint
214
215 devices_old = {}
216 parts_old = {}
217 parts_new = self._install_profile.get_partition_tables()
218 drives = GLIStorageDevice.detect_devices()
219 drives.sort()
220 for drive in drives:
221 devices_old[drive] = GLIStorageDevice.Device(drive)
222 devices_old[drive].set_partitions_from_disk()
223 for part in devices_old.keys(): parts_old[part] = devices_old[part].get_install_profile_structure()
224
225 pp = pprint.PrettyPrinter(indent=4)
226 pp.pprint(parts_old)
227 pp.pprint(parts_new)
228
229 for dev in parts_old.keys():
230 parts_active = []
231 parts_lba = []
232 print "\nProcessing " + dev + "..."
233 parted_dev = parted.PedDevice.get(dev)
234 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
238 for part in parts_old[dev]:
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
242 for new_part in parts_new[dev]:
243 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']):
246 matchingminor = new_part
247 print " Deleting old minor " + str(part) + " to be recreated later"
248 self._run_parted_command(dev, "rm " + str(part))
249 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']):
251 matchingminor = new_part
252 print " Ignoring old minor " + str(part) + " to resize later"
253 break
254 if not matchingminor:
255 print " No match found...deleting partition " + str(part)
256 self._run_parted_command(dev, "rm " + str(part))
257 else:
258 if parted_disk.get_partition(part).get_flag(1): # Active/boot
259 print " Partition " + str(part) + " was active...noted"
260 parts_active.append(int(matchingminor))
261 if parted_disk.get_partition(part).get_flag(7): # LBA
262 print " Partition " + str(part) + " was LBA...noted"
263 parts_lba.append(int(matchingminor))
264 # Second pass to resize old partitions that need to be resized
265 print " Second pass..."
266 for part in parts_old[dev]:
267 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]:
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']):
273 print " Resizing old minor " + str(part) + " from " + str(oldpart['start']) + "-" + str(oldpart['end'])+ " to " + str(tmppart['start']) + "-" + str(tmppart['end'])
274 type = tmppart['type']
275 device = dev
276 minor = part
277 start = int(new_start)
278 end = int(new_end)
279 if type == "ext2" or type == "ext3":
280 total_sectors = end - start + 1
281 commands.getstatus("resize2fs " + device + str(minor) + " " + str(total_sectors) + "s")
282 print "resize2fs " + device + str(minor) + " " + str(total_sectors) + "s"
283 elif type == "ntfs":
284 total_sectors = end - start + 1
285 total_bytes = int(self._sectors_to_bytes(total_sectors))
286 commands.getstatus("ntfsresize --size " + str(total_bytes) + " " + device + str(minor))
287 print "ntfsresize --size " + str(total_bytes) + " " + device + str(minor)
288 else:
289 start = float(self._sectors_to_megabytes(start))
290 end = float(self._sectors_to_megabytes(end))
291 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"
293 self._run_parted_command(dev, "rm " + str(part))
294 break
295 # Third pass to create new partition table
296 print " Third pass..."
297 for part in parts_new[dev]:
298 newpart = parts_new[dev][part]
299 new_start, new_end = self._cylinders_to_sectors(part, newpart['start'], newpart['end'], sectors_in_cylinder)
300 if newpart['type'] == "extended":
301 print " Adding extended partition from " + str(newpart['start']) + " to " + str(newpart['end'])
302 self._add_partition(dev, new_start, new_end, "extended", "")
303 elif int(part) < 5:
304 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 elif int(part) > 4:
307 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 if int(part) in parts_active and not newpart['format']:
310 print " Partition was previously active...setting"
311 self._run_parted_command(dev, "set " + str(part) + " boot on")
312 if int(part) in parts_lba and not newpart['format']:
313 print " Partition was previously LBA...setting"
314 self._run_parted_command(dev, "set " + str(part) + " lba on")

Legend:
Removed from v.219  
changed lines
  Added in v.220

  ViewVC Help
Powered by ViewVC 1.1.20