Changeset 405


Ignore:
Timestamp:
Apr 3, 2008, 2:22:54 AM (17 years ago)
Author:
price
Message:

put the post-copy frobbing details in the image

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/sipb-xen-guest-installer/files/usr/sbin/sipb-xen-lvcopy

    r343 r405  
    2828    os.unlink(lockfilename) #unlock
    2929  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,
    3131  # this seems like an adequate capacity.
    3232
    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):
     33def frob_copy_in_vm(target, *args):
    7234  '''UNUSED: maybe we'll use this someday; it does isolate the frobber.'''
    7335  # 1. prepare arguments volume
     
    8749  # XXX should check_call(['/sbin/lvremove', '-f', 'xenvg/'+args_volume])
    8850
    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   """
     51def frob_copy(target, hostname, rootpw):
     52  """target should be an LV device filename"""
    9553  # 1: mount filesystem
    9654  fs = losetup(target, 32256)
     
    9856  call(['mount', '-t', 'ext3', fs, mntdir])
    9957  # 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])
    11959  # 3: clean up
    120   os.chdir('/')
    12160  call(['umount', mntdir])
    12261  os.rmdir(mntdir)
    12362  call(['losetup', '-d', fs])
    12463
    125 def duplicate_by_vm(source, target, rootpw, nodd=False):
     64def duplicate_by_vm(source, target, rootpw, nodd=False, nofrob=False):
    12665  # source, target should be machine names
    12766  prefix = 'd_'
     
    13372                'if='+source_device, 'of='+target_device])
    13473  # 2. frob target
    135   frob_copy_simple(target_device, target, rootpw)
     74  if not nofrob:
     75    frob_copy(target_device, target, rootpw)
    13676
    13777def main(*argv):
     
    14181  if subcommand == 'lvcopy':
    14282    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
    14692    duplicate_by_vm(*args, **kwargs)
     93  elif subcommand == 'test':
     94    pass
    14795  else:
    14896    print >>sys.stderr, argv[0]+": unknown subcommand: "+subcommand
Note: See TracChangeset for help on using the changeset viewer.