]> git.siccegge.de Git - forks/vmdebootstrap.git/commitdiff
Merge branch 'codehelp/bugfixes'
authorNeil Williams <codehelp@debian.org>
Thu, 28 Aug 2014 05:49:04 +0000 (22:49 -0700)
committerNeil Williams <codehelp@debian.org>
Thu, 28 Aug 2014 05:50:13 +0000 (22:50 -0700)
NEWS
examples/README.txt [new file with mode: 0644]
examples/auto-serial-console [new file with mode: 0755]
examples/beagleboneblack-customise.sh [new file with mode: 0755]
examples/beagleboneblack.sh [new file with mode: 0755]
examples/cubietruck-customise.sh [new file with mode: 0755]
examples/cubietruck.sh [new file with mode: 0755]
examples/lava.sh [new file with mode: 0755]
examples/vmdebootstrap.txt [new file with mode: 0644]
vmdebootstrap
vmdebootstrap.8.in

diff --git a/NEWS b/NEWS
index e58080141221b5366150d59ab649b32fd447d3c8..c1ac34df6eab60802fa7f91525fc89d383abb75d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,13 @@
 NEWS for vmdebootstrap
 ======================
 
+Version 0.3, unreleased
+-----------------------
+
+* Add example customisation scripts to complement the support
+  for other architectures which need work beyond the scope of
+  available packages.
+
 Version 0.2, released 2013-11-15
 --------------------------------
 
