]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
Fix typo in README
[forks/vmdebootstrap.git] / vmdebootstrap
index 19eaecb752567904618f010e4785cfd72adb614e..a9f9e9bf4c2b87e6886f7c170dfca3dc3ed93b1d 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-# Copyright 2011, 2012  Lars Wirzenius
+# Copyright 2011-2013  Lars Wirzenius
 # Copyright 2012  Codethink Limited
 # 
 # This program is free software: you can redistribute it and/or modify
@@ -23,9 +23,10 @@ import re
 import shutil
 import subprocess
 import tempfile
+import time
 
 
-__version__ = '0.1.0'
+__version__ = '0.2'
 
 
 class VmDebootstrap(cliapp.Application):
@@ -51,7 +52,10 @@ class VmDebootstrap(cliapp.Application):
                              'set up foreign debootstrap environment using provided program (ie binfmt handler)')
         self.settings.string(['variant'],
                              'select debootstrap variant it not using the default')
-        self.settings.boolean(['no-extlinux'], 'do not install extlinux')
+        self.settings.boolean(
+            ['extlinux'],
+            'install extlinux?',
+            default=True)
         self.settings.string(['tarball'], "tar up the disk's contents in FILE",
                              metavar='FILE')
         self.settings.string(['mirror'],
@@ -109,7 +113,10 @@ class VmDebootstrap(cliapp.Application):
         self.mount_points = []
 
         try:
+            rootdev = None
             roottype = 'ext4'
+            bootdev = None
+            boottype = None
             if self.settings['image']:
                 self.create_empty_image()
                 self.partition_image()
@@ -139,7 +146,7 @@ class VmDebootstrap(cliapp.Application):
             self.setup_networking(rootdir)
             self.customize(rootdir)
             if self.settings['image']:
-                if not self.settings['no-extlinux']:
+                if self.settings['extlinux']:
                     self.install_extlinux(rootdev, rootdir)
                 self.optimize_image(rootdir)
 
@@ -217,7 +224,7 @@ class VmDebootstrap(cliapp.Application):
         self.runcmd(['install-mbr', self.settings['image']])
 
     def setup_kpartx(self):
-        out = self.runcmd(['kpartx', '-av', self.settings['image']])
+        out = self.runcmd(['kpartx', '-avs', self.settings['image']])
         if self.settings['bootsize']:
             bootindex = 0
             rootindex = 1
@@ -285,13 +292,16 @@ class VmDebootstrap(cliapp.Application):
             f.write('%s\n' % hostname)
             
         etc_hosts = os.path.join(rootdir, 'etc', 'hosts')
-        with open(etc_hosts, 'r') as f:
-            data = f.read()
-        with open(etc_hosts, 'w') as f:
-            for line in data.splitlines():
-                if line.startswith('127.0.0.1'):
-                    line += ' %s' % hostname
-                f.write('%s\n' % line)
+        try:
+            with open(etc_hosts, 'r') as f:
+                data = f.read()
+            with open(etc_hosts, 'w') as f:
+                for line in data.splitlines():
+                    if line.startswith('127.0.0.1'):
+                        line += ' %s' % hostname
+                    f.write('%s\n' % line)
+        except IOError, e:
+            pass
 
     def create_fstab(self, rootdir, rootdev, roottype, bootdev, boottype):
         def fsuuid(device):
@@ -466,10 +476,15 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         if self.settings['image']:
             for i in xrange(len(self.mount_points) - 1, -1, -1):
                 mount_point = self.mount_points[i]
-                self.runcmd(['umount', mount_point], ignore_fail=True)
+                try:
+                    self.runcmd(['umount', mount_point], ignore_fail=False)
+                except cliapp.AppException:
+                    logging.debug("umount failed, sleeping and trying again")
+                    time.sleep(5)
+                    self.runcmd(['umount', mount_point], ignore_fail=False)
 
             self.runcmd(['kpartx', '-d', self.settings['image']], ignore_fail=True)
-        
+
         for dirname in self.remove_dirs:
             shutil.rmtree(dirname)