Index: b/sysv/etc/init.d/cloud-init-resizefs
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/sysv/etc/init.d/cloud-init-resizefs	2012-07-26 11:33:06.776890046 +0200
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# cloud-init resize root partition filesystem
+#
+# chkconfig: 2345 00 00
+# description: Resize the filesystem on the root partition.
+#
+
+# Source function library
+. /etc/init.d/functions
+
+if [ -e /var/lib/cloud/.resizefs ] ; then
+    exit 0
+fi
+
+start()
+{
+    root_dev=$(mount | awk '/ on \/ type / { print $1 }')
+    echo -n $"Resizing $root_dev: "
+    resize2fs $root_dev && success || failure
+    echo
+
+    touch /var/lib/cloud/.resizefs
+    touch /var/lib/cloud/.growpart
+}
+
+case "$1" in
+    start)
+	start
+	;;
+    stop)
+	;;
+    *)
+	echo $"Usage: $0 {start|stop}"
+	;;
+esac
Index: b/tools/cloud-init-growpart
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/tools/cloud-init-growpart	2012-07-26 11:31:27.936399931 +0200
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# cloud-init grow partition
+#
+# Grow a partition to its maximum size. This script makes certain assumptions
+# and is intended to be used within a CentOS 5 initrd only. It requires
+# busybox to be installed in the initrd.
+#
+
+if [ ! -d /sysroot/var/lib/cloud/ -o \
+    -e /sysroot/var/lib/cloud/.growpart ] ; then
+    exit
+fi
+
+dev=$1
+disk=$dev
+while [ "${disk%[0-9]}" != "$disk" ]; do
+        disk=${disk%[0-9]}
+done
+
+umount /sysroot
+
+echo "Before partition resizing:"
+fdisk -l $disk
+
+# TODO: This doesn't work if the disk contains more than one partition
+echo "Resizing partition:"
+echo -e "d\nn\np\n1\n\n\na\n1\nw" | fdisk $disk
+
+echo "After partition resizing:"
+fdisk -l $disk
+
+mount /sysroot
Index: b/tools/cloud-init-mdinitrd
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/tools/cloud-init-mdinitrd	2012-07-26 11:38:23.682461502 +0200
@@ -0,0 +1,106 @@
+#!/bin/bash
+#
+# Modify the initrd to resize the root (first) partition to the maximum
+# possible size before the partition is mounted.
+#
+
+# Cleanup handler
+function cleanup()
+{
+    if [ -d "$tmpdir" ] ; then
+	rm -rf $tmpdir
+    fi
+    if [ -e "$tmpinitrd" ] ; then
+	rm -rf $tmpinitrd
+    fi
+}
+
+# Print an error message and exit
+function fatal()
+{
+    echo "Error: $*"
+    exit 1
+}
+
+# Parse the commandline arguments
+ocleanup=1
+ointeractive=0
+for opt in "$@" ; do
+    case $opt in
+	--nocleanup)
+	    ocleanup=0
+	    ;;
+	--interactive)
+	    ointeractive=1
+	    ;;
+	-*)
+	    fatal "unknown option $opt"
+	    ;;
+	*)
+	    initrd=$opt
+	    ;;
+    esac
+done
+
+test -e "$initrd" || fatal "initrd $initrd doesn't exist"
+
+# Create a temp directory
+tmpdir=$(mktemp -d /tmp/initrd.XXXXXX) || fatal "failed to create temp dir"
+
+# Install the cleanup handler
+test $ocleanup -eq 1 && trap cleanup EXIT
+
+# Extract the initrd
+cd $tmpdir && \
+    gzip --decompress --stdout $initrd | \
+    cpio --quiet --extract --make-directories || \
+    fatal "failed to extract $initrd tp $tmpdir"
+
+# Check if we run interactively
+if [ $ointeractive -eq 1 ] ; then
+
+    echo "Initrd extracted to $tmpdir"
+    echo -n "Press Enter to continue: "
+    read tmp
+
+else
+
+    # Check if the initrd is patched already
+    if grep -q growpart $tmpdir/init ; then
+	echo "Exiting, initrd already patched"
+	exit
+    fi
+
+    # Get the root device name from the init script
+    root_dev=$(awk '/^mkrootdev/ { print $NF }' $tmpdir/init)
+    test -n "$root_dev" || fatal "Failed to get the root device name"
+
+    # Patch the init script
+    sed -i "/^mount /a \
+echo Growing root partition $root_dev.\n\
+/cloud/busybox ash /cloud/growpart $root_dev" \
+	$tmpdir/init || fatal "Failed to patch init script"
+
+    # Copy the growpart script and busybox to the initrd
+    mkdir $tmpdir/cloud
+    cp $(which cloud-init-growpart) $tmpdir/cloud/growpart
+    cp $(which busybox) $tmpdir/cloud/
+
+fi
+
+# Create the initrd
+tmpinitrd=$(mktemp $initrd.XXXXXX)
+cd $tmpdir && \
+    find . | \
+    cpio --quiet --create --format=newc | \
+    gzip -9 > $tmpinitrd || \
+    fatal "failed to create $tmpinitrd"
+
+# Copy the initrd
+mv $initrd $initrd.bak
+cp $tmpinitrd $initrd || \
+    fatal "failed to copy $tmpinitrd to $initrd"
+
+echo "Created new initrd $initrd"
+
+test $ocleanup -eq 0 && echo "Temporary initrd in $tmpdir"
Index: b/setup.py
===================================================================
--- a/setup.py	2012-07-26 11:31:27.824399370 +0200
+++ b/setup.py	2012-07-26 11:31:27.940399947 +0200
@@ -35,7 +35,9 @@
       packages=['cloudinit', 'cloudinit.CloudConfig' ],
       scripts=['cloud-init.py',
                'cloud-init-run-module.py',
-               'cloud-init-cfg.py'
+               'cloud-init-cfg.py',
+               'tools/cloud-init-growpart',
+               'tools/cloud-init-mdinitrd'
                ],
       data_files=[('/etc/cloud', ['cloud.cfg']),
                   ('/etc/cloud/templates', glob('templates/*')),
