Add an example about how to run hooks
[ext/instance-debootstrap.git] / create
diff --git a/create b/create
index 072905c..442667c 100755 (executable)
--- a/create
+++ b/create
 
 set -e
 
+# minimum device size is 256 MB, but we use 255 to account for
+# potential rounding
+declare -ri MIN_DEV_SIZE=$((255*1048576))
+
 . common.sh
 
 if [ "$GENERATE_CACHE" = "yes" -a ! -d "$CACHE_DIR" ]; then
@@ -36,6 +40,13 @@ if [ ! -b $blockdev ]; then
   CLEANUP+=("losetup -d $blockdev")
 fi
 
+DEVICE_SIZE=$(blockdev --getsize64 $blockdev)
+if [ "$DEVICE_SIZE" -lt $MIN_DEV_SIZE ]; then
+  echo "Device size is too small ($((DEVICE_SIZE/1048576)) MB)" 1>&2
+  echo "Required size is at least 256MB" 1>&2
+  exit 1
+fi
+
 if [ "$PARTITION_STYLE" = "none" ]; then
   filesystem_dev=$blockdev
 elif [ "$PARTITION_STYLE" = "msdos" ]; then
@@ -44,11 +55,11 @@ elif [ "$PARTITION_STYLE" = "msdos" ]; then
   filesystem_dev=$(map_disk0 $blockdev)
   CLEANUP+=("unmap_disk0 $blockdev")
 else
-  echo "Unknown partition style $PARTITION_STYLE"
+  echo "Unknown partition style $PARTITION_STYLE" 1>&2
   exit 1
 fi
 
-mke2fs -Fjq $filesystem_dev
+mke2fs -Fjqt $OSP_FILESYSTEM $filesystem_dev
 root_uuid=$($VOL_ID $filesystem_dev )
 
 if [ -n "$swapdev" ]; then
@@ -80,9 +91,11 @@ else
   # INCLUDE will be empty if EXTRA_PKGS is null/empty, otherwise we
   # build the full parameter format from it
   INCLUDE=${EXTRA_PKGS:+"--include=$EXTRA_PKGS"}
+  COMP=${COMPONENTS:+"--components=$COMPONENTS"}
   debootstrap \
     --arch "$DPKG_ARCH" \
     $INCLUDE \
+    $COMP \
     "$SUITE" $TMPDIR $MIRROR
 
   # remove the downloaded debs, as they are no longer needed
@@ -100,6 +113,9 @@ else
   fi
 fi
 
+# reset the root password
+chroot $TMPDIR passwd -d root
+
 cp -p /etc/hosts $TMPDIR/etc/hosts
 cp -p /etc/resolv.conf $TMPDIR/etc/resolv.conf
 echo $instance > $TMPDIR/etc/hostname
@@ -122,22 +138,32 @@ auto lo
 iface lo inet loopback
 EOF
 
+# for kvm, we should only activate a serial console if the
+# 'serial_console' parameter is set; for xen-pvm though, we should
+# always define a serial console
+SERIAL_PORT=""
 if [ "$INSTANCE_HV_serial_console" = "True" ]; then
+  SERIAL_PORT="ttyS0"
+elif [ "$HYPERVISOR" = "xen-pvm" ]; then
+  SERIAL_PORT="hvc0"
+fi
+
+if [ -n "$SERIAL_PORT" ]; then
   if [ -e $TMPDIR/etc/inittab ]; then
     # debian
-    echo "T0:23:respawn:/sbin/getty ttyS0 38400" >> $TMPDIR/etc/inittab
+    echo "T0:23:respawn:/sbin/getty $SERIAL_PORT 38400" >> $TMPDIR/etc/inittab
   elif [ -e $TMPDIR/etc/init ]; then
     # ubuntu (eg. karmic)
-    cat > $TMPDIR/etc/init/ttyS0.conf <<EOF
+    cat > $TMPDIR/etc/init/${SERIAL_PORT}.conf <<EOF
 start on stopped rc RUNLEVEL=[2345]
 stop on runlevel [!2345]
 
 respawn
-exec /sbin/getty -8 38400 ttyS0
+exec /sbin/getty -8 38400 $SERIAL_PORT
 EOF
   elif [ -e $TMPDIR/etc/event.d ]; then
     # ubuntu (eg. intrepid)
-    cat > $TMPDIR/etc/event.d/ttyS0.conf <<EOF
+    cat > $TMPDIR/etc/event.d/${SERIAL_PORT}.conf <<EOF
 start on stopped rc2
 start on stopped rc3
 start on stopped rc4
@@ -148,7 +174,7 @@ stop on runlevel 1
 stop on runlevel 6
 
 respawn
-exec /sbin/getty 38400 ttyS0
+exec /sbin/getty 38400 ${SERIAL_PORT}
 EOF
   fi
 fi