ich mich von diesem Skript (viewtopic.php?f=7&t=250) inspirieren lassen.
Das Problem sind die chroot-Aufrufe. Die funktionieren nicht mit einem 64Bit-System.
Code: Alles auswählen
import os
target = '/mnt/debian'
source = SCRIPT_PATH
tarfile = '/debian64.tar.gz'
# Rootpasswd
execute ("echo root:foobar | chpasswd")
# Get first harddisk
disk = getHarddisks()[0]
ui.getMessageBox().addText( "Verwende Festplatte %s (%s MB).\n" %(disk.device, disk.size) )
# Create new partitiontable
disk.deletePartitionTable()
disk.createPartition(start='0M', end='90%', fs='ext2', boot=True)
disk.createPartition(start='90%', end='100%', fs='linux-swap')
# format partitions
ui.getMessageBox().addText("Erstelle Root-Dateisystem auf %s1\n" % disk.device)
execute("mkfs.ext3 %s1" % disk.device)
ui.getMessageBox().addText("Erstelle Auslagerungspartion auf %s2\n" % disk.device)
execute("mkswap %s2" % disk.device)
execute("swapon %s2" % disk.device)
ui.getMessageBox().addText("Formatierung abgeschlossen\n")
#mount debian
ui.getMessageBox().addText("Mounte %s1\n" % disk.device)
execute ("/bin/mkdir " + target)
execute ("/bin/mount %s1 /mnt/debian" % disk.device)
# unpack tar-image from netmount to local hdd
ui.getMessageBox().addText("kopiere Tar-File\n")
depot.copy(source + tarfile, target)
ui.getMessageBox().addText("entpacke Tar-File\n")
execute ('/bin/tar xzpf ' + target + tarfile + ' -C /mnt/debian')
# startscript
execute ("rm /mnt/debian/root/.bashrc")
depot.copy(source + "/.bashrc", target + "/root")
execute ("chmod +x /mnt/debian/root/.bashrc")
# executes to make devices and install GRUB-Bootloader
execute ("mount -o bind /proc %s/proc" % target)
execute ("mount -o bind /sys %s/sys" % target)
execute ("mount -o bind /dev %s/dev" % target)
ui.getMessageBox().addText("Installiere Bootloader\n")
depot.copy(source + "/grub/*", "/")
execute ("chmod +x /usr/sbin/*")
execute ("chmod +x /usr/bin/*")
execute ("chmod +x /sbin/*")
f = open( os.path.join(target, 'tmp', 'grub.sh'), 'w' )
print >> f, "#/bin/bash"
print >> f, "mount --bind /mnt/debian/boot /boot"
print >> f, "mount --bind /mnt/debian/usr/lib/grub/i386-pc /usr/lib/grub/i386-pc"
# get UUID from sda1
print >> f, "blkid /dev/sda1 > /mnt/debian/tmp/uuid"
print >> f, 'sed "s/\\"//g" /mnt/debian/tmp/uuid > /mnt/debian/tmp/uuid.1'
print >> f, 'sed "s/\\///g" /mnt/debian/tmp/uuid.1 > /mnt/debian/tmp/uuid.2'
print >> f, 'sed "s/devsda1: UUID=//g" /mnt/debian/tmp/uuid.2 > /mnt/debian/tmp/uuid.3'
print >> f, 'sed "s/ TYPE=ext3//g" /mnt/debian/tmp/uuid.3 > /mnt/debian/tmp/uuid.4'
print >> f, "read uuid < /mnt/debian/tmp/uuid.4"
print >> f, "rm /mnt/debian/tmp/u*"
# get UUID from sda2
print >> f, "blkid /dev/sda2 > /mnt/debian/tmp/uuid"
print >> f, 'sed "s/\\"//g" /mnt/debian/tmp/uuid > /mnt/debian/tmp/uuid.1'
print >> f, 'sed "s/\\///g" /mnt/debian/tmp/uuid.1 > /mnt/debian/tmp/uuid.2'
print >> f, 'sed "s/devsda2: UUID=//g" /mnt/debian/tmp/uuid.2 > /mnt/debian/tmp/uuid.3'
print >> f, 'sed "s/ TYPE=swap//g" /mnt/debian/tmp/uuid.3 > /mnt/debian/tmp/uuid.4'
print >> f, "read uuid2 < /mnt/debian/tmp/uuid.4"
print >> f, "rm /mnt/debian/tmp/u*"
# replace UUIDs in grub.cfg and fstab
print >> f, "mv /mnt/debian/boot/grub/grub.cfg /mnt/debian/boot/grub/grub.cfg.1"
print >> f, 'sed "s/03f54e40-bf2a-46e0-925b-95ce8ff0b8eb/$uuid/g" /mnt/debian/boot/grub/grub.cfg.1 > /mnt/debian/boot/grub/grub.cfg'
print >> f, "mv /mnt/debian/etc/fstab /mnt/debian/etc/fstab.1"
print >> f, 'sed "s/72d1c802-2183-455f-b600-5a2a0f51de88/$uuid2/g" /mnt/debian/etc/fstab.1 > /mnt/debian/etc/fstab.2'
print >> f, 'sed "s/03f54e40-bf2a-46e0-925b-95ce8ff0b8eb/$uuid/g" /mnt/debian/etc/fstab.2 > /mnt/debian/etc/fstab'
print >> f, "rm /mnt/debian/boot/grub/grub.cfg.1"
print >> f, "rm /etc/mtab"
print >> f, "rm /etc/fstab"
print >> f, "cp /mnt/debian/etc/mtab /etc"
print >> f, "cp /mnt/debian/etc/fstab /etc"
print >> f, "/usr/sbin/grub-install --recheck --root-directory=/mnt/debian /dev/sda"
f.close()
execute ("chmod +x /mnt/debian/tmp/grub.sh")
execute ("/mnt/debian/tmp/grub.sh")
ui.getMessageBox().addText("Hostname setzen\n")
execute ("hostname > /mnt/debian/etc/hostname")
execute ("mv /mnt/debian/etc/hosts /mnt/debian/etc/hosts.1")
execute ('sed "s/debian/$HOSTNAME/g" /mnt/debian/etc/hosts.1 > /mnt/debian/etc/hosts.2')
execute ("rm /mnt/debian/etc/hosts.1")
execute ("rm /mnt/debian/etc/hosts.2")
execute ("rm /etc/udev/rules.d/70-persistent-net.rules")
os.putenv("LD_PRELOAD", "")
# do hardware inventory
logger.notice(u"Fetching opsi hw audit configuration")
hwconfig = backend.auditHardware_getConfig()
logger.notice(u"Running hardware inventory")
auditHardwareOnHosts = auditHardware(config = hwconfig, hostId = clientId)
logger.notice(u"Sending hardware information to service")
backend.auditHardwareOnHost_setObsolete(clientId)
backend.auditHardwareOnHost_updateObjects(auditHardwareOnHosts)
# send Mail
depotId = backend.getDepotId(fqdn)
depotIp = backend.getDepot_hash(depotId).get("ip", depotId)
depotBackend = JSONRPCBackend(address = depotIp, username = fqdn, password = pckey)
if not os.path.exists(u"/root/.ssh"):
mkdir(u"/root/.ssh", 0700)
f = open(u"/root/.ssh/id_rsa", 'w')
f.write(depotBackend.getPcpatchRSAPrivateKey())
f.close()
os.chmod(u"/root/.ssh/id_rsa", 0600)
f = open(u"/root/.ssh/known_hosts", 'w')
f.write(depotIp + " " + depotBackend.getHostRSAPublicKey())
f.close()
os.chmod(u"/root/.ssh/known_hosts", 0600)
depotBackend.exit()
ui.getMessageBox().addText("E-Mail senden\n")
execute ("hostname > /mnt/debian/tmp/mail")
execute ("echo >> /mnt/debian/tmp/mail")
execute ("ifconfig >> /mnt/debian/tmp/mail")
# copy Mailbody and send Mail
execute("scp -i /root/.ssh/id_rsa /mnt/debian/tmp/mail pcpatch@%s:/tmp/mail" % (depotIp))
execute("ssh -i /root/.ssh/id_rsa pcpatch@%s 'mail -s Opsi_Debian it@domain.tld < /tmp/mail'" % (depotIp))
execute("ssh -i /root/.ssh/id_rsa pcpatch@%s 'rm /tmp/mail'" % (depotIp))
execute("rm /mnt/debian/tmp/mail")
# Umount partition
disk.umountPartition(partition=1)
# Reboot
reboot()
# Debug
#execute ("/etc/init.d/ssh start")
Die beiden Pakete: grub-common_1.98+20100804-14+squeeze1_i386.deb und grub-pc_1.98+20100804-14+squeeze1_i386.deb müssen dazu auf dem Depotserver in das Skriptverzeichnis entpackt werden.
Also nach /opt/pcbin/install/debian_x64/grub. Am einfachsten geht das im Midnight Commander.
Am Ende wird noch eine Mail mit der IP-Adresse geschickt.
Ich hab 4 Tage gebraucht, bis es funktioniert. Vielleicht hilft es jemandem weiter.
Grüße