]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
Release version 0.1.0
[forks/vmdebootstrap.git] / vmdebootstrap
index ecb6df82e8d0764599a66d1ef2d5d88b5ecf34d8..a5537b7abd6f6191ddc2cf8704470db9082184f5 100755 (executable)
@@ -25,6 +25,9 @@ import subprocess
 import tempfile
 
 
+__version__ = '0.1.0'
+
+
 class VmDebootstrap(cliapp.Application):
 
     def add_settings(self):
@@ -73,6 +76,11 @@ class VmDebootstrap(cliapp.Application):
                                   metavar='USER/PASSWORD')
         self.settings.boolean(['serial-console'], 
                               'configure image to use a serial console')
+        self.settings.string(['serial-console-command'],
+                             'command to manage the serial console, appended '
+                               'to /etc/inittab (%default)',
+                             metavar='COMMAND',
+                             default='/sbin/getty -L ttyS0 115200 vt100')
         self.settings.boolean(['sudo'], 
                               'install sudo, and if user is created, add them '
                                 'to sudo group')
@@ -102,6 +110,7 @@ class VmDebootstrap(cliapp.Application):
             self.set_hostname(rootdir)
             self.create_fstab(rootdir)
             self.install_debs(rootdir)
+            self.cleanup_apt_cache(rootdir)
             self.set_root_password(rootdir)
             self.create_users(rootdir)
             self.remove_udev_persistent_rules(rootdir)
@@ -109,6 +118,7 @@ class VmDebootstrap(cliapp.Application):
             self.customize(rootdir)
             if self.settings['image']:
                 self.install_extlinux(rootdev, rootdir)
+                self.optimize_image(rootdir)
             if self.settings['tarball']:
                 self.create_tarball(rootdir)
         except BaseException, e:
@@ -191,10 +201,10 @@ class VmDebootstrap(cliapp.Application):
 
         if not self.settings['no-kernel']:
             if self.settings['arch'] == 'i386':
-                kernel_arch = '686'
+                kernel_arch = '486'
             else:
                 kernel_arch = self.settings['arch']
-            kernel_image = 'linux-image-2.6-%s' % kernel_arch
+            kernel_image = 'linux-image-%s' % kernel_arch
             include.append(kernel_image)
 
         if self.settings['sudo'] and 'sudo' not in include:
@@ -246,6 +256,10 @@ class VmDebootstrap(cliapp.Application):
         logging.debug('stdout:\n%s' % out)
         shutil.rmtree(tmp)
 
+    def cleanup_apt_cache(self, rootdir):
+        out = self.runcmd(['chroot', rootdir, 'apt-get', 'clean'])
+        logging.debug('stdout:\n%s' % out)
+
     def set_root_password(self, rootdir):
         if self.settings['root-password']:
             self.message('Setting root password')
@@ -299,7 +313,7 @@ class VmDebootstrap(cliapp.Application):
         
         if self.settings['enable-dhcp']:
             f.write('\n')
-            f.write('allow-hotplug eth0\n')
+            f.write('auto eth0\n')
             f.write('iface eth0 inet dhcp\n')
             
         f.close()
@@ -345,15 +359,25 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         f.close()
         
         if self.settings['serial-console']:
+            serial_command = self.settings['serial-console-command']
             logging.debug('adding getty to serial console')
             inittab = os.path.join(rootdir, 'etc/inittab')
             with open(inittab, 'a') as f:
-                f.write('\nS0:23:respawn:/sbin/getty -L ttyS0 115200 vt100\n')
+                f.write('\nS0:23:respawn:%s\n' % serial_command)
 
         self.runcmd(['extlinux', '--install', rootdir])
         self.runcmd(['sync'])
         import time; time.sleep(2)
-        
+
+    def optimize_image(self, rootdir):
+        """
+        Filing up the image with zeros will increase its compression rate
+        """
+        zeros = os.path.join(rootdir, 'ZEROS')
+        self.runcmd_unchecked(['dd', 'if=/dev/zero', 'of=' + zeros, 'bs=1M'])
+        self.runcmd(['rm', '-f', zeros])
+
+
     def cleanup_system(self):
         # Clean up after any errors.
 
@@ -383,5 +407,5 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
 
 
 if __name__ == '__main__':
-    VmDebootstrap().run()
+    VmDebootstrap(version=__version__).run()