- Timestamp:
- Mar 30, 2008, 2:49:43 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-guest-installer/files/usr/sbin/sipb-xen-duplicate
r245 r336 5 5 import shutil 6 6 import tempfile 7 from subprocess import call, check_call, Popen 7 import time 8 from subprocess import call, check_call, Popen, PIPE 8 9 9 10 # TODO: 10 11 # . pick a loop device sanely 11 # -adapt size of partition to fit volume12 # -fix hostname, root password12 # x adapt size of partition to fit volume 13 # . fix hostname, root password 13 14 # - (once debugging diminishes) umount, losetup -d, maybe rm -r 14 15 # - avoid race conditions with other loop-device users, too (somehow) … … 31 32 if loopdevice is not None: 32 33 call(['losetup', '-o', str(offset), loopdevice, source]) 34 else: 35 raise RuntimeError('out of loop devices for copying VM image: too many at once?') 33 36 finally: 34 37 os.unlink(lockfilename) #unlock … … 38 41 39 42 def duplicate_lv(source, dest): 40 ''' duplicate boot record, filesystem from LV source to LV dest43 '''OBSOLETE: duplicate boot record, filesystem from LV source to LV dest 41 44 42 45 source, dest should be device filenames. 46 47 Now we just dd. Doesn't support resizing, but it's easier, 48 especially if we allow the partition table to vary between images. 43 49 ''' 44 50 # XXX this is very specific to what the etch sipb-xen-make-iso installer does. … … 52 58 destfs = losetup(dest, 32256) 53 59 call(['mkfs.ext3', '-b', '4096', destfs, '987989']) 54 tmptree = tempfile.mkdtemp('', 'auto-install.dup.', '/tmp') 60 tmptree = tempfile.mkdtemp('', 'auto-install.dup.', '/tmp')#yes, args backward 55 61 os.mkdir(tmptree+"/source") 56 62 call(['mount', '-t', 'ext3', '-o', 'ro', sourcefs, tmptree+"/source"]) … … 72 78 print 'losetup -d '+destfs 73 79 80 def frob_copy(target, *args): 81 # 1. prepare arguments volume 82 args_volume = prefix+target+'_args' 83 args_device = '/dev/xenvg/' + args_volume 84 check_call(['/sbin/lvcreate', 'xenvg', '--name', args_volume, '--size', '4K']) 85 file(args_device, 'w').write('\n'.join(args) + '\n') 86 87 # 2. invoke frobber vm 88 copier_device = '/dev/xenvg/d_wert_hda' 89 check_call(['/usr/sbin/xm', 'create', 'sipb-database', 90 'machine_name='+target, 91 'disks=' + ' '.join(['phy:'+copier_device+',hda,w', 92 'phy:'+target_device+',hdc,w', 93 'phy:'+args_device+',hdd,w'])]) 94 95 # XXX should check_call(['/sbin/lvremove', '-f', 'xenvg/'+args_volume]) 96 97 def frob_copy_simple(target, hostname, rootpw, *args): 98 """target should be an LV device filename 99 100 This is highly specific to the etch install produced by sipb-xen-make-iso. 101 Generalizing and customizing to other distros is left to the future... 102 """ 103 # 1: mount filesystem 104 fs = losetup(target, 32256) 105 mntdir = tempfile.mkdtemp('', 'auto-install.frob.', '/tmp') 106 call(['mount', '-t', 'ext3', fs, mntdir]) 107 # 2: do frobbing 108 # 2a: (printf "%s\n" "$ROOTPW"; sleep .3; printf "%s\n" "$ROOTPW") 109 # | /usr/sbin/chroot "$TARGET" /usr/bin/passwd root 110 p = Popen(['/usr/sbin/chroot', mntdir, '/usr/bin/passwd', 'root'], stdin=PIPE) 111 p.stdin.write(rootpw+'\n') 112 time.sleep(1) 113 p.stdin.write(rootpw+'\n') 114 p.stdin.close() 115 p.wait() 116 os.chdir(mntdir) 117 # 2b: clear generated file that has eth0's old MAC address 118 # rm $TARGET/etc/udev/rules.d/z25_persistent-net.rules 119 os.unlink('etc/udev/rules.d/z25_persistent-net.rules') 120 # 2c: hostname. 121 # XX Use nullmailer in image, not exim4. (Fewer copies of hostname.) 122 # 2c1: rm /var/lib/dhcp3/dhclient.eth0.leases 123 os.unlink('var/lib/dhcp3/dhclient.eth0.leases') 124 # 2c2: /etc/hosts, /etc/hostname; /etc/motd? /etc/mailname? 125 call(['perl', '-i', '-pe', 's/ice3.servers.csail.mit.edu/'+hostname+'/g', 126 'etc/hosts', 'etc/hostname', 'etc/motd', 'etc/mailname']) 127 # 3: clean up 128 os.chdir('/') 129 call(['umount', mntdir]) 130 call(['losetup', '-d', fs]) 131 74 132 def duplicate_by_vm(source, target, *args): 75 133 # source, target should be machine names … … 78 136 source_device = '/dev/xenvg/' + prefix + source + '_hda' 79 137 target_device = '/dev/xenvg/' + prefix + target + '_hda' 80 #check_call(['/bin/dd', 'bs=1M', 'conv=nocreat', 81 # 'if='+source_device, 'of='+target_device]) 82 # 2. prepare arguments volume 83 args_volume = prefix+target+'_args' 84 args_device = '/dev/xenvg/' + args_volume 85 check_call(['/sbin/lvcreate', 'xenvg', '--name', args_volume, '--size', '4K']) 86 file(args_device, 'w').write('\n'.join(args) + '\n') 87 88 copier_device = '/dev/xenvg/d_wert_hda' 89 check_call(['/usr/sbin/xm', 'create', 'sipb-database', 90 'machine_name='+target, 91 'disks=' + ' '.join(['phy:'+copier_device+',hda,w', 92 'phy:'+target_device+',hdc,w', 93 'phy:'+args_device+',hdd,w'])]) 94 boot = 'c' 95 96 # XXX make this happen! check_call(['/sbin/lvremove', '-f', 'xenvg/'+args_volume]) 97 138 check_call(['/bin/dd', 'bs=1M', 'conv=nocreat', 139 'if='+source_device, 'of='+target_device]) 140 # 2. frob target 141 frob_copy_simple(target_device, *args) 98 142 99 143 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.