Re: Partitionen formatieren
Verfasst: 20 Aug 2008, 10:23
Nein, sollte funktionieren...
Code: Alles auswählen
disk.createFilesystem(partition=2, fs="ntfs")
Ja.major0190 hat geschrieben:Hallo,
d.h. inzwischen funktioniert auch diese Zeile mit Quickformat und ich kann meine damit wieder ersetzen?
vg, Thomas Freier
Code: Alles auswählen
target = '/mnt/hd'
source = DEPOT_MOUNT + '/install/winxppro'
hwFilename = DEPOT_MOUNT + "/pcpatch/pclog/" + hostname + ".hw"
srcDriversDir = DEPOT_MOUNT + '/install/winxppro/drivers'
# Do hardware inventory
hardware = hardwareInventory(filename = hwFilename)
###################################################################################
### Modifikation
###################################################################################
# Get first harddisk
KB=1000
MB=1000*1000
GB=1000*1000*1000
disks = getHarddisks()
disk = disks[0]
disksize = disk.size - KB
partitions = disk.getPartitions()
# Disksize <= 2GB
# => Platte zu klein => exit
if (disksize <= 2*GB):
raise Exception("Die Festplatte ist kleiner als 2GB!\n")
# 2GB < Disksize <= 6GB
# => erstelle 1 Partition ueber die gesamte Platte elif (2*GB < disksize) and (disksize <= 6*GB):
if not partitions:
ui.getMessageBox().addText("Es wird eine Partition ueber die gesamte Platte erstellt!\n")
disk.deletePartitionTable()
disk.createPartition(start="0%", end="100%", fs="fat32", boot=True)
disk.createFilesystem(partition=1, fs="fat32")
else:
partition = partitions[0]
partend = str(int((partition['end'] / (1024*1024)) - 1)) + "M"
ui.getMessageBox().addText('Ende Partition 1: %s\n' % (partend))
ui.getMessageBox().addText("Partition 1 wird neu erstellt\n")
disk.deletePartition(partition=1)
disk.createPartition(start="0%", end=partend, fs="fat32", boot=True)
disk.createFilesystem(partition=1, fs="fat32")
# 6GB < Disksize <= 15GB
# => 2 Partitionen: 1. 6GB, 2. Rest
elif (6*GB < disksize) and (disksize <= 15*GB):
if not partitions:
ui.getMessageBox().addText("Es werden zwei Partition erstellt!\n1. Partition: 6GB, 2. Partition: Rest\n")
disk.deletePartitionTable()
disk.createPartition(start="0M", end="6000M", fs="fat32", boot=True)
disk.createFilesystem(partition=1, fs="fat32")
disk.createPartition(start="6001M", end="100%", fs="ntfs", boot=False)
else:
partition = partitions[0]
partend = str(int((partition['end'] / (1024*1024)) - 1)) + "M"
ui.getMessageBox().addText('Ende Partition 1: %s\n' % (partend))
ui.getMessageBox().addText("Partition 1 wird neu erstellt\n")
disk.deletePartition(partition=1)
disk.createPartition(start="0%", end=partend, fs="fat32", boot=True)
disk.createFilesystem(partition=1, fs="fat32")
# Disksize > 15GB
# 2 Partitionen: 1. 40%, 2. 60%
else:
if not partitions:
ui.getMessageBox().addText("Es werden zwei Partition erstellt!\n1. Partition: 40%, 2. Partition: 60%\n")
disk.deletePartitionTable()
disk.createPartition(start="0%", end="40%", fs="fat32", boot=True)
disk.createFilesystem(partition=1, fs="fat32")
disk.createPartition(start="41%", end="100%", fs="ntfs")
disk.createFilesystem(partition=2, fs="fat32")
else:
partition = partitions[0]
partend = str(int((partition['end'] / (1024*1024)) - 1)) + "M"
disk.deletePartitionTable()
ui.getMessageBox().addText('Ende Partition 1: %s\n' % (partend))
ui.getMessageBox().addText("Partition 1 wird neu erstellt\n")
ui.getMessageBox().addText("\nSchritt 2: Erstelle neue Partition\n")
disk.createPartition(start="0%", end="40%", fs="fat32", boot=True)
ui.getMessageBox().addText("\nSchritt 3: Formatiere Partition\n")
disk.createFilesystem(partition=1, fs="fat32")
ui.getMessageBox().addText("\nSchritt 5: Erstelle neue Partition\n")
disk.createPartition(start="41%", end="100%", fs="fat32")
ui.getMessageBox().addText("\nSchritt 5: Formatiere Partition\n")
disk.createFilesystem(partition=2, fs="fat32")
###################################################################################
### Modifikation ende
###################################################################################
# Write Master Boot Record
disk.writeMasterBootRecord(system='mbrdos')
# Write Partition Boot Record
disk.writePartitionBootRecord(partition=1, fsType='fat32nt')
# Mount partition 1
disk.mountPartition(partition=1, mountpoint=target)
# Copy Windows installation files
copy(source + '/i386', target + '/$win_nt$.~ls/')
copy(target + '/$win_nt$.~ls/i386/*', target + '/$win_nt$.~bt/')
copy(target + '/$win_nt$.~ls/i386/ntldr', target)
copy(target + '/$win_nt$.~ls/i386/ntdetect.com', target)
copy(target + '/$win_nt$.~ls/i386/txtsetup.sif', target)
copy(target + '/$win_nt$.~ls/i386/bootfont.bin', target)
copy(target + '/$win_nt$.~ls/i386/setupldr.bin', target + '/$ldr$')
# Copy OEM files
copy(source + '/opsi/$oem$/*', target + '/$/')
copy(source + '/opsi/$oem$/unattend/unattend.txt', target + '/$win_nt$.~bt/winnt.sif')
# Copy opsi-preloginloader
copy(DEPOT_MOUNT + '/install/preloginloader/files/*', target)
# Copy sysconf.ini to C:\opsi\cfg
copy (SYSCONF_INI , target + '/opsi/cfg')
# Integrate drivers
if os.path.exists(srcDriversDir):
ui.getMessageBox().addText("Treiber-Verzeichnis gefunden, versuche Treiber einbzubinden.\n")
oemPnpDriversPath = ''
driverNumber = 0
for (key, info) in hardware.items():
name = info.get('name', '???')
name = name.replace('/', '_')
vendorId = info.get('vendorId', '').upper()
deviceId = info.get('deviceId', '').upper()
if not vendorId or not deviceId:
continue
logger.info("Searching driver for device '%s', id '%s:%s'" % (name, vendorId, deviceId))
ui.getMessageBox().addText(" * Suche Treiber fuer '%s'.\n" % name)
srcDriverPath = os.path.join(srcDriversDir, 'pciids', vendorId)
if not os.path.exists(srcDriverPath):
logger.error("Vendor directory '%s' not found" % srcDriverPath)
ui.getMessageBox().addText(" [Fehler] Hersteller-Verzeichnis '%s' nicht gefunden.\n" % vendorId)
continue
srcDriverPath = os.path.join(srcDriverPath, deviceId)
if not os.path.exists(srcDriverPath):
logger.error("Device directory '%s' not found" % srcDriverPath)
ui.getMessageBox().addText(" [Fehler] Geraete-Verzeichnis '%s' nicht gefunden.\n" % deviceId)
continue
logger.notice("Found driver for device '%s', in dir '%s'" % (name, srcDriverPath))
ui.getMessageBox().addText(" [OK] Treiber gefunden, wird eingebunden.\n")
driverNumber += 1
if not os.path.exists( os.path.join(target, 'drv') ):
os.mkdir( os.path.join(target, 'drv') )
if not os.path.exists( os.path.join(target, 'drv', str(driverNumber)) ):
os.mkdir( os.path.join(target, 'drv', str(driverNumber)) )
copy( srcDriverPath + '/*', os.path.join(target, 'drv', str(driverNumber)) )
if oemPnpDriversPath:
oemPnpDriversPath += ';'
oemPnpDriversPath += '\\'.join(['drv', str(driverNumber)])
pi = open(PATCHA_IN, 'a')
print >> pi, "oempnpdriverspath=%s" % oemPnpDriversPath
pi.close()
# Create bootsect.dat
execute("dd if=%s1 of='%s/$win_nt$.~bt/bootsect.dat' bs=512 count=1" % (disk.device, target))
import posix
f = posix.open(target + '/$win_nt$.~bt/bootsect.dat', posix.O_WRONLY)
# replace NTLDR by $LDR$
posix.lseek(f, 0x170, 0)
posix.write( f, chr(0x24) + chr(0x4c) + chr(0x44) + chr(0x52) + chr(0x24) )
posix.close(f)
# Patch unattended.txt
for i in ( target + '/$win_nt$.~bt/winnt.sif', target + '/opsi/cfg/pxecfg.ini' ):
execute("/usr/local/bin/patcha '%s'" % i)
execute("/usr/local/bin/patcha -f %s '%s'" % (PATCHA_IN, i))
# boot ini
f = open(target + '/boot.ini', 'w')
print >> f, '[Boot Loader]'
print >> f, 'Timeout=1'
print >> f, 'Default=C:\$WIN_NT$.~BT\BOOTSECT.DAT'
print >> f, '[Operating Systems]'
print >> f, 'C:\$WIN_NT$.~BT\BOOTSECT.DAT = "OPSI Windows Installation"'
f.close()
# Umount harddisk
disk.umountPartition(partition=1)
# Reboot
reboot()