Changeset 405 for trunk/packages/sipb-xen-guest-installer
- Timestamp:
- Apr 3, 2008, 2:22:54 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-guest-installer/files/usr/sbin/sipb-xen-lvcopy
r343 r405 28 28 os.unlink(lockfilename) #unlock 29 29 return loopdevice 30 # XX this means we can duplicate 9 at once. since it takes around 30 seconds,30 # XX this means we can duplicate 28 at once. Since it takes around 30s, 31 31 # this seems like an adequate capacity. 32 32 33 def duplicate_lv(source, dest): 34 '''OBSOLETE: duplicate boot record, filesystem from LV source to LV dest 35 36 source, dest should be device filenames. 37 38 Now we just dd. Doesn't support resizing, but it's easier, 39 especially if we allow the partition table to vary between images. 40 ''' 41 # XXX this is very specific to what the etch sipb-xen-make-iso installer does. 42 # XXXX also, it's specific to four gigs. 43 # step 1: copy the MBR 44 call(['dd', 'if='+source, 'bs=512', 'count=63', 'of='+dest]) 45 # step 2: fix up partition table 46 # XX actually do this; this is our opportunity to resize the filesystem 47 # step 3: make the filesystem, and copy its contents in 48 sourcefs = losetup(source, 32256) 49 destfs = losetup(dest, 32256) 50 call(['mkfs.ext3', '-b', '4096', destfs, '987989']) 51 tmptree = tempfile.mkdtemp('', 'auto-install.dup.', '/tmp')#yes, args backward 52 os.mkdir(tmptree+"/source") 53 call(['mount', '-t', 'ext3', '-o', 'ro', sourcefs, tmptree+"/source"]) 54 os.mkdir(tmptree+"/dest") 55 call(['mount', '-t', 'ext3', destfs, tmptree+"/dest"]) 56 call(['cp', '-aT', tmptree+"/source", tmptree+"/dest"]) 57 # step 4: twiddle what we want to twiddle 58 # XX do this 59 # step 5: make the swap area 60 swapfs = losetup(dest, 4046870016) 61 call(['mkswap', swapfs, str(240943)]) 62 # call(['losetup', '-d', swapfs]) 63 print 'losetup -d '+swapfs 64 # step 6: clean up. 65 # XX actually unmount etc (leaving it is for debugging) 66 print 'umount '+tmptree+'/source' 67 call(['umount', tmptree+"/dest"]) # needed to flush writes 68 print 'losetup -d '+sourcefs 69 print 'losetup -d '+destfs 70 71 def frob_copy(target, *args): 33 def frob_copy_in_vm(target, *args): 72 34 '''UNUSED: maybe we'll use this someday; it does isolate the frobber.''' 73 35 # 1. prepare arguments volume … … 87 49 # XXX should check_call(['/sbin/lvremove', '-f', 'xenvg/'+args_volume]) 88 50 89 def frob_copy_simple(target, hostname, rootpw): 90 """target should be an LV device filename 91 92 This is highly specific to the etch install produced by sipb-xen-make-iso. 93 Generalizing and customizing to other distros is left to the future... 94 """ 51 def frob_copy(target, hostname, rootpw): 52 """target should be an LV device filename""" 95 53 # 1: mount filesystem 96 54 fs = losetup(target, 32256) … … 98 56 call(['mount', '-t', 'ext3', fs, mntdir]) 99 57 # 2: do frobbing 100 # 2a: (printf "%s\n" "$ROOTPW"; sleep .3; printf "%s\n" "$ROOTPW") 101 # | /usr/sbin/chroot "$TARGET" /usr/bin/passwd root 102 p = Popen(['/usr/sbin/chroot', mntdir, '/usr/bin/passwd', 'root'], stdin=PIPE) 103 p.stdin.write(rootpw+'\n') 104 time.sleep(1) 105 p.stdin.write(rootpw+'\n') 106 p.stdin.close() 107 p.wait() 108 os.chdir(mntdir) 109 # 2b: clear generated file that has eth0's old MAC address 110 # rm $TARGET/etc/udev/rules.d/z25_persistent-net.rules 111 os.unlink('etc/udev/rules.d/z25_persistent-net.rules') 112 # 2c: hostname. 113 # XX Use nullmailer in image, not exim4. (Fewer copies of hostname.) 114 # 2c1: rm /var/lib/dhcp3/dhclient.eth0.leases 115 os.unlink('var/lib/dhcp3/dhclient.eth0.leases') 116 # 2c2: /etc/hosts, /etc/hostname; /etc/motd? /etc/mailname? 117 call(['perl', '-i', '-pe', 's/ice3.servers.csail.mit.edu/'+hostname+'/g', 118 'etc/hosts', 'etc/hostname', 'etc/motd', 'etc/mailname']) 58 call(['/usr/sbin/chroot', mntdir, '/post-copy', hostname, rootpw]) 119 59 # 3: clean up 120 os.chdir('/')121 60 call(['umount', mntdir]) 122 61 os.rmdir(mntdir) 123 62 call(['losetup', '-d', fs]) 124 63 125 def duplicate_by_vm(source, target, rootpw, nodd=False ):64 def duplicate_by_vm(source, target, rootpw, nodd=False, nofrob=False): 126 65 # source, target should be machine names 127 66 prefix = 'd_' … … 133 72 'if='+source_device, 'of='+target_device]) 134 73 # 2. frob target 135 frob_copy_simple(target_device, target, rootpw) 74 if not nofrob: 75 frob_copy(target_device, target, rootpw) 136 76 137 77 def main(*argv): … … 141 81 if subcommand == 'lvcopy': 142 82 kwargs = {} 143 if args[0] == '--nodd': 144 args = args[1:] 145 kwargs['nodd'] = True 83 while True: 84 if args[0].startswith('--'): 85 kwargs[args[0][2:]] = True 86 args = args[1:] 87 continue 88 if len(args) != 3: 89 print >>sys.stderr, argv[0]+': bad argument list' 90 return 2 91 break 146 92 duplicate_by_vm(*args, **kwargs) 93 elif subcommand == 'test': 94 pass 147 95 else: 148 96 print >>sys.stderr, argv[0]+": unknown subcommand: "+subcommand
Note: See TracChangeset
for help on using the changeset viewer.