commit 77449e7cb0a02f8ba22eb9af508e0e332c68d57a
Author: Lance Albertson <lance@osuosl.org>
Date:   Wed Feb 10 10:12:14 2010 -0800

    Add optional support for no /boot partition
    
    Allow for more flexibility for which partitions you need or what. It will allow
    for four different partition layouts depending on whether you want a swap
    partition or booting a kernel outside of the VM.
    
    Also merge the partition mapping for root_dev, boot_dev, & swap_dev entirely
    into map_disk0 so that there isn't code replication going on.

diff --git a/common.sh.in b/common.sh.in
index e751424..f672372 100644
--- a/common.sh.in
+++ b/common.sh.in
@@ -111,64 +111,96 @@ get_os_type() {
 }
 
 format_disk0() {
-    if [ "${SWAP}" = "yes" ] ; then
+    local sfdisk_cmd="$SFDISK -uM -H 255 -S 63 --quiet --Linux \"$1\""
+    if [  "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then
         # Create three partitions:
         # 1 - 100MB /boot, bootable
         # 2 - Size of Memory, swap
         # 3 - Rest
-        $SFDISK -uM -H 255 -S 63 --quiet --Linux "$1" <<EOF
+        $sfdisk_cmd <<EOF
 ,100,L,*
 ,$INSTANCE_BE_memory,S
 ,,L
 EOF
-    else
+    elif [  "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then
         # Create two partitions:
         # 1 - 100MB /boot, bootable
         # 2 - Rest
-        $SFDISK -uM -H 255 -S 63 --quiet --Linux "$1" <<EOF
+        $sfdisk_cmd <<EOF
 ,100,L,*
 ,,L
 EOF
+    elif [  "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then
+        # Create two partitions:
+        # 1 - Size of Memory, swap
+        # 2 - Rest
+        $sfdisk_cmd <<EOF
+,$INSTANCE_BE_memory,S
+,,L
+EOF
+    elif [  "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then
+        # Create two partitions:
+        # 1 - Whole
+        $sfdisk_cmd <<EOF
+,,L
+EOF
     fi
 }
 
 mkfs_disk0() {
-    local boot_dev=$1 root_dev=$2 swap_dev=$3
-    # Format /boot
-    mke2fs -Fjq -L /boot $boot_dev
     # Format /
-    mke2fs -Fjq -L / $root_dev
-    if [ "${SWAP}" = "yes" ] ; then
+    mkfs.ext3 -Fq -L / $root_dev
+    # Format /boot
+    if [ -n "${boot_dev}" ] ; then
+        mkfs.ext3 -Fq -L /boot $boot_dev
+    fi
+    # Format swap
+    if [ -n "${swap_dev}" ] ; then
         # Format swap
         mkswap -f $swap_dev
     fi
 }
 
 mount_disk0() {
-    local target=$1 root_dev=$2 boot_dev=$3
+    local target=$1
     mount $root_dev $target
     CLEANUP+=("umount $target")
-    $MKDIR_P $target/boot
-    mount $boot_dev $target/boot
-    CLEANUP+=("umount $target/boot")
+    if [ -n "${boot_dev}" ] ; then
+        $MKDIR_P $target/boot
+        mount $boot_dev $target/boot
+        CLEANUP+=("umount $target/boot")
+    fi
 }
 
 map_disk0() {
-  blockdev="$1"
-  filesystem_dev_base=`$KPARTX -l -p- $blockdev | \
-                       grep -m 1 -- "-1.*$blockdev" | \
-                       $AWK '{print $1}'`
-  if [ -z "$filesystem_dev_base" ]; then
-    log_error "Cannot interpret kpartx output and get partition mapping"
-    exit 1
-  fi
-  $KPARTX -a -p- $blockdev > /dev/null
-  filesystem_dev="/dev/mapper/${filesystem_dev_base/%-1/}"
-  if [ ! -b "/dev/mapper/$filesystem_dev_base" ]; then
-    log_error "Can't find kpartx mapped partition: /dev/mapper/$filesystem_dev_base"
-    exit 1
-  fi
-  echo "$filesystem_dev"
+    blockdev="$1"
+    filesystem_dev_base=`$KPARTX -l -p- $blockdev | \
+                            grep -m 1 -- "-1.*$blockdev" | \
+                            $AWK '{print $1}'`
+    if [ -z "$filesystem_dev_base" ]; then
+        log_error "Cannot interpret kpartx output and get partition mapping"
+        exit 1
+    fi
+    $KPARTX -a -p- $blockdev > /dev/null
+    filesystem_dev="/dev/mapper/${filesystem_dev_base/%-1/}"
+    if [ ! -b "/dev/mapper/$filesystem_dev_base" ]; then
+        log_error "Can't find kpartx mapped partition: /dev/mapper/$filesystem_dev_base"
+        exit 1
+    fi
+    if [ "${SWAP}" = "yes" -a -z "${KERNEL_PATH}" ] ; then
+        boot_dev="${filesystem_base_dev}-1"
+        swap_dev="${filesystem_base_dev}-2"
+        root_dev="${filesystem_base_dev}-3"
+    elif [ "${SWAP}" = "no" -a -z "${KERNEL_PATH}" ] ; then
+        boot_dev="${filesystem_base_dev}-1"
+        root_dev="${filesystem_base_dev}-2"
+    elif [ "${SWAP}" = "yes" -a -n "${KERNEL_PATH}" ] ; then
+        swap_dev="${filesystem_base_dev}-1"
+        root_dev="${filesystem_base_dev}-2"
+    elif [ "${SWAP}" = "no" -a -n "${KERNEL_PATH}" ] ; then
+        root_dev="${filesystem_base_dev}-1"
+    fi
+    echo "$filesystem_dev"
 }
 
 unmap_disk0() {
@@ -208,6 +240,7 @@ fi
 : ${IMAGE_DEBUG:="0"}
 
 SCRIPT_NAME=$(basename $0)
+KERNEL_PATH="$INSTANCE_HV_kernel_path"
 
 if [ -f /sbin/blkid -a -x /sbin/blkid ]; then
     VOL_ID="/sbin/blkid -o value -s UUID"