diff --git a/examples/README.txt b/examples/README.txt
new file mode 100644 (file)
index 0000000..a41d83d
--- /dev/null
@@ -0,0 +1,27 @@
+Examples
+========
+
+The Freedombox project are using vmdebootstrap for ARM based images.
+
+http://anonscm.debian.org/cgit/freedombox/freedom-maker.git/
+
+Those scripts have been adapted to work directly within vmdebootstrap
+as customise scripts in this examples directory.
+
+There are also examples which fold all of the options into a single
+script which just needs to be called with a size and an image name.
+
+The only required argument for each example is the image name.
+
+Beaglebone-black
+----------------
+
+sudo ./beagleboneblack.sh --image bbb.img
+
+Arguments other than those already included in the shortcut can also
+be supplied, where required. e.g. --size, --variant, --package (can be
+specified multiple times), --hostname, --sudo, --root-password or
+--lock-root-password.
+
+CubieTruck
+----------
diff --git a/examples/auto-serial-console b/examples/auto-serial-console
new file mode 100755 (executable)
index 0000000..9304e98
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh -e
+
+[ -f /etc/default/autogetty ] && . /etc/default/autogetty
+
+[ 1 -gt $ENABLED ] && exit
+
+for arg in $(cat /proc/cmdline)
+do
+    case $arg in
+        console=*)
+            tty=${arg#console=}
+            tty=${tty#/dev/}
+
+            case $tty in
+                tty[a-zA-Z]* )
+                    PORT=${tty%%,*}
+
+                    # check for service which do something on this port
+                    if [ -f /etc/init/$PORT.conf ];then continue;fi 
+
+                    tmp=${tty##$PORT,}
+                    SPEED=${tmp%%n*}
+                    BITS=${tmp##${SPEED}n}
+
+                    # 8bit serial is default
+                    [ -z $BITS ] && BITS=8
+                    [ 8 -eq $BITS ] && GETTY_ARGS="$GETTY_ARGS -8 "
+
+                    [ -z $SPEED ] && SPEED='115200,57600,38400,19200,9600'
+
+                    GETTY_ARGS="$AUTOGETTY_ARGS $GETTY_ARGS $SPEED $PORT"
+                    exec /sbin/getty $GETTY_ARGS
+            esac
+    esac
+done
diff --git a/examples/beagleboneblack-customise.sh b/examples/beagleboneblack-customise.sh
new file mode 100755 (executable)
index 0000000..2b69069
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+set -e
+
+rootdir=$1
+
+# copy u-boot to the boot partition
+cp $rootdir/usr/lib/u-boot/am335x_boneblack/MLO $rootdir/boot/MLO
+cp $rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img $rootdir/boot/u-boot.img
+
+# Setup uEnv.txt
+kernelVersion=$(basename `dirname $rootdir/usr/lib/*/am335x-boneblack.dtb`)
+version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
+initRd=initrd.img-$version
+vmlinuz=vmlinuz-$version
+
+# uEnv.txt for Beaglebone
+# based on https://github.com/beagleboard/image-builder/blob/master/target/boot/beagleboard.org.txt
+cat >> $rootdir/boot/uEnv.txt <<EOF
+mmcroot=/dev/mmcblk0p2 ro
+mmcrootfstype=ext4 rootwait fixrtc
+
+console=ttyO0,115200n8
+
+kernel_file=$vmlinuz
+initrd_file=$initRd
+
+loadaddr=0x80200000
+initrd_addr=0x81000000
+fdtaddr=0x80F80000
+
+initrd_high=0xffffffff
+fdt_high=0xffffffff
+
+loadkernel=load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
+loadinitrd=load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}; setenv initrd_size \${filesize}
+loadfdt=load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
+
+loadfiles=run loadkernel; run loadinitrd; run loadfdt
+mmcargs=setenv bootargs console=tty0 console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype}
+
+uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
+EOF
+
+mkdir -p $rootdir/boot/dtbs
+cp $rootdir/usr/lib/linux-image-*-armmp/* $rootdir/boot/dtbs
diff --git a/examples/beagleboneblack.sh b/examples/beagleboneblack.sh
new file mode 100755 (executable)
index 0000000..3923949
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+sudo vmdebootstrap \
+ --owner $(whoami) --verbose \
+ --mirror http://http.debian.net/debian \
+ --log beaglebone-black.log --log-level debug \
+ --arch armhf \
+ --foreign /usr/bin/qemu-arm-static \
+ --enable-dhcp \
+ --configure-apt \
+ --no-extlinux \
+ --no-kernel \
+ --package u-boot \
+ --package linux-image-armmp \
+ --distribution sid \
+ --serial-console-command "'/sbin/getty -L ttyO0 115200 vt100'" \
+ --customize "beagleboneblack-customise.sh" \
+ --bootsize 50m --boottype vfat \
+ "$@"
diff --git a/examples/cubietruck-customise.sh b/examples/cubietruck-customise.sh
new file mode 100755 (executable)
index 0000000..74a0d5b
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+set -e
+
+rootdir=$1
+
+# u-boot needs to be dd'd to the partition
+#cp /usr/lib/u-boot/Cubietruck/uboot.elf /boot/
+#cp /usr/lib/u-boot/Cubietruck/u-boot-sunxi-with-spl.bin /boot/
+
+mkdir -p $rootdir/boot/dtbs
+cp $rootdir/usr/lib/linux-image-*-armmp/* $rootdir/boot/dtbs
diff --git a/examples/cubietruck.sh b/examples/cubietruck.sh
new file mode 100755 (executable)
index 0000000..2da46af
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+
+sudo vmdebootstrap \
+ --owner $(whoami) --verbose \
+ --size 3G \
+ --mirror http://http.debian.net/debian \
+ --log cubietruck.log --log-level debug \
+ --arch armhf \
+ --foreign /usr/bin/qemu-arm-static \
+ --enable-dhcp \
+ --configure-apt \
+ --no-extlinux \
+ --no-kernel \
+ --package u-boot \
+ --package linux-image-armmp \
+ --distribution sid \
+ --serial-console-command "/sbin/getty -L ttyS0 115200 vt100" \
+ --customize "cubietruck-customise.sh" \
+ --serial-console-command \
+ --bootsize 50m --boottype vfat \
+ "$@"
diff --git a/examples/lava.sh b/examples/lava.sh
new file mode 100755 (executable)
index 0000000..06da069
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+set -e
+
+rootdir=$1
+
+cp auto-serial-console $rootdir/bin/
diff --git a/examples/vmdebootstrap.txt b/examples/vmdebootstrap.txt
new file mode 100644 (file)
index 0000000..941edc1
--- /dev/null
@@ -0,0 +1,47 @@
+
+# Run vmdebootstrap script to create image
+sudo \
+    vmdebootstrap \
+    --log ../log \
+    --log-level debug \
+    --size 3G \
+    --image $IMAGE.img \
+    --verbose \
+    --mirror $MIRROR \
+    --customize "$basedir/bin/freedombox-customize" \
+    --arch $ARCHITECTURE \
+    --distribution $SUITE \
+    $extra_opts \
+    $pkgopts
+
+Needs u-boot:armhf & linux-image-armmp:armhf in the image.
+
+sudo ./vmdebootstrap --image ../images/test.img \
+ --size 1g --owner $(whoami) --verbose \
+ --mirror http://mirror.bytemark.co.uk/debian \
+ --log ../images/test.log --log-level debug \
+ --arch armhf \
+ --foreign /usr/bin/qemu-arm-static \
+ --no-extlinux \
+ --no-kernel \
+ --package u-boot \
+ --package linux-image-armmp \
+ --distribution sid \
+ --bootsize 20m --boottype vfat
+
+# copy u-boot specific files
+
+# copy auto-serial-console to /bin/
+
+sudo vmdebootstrap \
+  --enable-dhcp \
+  --serial-console --serial-console-command='/bin/auto-serial-console' \
+  --root-password='root' \
+  --verbose \
+  "$@"
+
+sudo vmdebootstrap \
+  --enable-dhcp --no-kernel --package=linux-image-generic \
+  --serial-console --serial-console-command='/bin/auto-serial-console' \
+  --root-password='root' --hostname='ubuntu' --user=user/pass --sudo \
+  --verbose \
index 64614ad8c5f91442a5e71b7579b38ee8e97d3a9b..80089a513c8961c70d74a9e8c9c00457088c3f1d 100755 (executable)
@@ -1,17 +1,17 @@
 #!/usr/bin/python
 # Copyright 2011-2013  Lars Wirzenius
 # Copyright 2012  Codethink Limited
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
@@ -20,6 +20,7 @@ import crypt
 import logging
 import os
 import re
+import time
 import shutil
 import subprocess
 import tempfile
@@ -32,7 +33,9 @@ __version__ = '0.3'
 class VmDebootstrap(cliapp.Application):
 
     def add_settings(self):
-        default_arch = 'amd64'
+        default_arch = self.runcmd(
+            ["dpkg", "--print-architecture"],
+            ignore_fail=False).strip()
 
         self.settings.boolean(['verbose'], 'report what is going on')
         self.settings.string(['image'], 'put created disk image in FILE',
@@ -72,13 +75,13 @@ class VmDebootstrap(cliapp.Application):
         self.settings.string_list(['package'], 'install PACKAGE onto system')
         self.settings.string_list(['custom-package'],
                                   'install package in DEB file onto system '
-                                    '(not from mirror)',
+                                  '(not from mirror)',
                                   metavar='DEB')
         self.settings.boolean(['no-kernel'], 'do not install a linux package')
         self.settings.boolean(['enable-dhcp'], 'enable DHCP on eth0')
         self.settings.string(['root-password'], 'set root password',
                              metavar='PASSWORD')
-        self.settings.boolean(['lock-root-password'], 
+        self.settings.boolean(['lock-root-password'],
                               'lock root account so they cannot login?')
         self.settings.string(['customize'],
                              'run SCRIPT after setting up system',
@@ -90,19 +93,29 @@ class VmDebootstrap(cliapp.Application):
         self.settings.string_list(['user'],
                                   'create USER with PASSWORD',
                                   metavar='USER/PASSWORD')
-        self.settings.boolean(['serial-console'], 
+        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)',
+                             'to /etc/inittab (%default)',
                              metavar='COMMAND',
                              default='/sbin/getty -L ttyS0 115200 vt100')
-        self.settings.boolean(['sudo'], 
+        self.settings.boolean(['sudo'],
                               'install sudo, and if user is created, add them '
-                                'to sudo group')
+                              'to sudo group')
         self.settings.string(['owner'],
                              'the user who will own the image when the build '
-                               'is complete.')
+                             'is complete.')
+        self.settings.boolean(['squash'],
+                              'use squashfs on the final image.')
+        self.settings.boolean(['configure-apt'],
+                              'Create an apt source based on the distribution '
+                              'and mirror selected.')
+        self.settings.boolean(['mbr'],
+                              'Run install-mbr (no longer done by default)')
+        self.settings.boolean(['grub'],
+                              'Install and configure grub2 - disables '
+                              'extlinux.')
 
     def process_args(self, args):
         if not self.settings['image'] and not self.settings['tarball']:
@@ -120,11 +133,13 @@ class VmDebootstrap(cliapp.Application):
             roottype = 'ext4'
             bootdev = None
             boottype = None
+            rootdir = None
             if self.settings['image']:
                 self.create_empty_image()
                 self.partition_image()
-                self.install_mbr()
-                (rootdev,bootdev) = self.setup_kpartx()
+                if self.settings['mbr']:
+                    self.install_mbr()
+                (rootdev, bootdev) = self.setup_kpartx()
                 self.mkfs(rootdev, type=roottype)
                 rootdir = self.mount(rootdev)
                 if bootdev:
@@ -147,11 +162,18 @@ class VmDebootstrap(cliapp.Application):
             self.create_users(rootdir)
             self.remove_udev_persistent_rules(rootdir)
             self.setup_networking(rootdir)
+            if self.settings['configure-apt']:
+                self.configure_apt(rootdir)
             self.customize(rootdir)
             if self.settings['image']:
-                if self.settings['extlinux']:
+                if self.settings['grub']:
+                    self.install_grub2(rootdev, rootdir)
+                elif self.settings['extlinux']:
                     self.install_extlinux(rootdev, rootdir)
+                self.append_serial_console(rootdir)
                 self.optimize_image(rootdir)
+                if self.settings['squash']:
+                    self.squash()
 
             if self.settings['foreign']:
                 os.unlink('%s/usr/bin/%s' %
@@ -164,6 +186,10 @@ class VmDebootstrap(cliapp.Application):
                 self.chown(rootdir)
         except BaseException, e:
             self.message('EEEK! Something bad happened...')
+            if rootdir:
+                db_log = os.path.join(rootdir, 'debootstrap', 'debootstrap.log')
+                if os.path.exists(db_log):
+                    shutil.copy(db_log, os.getcwd())
             self.message(e)
             self.cleanup_system()
             raise
@@ -177,8 +203,8 @@ class VmDebootstrap(cliapp.Application):
 
     def runcmd(self, argv, stdin='', ignore_fail=False, **kwargs):
         logging.debug('runcmd: %s %s' % (argv, kwargs))
-        p = subprocess.Popen(argv, stdin=subprocess.PIPE, 
-                             stdout=subprocess.PIPE, stderr=subprocess.PIPE, 
+        p = subprocess.Popen(argv, stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                              **kwargs)
         out, err = p.communicate(stdin)
         if p.returncode != 0:
@@ -193,13 +219,13 @@ class VmDebootstrap(cliapp.Application):
         self.remove_dirs.append(dirname)
         logging.debug('mkdir %s' % dirname)
         return dirname
-    
+
     def mount(self, device, path=None):
         if not path:
             mount_point = self.mkdtemp()
         else:
             mount_point = path
-        self.message('Mounting %s on %s' % (device,mount_point))
+        self.message('Mounting %s on %s' % (device, mount_point))
         self.runcmd(['mount', device, mount_point])
         self.mount_points.append(mount_point)
         logging.debug('mounted %s on %s' % (device, mount_point))
@@ -207,7 +233,7 @@ class VmDebootstrap(cliapp.Application):
 
     def create_empty_image(self):
         self.message('Creating disk image')
-        self.runcmd(['qemu-img', 'create', '-f', 'raw', 
+        self.runcmd(['qemu-img', 'create', '-f', 'raw',
                      self.settings['image'],
                      str(self.settings['size'])])
 
@@ -216,19 +242,20 @@ class VmDebootstrap(cliapp.Application):
         self.runcmd(['parted', '-s', self.settings['image'],
                      'mklabel', 'msdos'])
         if self.settings['bootsize'] and self.settings['bootsize'] is not '0%':
-            bootsize=str(self.settings['bootsize']/(1024*1024))
+            bootsize = str(self.settings['bootsize'] / (1024 * 1024))
             self.runcmd(['parted', '-s', self.settings['image'],
                          'mkpart', 'primary', 'fat16', '0', bootsize])
         else:
-            bootsize='0%'
+            bootsize = '0%'
         self.runcmd(['parted', '-s', self.settings['image'],
                      'mkpart', 'primary', bootsize, '100%'])
         self.runcmd(['parted', '-s', self.settings['image'],
                      'set', '1', 'boot', 'on'])
 
     def install_mbr(self):
-        self.message('Installing MBR')
-        self.runcmd(['install-mbr', self.settings['image']])
+        if os.path.exists("/sbin/install-mbr"):
+            self.message('Installing MBR')
+            self.runcmd(['install-mbr', self.settings['image']])
 
     def setup_kpartx(self):
         out = self.runcmd(['kpartx', '-avs', self.settings['image']])
@@ -248,12 +275,12 @@ class VmDebootstrap(cliapp.Application):
         root = '/dev/mapper/%s' % devices[rootindex]
         if self.settings['bootsize']:
             boot = '/dev/mapper/%s' % devices[bootindex]
-        return (root,boot)
+        return (root, boot)
 
     def mkfs(self, device, type):
         self.message('Creating filesystem %s' % type)
         self.runcmd(['mkfs', '-t', type, device])
-    
+
     def debootstrap(self, rootdir):
         self.message('Debootstrapping')
 
@@ -262,6 +289,9 @@ class VmDebootstrap(cliapp.Application):
         else:
             necessary_packages = ['acpid']
 
+        if self.settings['grub']:
+            necessary_packages.append('grub2')
+
         include = self.settings['package']
 
         if not self.settings['no-kernel']:
@@ -285,11 +315,13 @@ class VmDebootstrap(cliapp.Application):
             args.append(self.settings['variant'])
         args += [self.settings['distribution'],
                  rootdir, self.settings['mirror']]
+        logging.debug(" ".join(args))
         self.runcmd(args)
         if self.settings['foreign']:
             # First copy the binfmt handler over
             shutil.copy(self.settings['foreign'], '%s/usr/bin/' % rootdir)
             # Next, run the package install scripts etc.
+            self.message('Running debootstrap second stage')
             self.runcmd(['chroot', rootdir,
                          '/debootstrap/debootstrap', '--second-stage'])
 
@@ -297,7 +329,7 @@ class VmDebootstrap(cliapp.Application):
         hostname = self.settings['hostname']
         with open(os.path.join(rootdir, 'etc', 'hostname'), 'w') as f:
             f.write('%s\n' % hostname)
-            
+
         etc_hosts = os.path.join(rootdir, 'etc', 'hosts')
         try:
             with open(etc_hosts, 'r') as f:
@@ -347,8 +379,8 @@ class VmDebootstrap(cliapp.Application):
             self.runcmd_unchecked(['chroot', rootdir, 'dpkg', '-i'] + filenames)
         logging.debug('stdout:\n%s' % out)
         logging.debug('stderr:\n%s' % err)
-        out = self.runcmd(['chroot', rootdir, 
-                     'apt-get', '-f', '--no-remove', 'install'])
+        out = self.runcmd(['chroot', rootdir,
+                          'apt-get', '-f', '--no-remove', 'install'])
         logging.debug('stdout:\n%s' % out)
         shutil.rmtree(tmp)
 
@@ -402,19 +434,50 @@ class VmDebootstrap(cliapp.Application):
 
     def setup_networking(self, rootdir):
         self.message('Setting up networking')
-        
+
         f = open(os.path.join(rootdir, 'etc', 'network', 'interfaces'), 'w')
         f.write('auto lo\n')
         f.write('iface lo inet loopback\n')
-        
+
         if self.settings['enable-dhcp']:
             f.write('\n')
             f.write('auto eth0\n')
             f.write('iface eth0 inet dhcp\n')
-            
+
         f.close()
 
+    def append_serial_console(self, rootdir):
+        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:%s\n' % serial_command)
+
+    def install_grub2(self, rootdev, rootdir):
+        self.message("Configuring grub2")
+        # rely on kpartx using consistent naming to map loop0p1 to loop0
+        install_dev = os.path.join('/dev', os.path.basename(rootdev)[:-2])
+        self.runcmd(['mount', '/dev', '-t', 'devfs', '-obind',
+                    '%s' % os.path.join(rootdir, 'dev')])
+        self.runcmd(['mount', '/proc', '-t', 'proc', '-obind',
+                    '%s' % os.path.join(rootdir, 'proc')])
+        self.runcmd(['mount', '/sys', '-t', 'sysfs', '-obind',
+                    '%s' % os.path.join(rootdir, 'sys')])
+        try:
+            self.runcmd(['chroot', rootdir, 'update-grub'])
+            self.runcmd(['chroot', rootdir, 'grub-install', install_dev])
+        except cliapp.AppException as e:
+            self.message("Failed to configure grub2. Using extlinux.")
+        self.runcmd(['umount', os.path.join(rootdir, 'sys')])
+        self.runcmd(['umount', os.path.join(rootdir, 'proc')])
+        self.runcmd(['umount', os.path.join(rootdir, 'dev')])
+        self.install_extlinux(rootdev, rootdir)
+
     def install_extlinux(self, rootdev, rootdir):
+        if not os.path.exists("/usr/bin/extlinux"):
+            self.message("extlinux not installed, skipping.")
+            return
         self.message('Installing extlinux')
 
         def find(pattern):
@@ -445,25 +508,18 @@ kernel %(kernel)s
 append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
 %(extserial)s
 ''' % {
-    'kernel': kernel_image,
-    'initrd': initrd_image,
-    'uuid': uuid,
-    'kserial': 
-        'console=ttyS0,115200' if self.settings['serial-console'] else '',
-    'extserial': 'serial 0 115200' if self.settings['serial-console'] else '',
-})
+            'kernel': kernel_image,
+            'initrd': initrd_image,
+            'uuid': uuid,
+            'kserial':
+            'console=ttyS0,115200' if self.settings['serial-console'] else '',
+            'extserial': 'serial 0 115200' if self.settings['serial-console'] else '',
+        })
         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:%s\n' % serial_command)
 
         self.runcmd(['extlinux', '--install', rootdir])
         self.runcmd(['sync'])
-        import time; time.sleep(2)
+        time.sleep(2)
 
     def optimize_image(self, rootdir):
         """
@@ -473,13 +529,27 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
         self.runcmd_unchecked(['dd', 'if=/dev/zero', 'of=' + zeros, 'bs=1M'])
         self.runcmd(['rm', '-f', zeros])
 
+    def squash(self):
+        """
+        Run squashfs on the image.
+        """
+        if not os.path.exists('/usr/bin/mksquashfs'):
+            logging.warning("Squash selected but mksquashfs not found!")
+            return
+        self.message("Running mksquashfs")
+        suffixed = "%s.squashfs" % self.settings['image']
+        self.runcmd(['mksquashfs', self.settings['image'],
+                     suffixed,
+                     '-no-progress', '-comp', 'xz'], ignore_fail=False)
+        os.unlink(self.settings['image'])
+        self.settings['image'] = suffixed
 
     def cleanup_system(self):
         # Clean up after any errors.
 
         self.message('Cleaning up')
 
-        # Umount in the reverse mount order 
+        # Umount in the reverse mount order
         if self.settings['image']:
             for i in xrange(len(self.mount_points) - 1, -1, -1):
                 mount_point = self.mount_points[i]
@@ -515,7 +585,20 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s
                          self.settings["owner"],
                          self.settings["image"]])
 
+    def configure_apt(self, rootdir):
+        # use the distribution and mirror to create an apt source
+        self.message("Configuring apt to use distribution and mirror")
+        conf = os.path.join(rootdir, 'etc', 'apt', 'sources.list.d', 'base.list')
+        logging.debug('configure apt %s' % conf)
+        f = open(conf, 'w')
+        f.write('''
+deb %(mirror)s %(distribution)s main
+#deb-src %(mirror)s %(distribution)s main
+''' % {
+            'mirror': self.settings['mirror'],
+            'distribution': self.settings['distribution']
+        })
+        f.close()
 
 if __name__ == '__main__':
     VmDebootstrap(version=__version__).run()
-
index 8eceba12fcab611ee6ff34e4f15498bed7d9e6b2..2c411b7091bcfab43bca8af729486953126385d9 100644 (file)
 .SH NAME
 vmdebootstrap \- install basic Debian system into virtual disk image
 .SH SYNOPSIS
+.B vmdebootstrap
+--image=FILE --size=SIZE [--mirror=URL] [--distribution=NAME]
+.PP
+.B vmdebootstrap
+[--output=FILE] [--verbose | --no-verbose] --image=FILE --size=SIZE
+[--tarball=FILE] [--mirror=URL] [--arch=ARCH] [--distribution=NAME]
+[--package=PACKAGE] [--custom-package=DEB] [--no-kernel]
+[--enable-dhcp | --no-enable-dhcp] [--root-password=PASSWORD]
+[--customize=SCRIPT] [--hostname=HOSTNAME] [--user=USER/PASSWORD]
+[--serial-console | --no-serial-console] [--sudo | --no-sudo] [--owner=OWNER]
+[--bootsize=BOOTSIZE] [--boottype=FSTYPE] [--foreign=PATH] [--variant=VARIANT]
+[--no-extlinux] [--squash] [--configure-apt] [--grub]
 .SH DESCRIPTION
 .B vmdebootstrap
 installs a basic Debian system into a virtual disk image,
@@ -34,7 +46,9 @@ is a wrapper around
 .PP
 You need to run
 .B vmdebootstrap
-as root.
+as root. If the \-\-verbose option is not used, no output will be
+sent to the command line. If the \-\-log option is not used, no
+output will be sent to any log files either.
 .PP
 To use the image,
 you probably want to create a virtual machine using your preferred
@@ -46,19 +60,142 @@ Configure the virtual machine to use the image you've created.
 Then start the virtual machine,
 and log into it via its console to configure it.
 .PP
-The image will be using
+Unless the \-\-no\-extlinux option is specified, the image will use
 .BR extlinux (1)
 as a boot loader.
-It has an empty root password.
-The image will not have networking configured.
-Set the root password before you configure networking.
+The image has an empty root password and will not have networking
+configured by default. Set the root password before you configure
+networking.
 .SH OPTIONS
+.IP \-\-output=FILE
+write output to FILE, instead of standard output
+.IP \-\-verbose
+report what is going on
+.IP \-\-image=FILE
+put created disk image in FILE
+.IP \-\-size=SIZE
+create a disk image of size SIZE (1000000000)
+.IP \-\-tarball=FILE
+tar up the disk's contents in FILE
+.IP \-\-mirror=URL
+use MIRROR as package source (http://cdn.debian.net/debian/)
+.IP \-\-arch=ARCH
+architecture to use (amd64)
+.IP \-\-distribution=NAME
+release to use (stable)
+.IP \-\-package=PACKAGE
+install PACKAGE onto system
+.IP \-\-custom-package=DEB
+install package in DEB file onto system (not from mirror)
+.IP \-\-no-kernel
+do not install a linux package
+.IP \-\-enable-dhcp
+enable DHCP on eth0
+.IP \-\-root-password=PASSWORD
+set root password
+.IP \-\-customize=SCRIPT
+run SCRIPT after setting up system
+.IP \-\-hostname=HOSTNAME
+set name to HOSTNAME (debian)
+.IP \-\-user=USER/PASSWORD
+create USER with PASSWORD
+.IP \-\-owner=OWNER
+change the owner of the final image from root to the specified user.
+.IP \-\-serial\-console
+configure image to use a serial console
+.IP \-\-serial-console-command
+set the command to manage the serial console which will be appended to
+/etc/inittab. Default is "/sbin/getty -L ttyS0 115200 vt100", resulting in a line
+.BR "S0:23:respawn:/sbin/getty -L ttyS0 115200 vt100"
+.IP \-\-sudo
+install sudo, and if user is created, add them to sudo group
+.IP \-\-bootsize=BOOTSIZE
+If specified, create a /boot partition of the given size within the image. Debootstrapping will fail if this is too small for the selected kernel package.
+.IP \-\-boottype=FSTYPE
+Filesystem to use for the /boot partition. (default ext2)
+.IP \-\-foreign=PATH
+Path to the binfmt_handler to enable foreign support in debootstrap. e.g. /usr/bin/qemu-arm-static - note foreign debootstraps may take a signficant amount of time to complete and that debootstrap will retry five times if packages fail to install by default.
+.IP \-\-no\-extlinux
+Skip installation of extlinux. needs a customize script to make the image bootable. Useful for architectures where extlinux is not supportable.
+.IP \-\-squash
+Run mksquashfs against the final image using xz compression - requires
+squashfs-tools to be installed. The final file will have the .squashfs suffix. 
+By default, mksquashfs is allowed to use all processors which may result
+in high load. Run mksquashfs separately if you need to control the number
+of processors used per run.
+.IP \-\-configure\-apt
+Use the specified mirror and distribution to create a suitable apt source inside
+the VM. Can be useful if debootstrap fails to create it automatically.
+.IP \-\-grub
+Disable extlinux installation and configure grub2 instead. grub2 will be added to
+the list of packages to install. update-grub will be called once the debootstrap is
+complete and grub-install will be called in the image. Versions of grub2 in wheezy
+can fail to install in the VM, at which point vmdebootstrap will fall back to
+extlinux. It may still be possible to complete the installation of grub2 after
+booting the VM as the problem may be related to the need to use loopback
+devices during the grub-install operation. Details of the error will appear in the
+vmdebootstrap log file, if enabled with the \-\-log option.
+.SH Configuration files and settings:
+.IP \-\-dump-config
+write out the entire current configuration
+.IP \-\-no-default-configs
+clear list of configuration files to read
+.IP \-\-config=FILE
+add FILE to config files
+.SH Logging:
+.IP \-\-log=FILE
+write log entries to FILE (default is to not write log files at all);
+use "syslog" to log to system log, or "none" to disable logging
+.IP \-\-log-level=LEVEL
+log at LEVEL, one of debug, info, warning, error, critical, fatal (default: debug)
+.IP \-\-log-max=SIZE
+rotate logs larger than SIZE, zero for never (default: 0)
+.IP \-\-log-keep=N
+keep last N logs (10)
+.IP \-\-log-mode=MODE
+set permissions of new log files to MODE (octal;  default 0600)
+.SH Peformance:
+.IP \-\-dump-memory-profile=METHOD
+make memory profiling dumps using METHOD, which is one of:
+none, simple, meliae, or heapy (default: simple)
+.IP \-\-memory-dump-interval=SECONDS
+make memory profiling dumps at least SECONDS apart
 .SH EXAMPLE
 To create an image for the stable release of Debian:
 .nf
 .IP
-sudo ./vmdebootstrap --image test.img --size 1g \\
+sudo vmdebootstrap --image test.img --size 1g \\
     --log test.log --log-level debug --verbose \\
     --mirror http://mirror.lan/debian/
+.PP
+To run the test image, make sure it is writeable. Use the \-\-owner option to set mode 0644 for the specified user or use chmod manually:
+.IP
+sudo chmod a+w ./test.img
+.PP
+Execute using qemu, e.g. on amd64 using qemu-system-x86_64:
+.IP
+qemu-system-x86_64 ./test.img
+.PP
+(This loads the image in a new window.)
+.PP
+For further examples, including u-boot support for beaglebone-black, see /usr/share/vmdebootstrap/examples
+.SH NOTES
+If you get problems with the bootstrap process, run a similar bootstrap call directly and chroot into the directory to investigate the failure. The actual debootstrap call is part of the vmdebootstrap logfile. The debootstrap logfile, if any, will be copied into your current working directory on error.
+.PP
+.B debootstrap
+will download all the apt archive files into the apt cache and does not remove them before starting the configuration of the packages. This can mean that debootstrap can fail due to a lack of space on the device if the VM size is small. vmdebootstrap cleans up the apt cache once debootstrap has finished but this doesn't help if the package unpack or configuration steps use up all of the space in the meantime. Avoid this problem by specifying a larger size for the image.
+.PP
+Note that if you are also using a separate /boot partition in your options to vmdebootstrap, it may well be the boot partition which needs to be enlarged rather than the entire image.
+.PP
+It is advisable to change the mirror in the example scripts to a mirror closer to your location,
+particularly if you need to do repeated builds.
+.PP
 .SH "SEE ALSO"
-.BR debootstrap (8).
+.BR debootstrap (8)
+,
+.BR qemu-system-x86_64 (1)
+,
+.BR grub-install (8)
+.
+.SH BUGS
+Please provide the config section of the logfile when reporting bugs, as well as the complete command line.